Line.js 7.47 KB
"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.default = void 0;
var _invariant = _interopRequireDefault(require("invariant"));
var _lodash = _interopRequireDefault(require("lodash.omit"));function _interopRequireDefault(obj) {return obj && obj.__esModule ? obj : { default: obj };}function ownKeys(object, enumerableOnly) {var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {return Object.getOwnPropertyDescriptor(object, sym).enumerable;});keys.push.apply(keys, symbols);}return keys;}function _objectSpread(target) {for (var i = 1; i < arguments.length; i++) {var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {ownKeys(source, true).forEach(function (key) {_defineProperty(target, key, source[key]);});} else if (Object.getOwnPropertyDescriptors) {Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));} else {ownKeys(source).forEach(function (key) {Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));});}}return target;}function _defineProperty(obj, key, value) {if (key in obj) {Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });} else {obj[key] = value;}return obj;}



























function createText(text, options = {}) {
  return _objectSpread({
    type: 'text',
    text },
  (0, _lodash.default)(options, 'accessToken'));

}

function createImage(
contentUrlOrImage,
previewUrlOrOptions)
{
  if (previewUrlOrOptions) {
    if (
    typeof contentUrlOrImage === 'object' &&
    typeof previewUrlOrOptions === 'object')
    {
      const image = contentUrlOrImage;
      const options = previewUrlOrOptions;
      return _objectSpread({
        type: 'image',
        originalContentUrl: image.originalContentUrl,
        previewImageUrl: image.previewImageUrl || image.originalContentUrl },
      (0, _lodash.default)(options, 'accessToken'));

    }

    if (
    typeof contentUrlOrImage === 'string' &&
    typeof previewUrlOrOptions === 'string')
    {
      return {
        type: 'image',
        originalContentUrl: contentUrlOrImage,
        previewImageUrl: previewUrlOrOptions };

    }
  } else {
    if (typeof contentUrlOrImage === 'object') {
      const image = contentUrlOrImage;
      return {
        type: 'image',
        originalContentUrl: image.originalContentUrl,
        previewImageUrl: image.previewImageUrl || image.originalContentUrl };

    }

    if (typeof contentUrlOrImage === 'string') {
      return {
        type: 'image',
        originalContentUrl: contentUrlOrImage,
        previewImageUrl: contentUrlOrImage };

    }
  }

  (0, _invariant.default)(false, 'Line#createImage: Wrong type of arguments.');
}

function createVideo(
contentUrlOrVideo,
previewImageUrlOrOptions)
{
  if (
  typeof contentUrlOrVideo === 'string' &&
  typeof previewImageUrlOrOptions === 'string')
  {
    return {
      type: 'video',
      originalContentUrl: contentUrlOrVideo,
      previewImageUrl: previewImageUrlOrOptions };

  }

  if (
  typeof contentUrlOrVideo === 'object' && (
  !previewImageUrlOrOptions || typeof previewImageUrlOrOptions === 'object'))
  {
    const video = contentUrlOrVideo;
    const options = previewImageUrlOrOptions || {};
    return _objectSpread({
      type: 'video',
      originalContentUrl: video.originalContentUrl,
      previewImageUrl: video.previewImageUrl },
    (0, _lodash.default)(options, 'accessToken'));

  }

  (0, _invariant.default)(false, 'Line#createVideo: Wrong type of arguments.');
}

function createAudio(
contentUrlOrAudio,
durationOrOptions)
{
  if (
  typeof contentUrlOrAudio === 'string' &&
  typeof durationOrOptions === 'number')
  {
    return {
      type: 'audio',
      originalContentUrl: contentUrlOrAudio,
      duration: durationOrOptions };

  }

  if (
  typeof contentUrlOrAudio === 'object' && (
  !durationOrOptions || typeof durationOrOptions === 'object'))
  {
    const audio = contentUrlOrAudio;
    const options = durationOrOptions || {};
    return _objectSpread({
      type: 'audio',
      originalContentUrl: audio.originalContentUrl,
      duration: audio.duration },
    (0, _lodash.default)(options, 'accessToken'));

  }

  (0, _invariant.default)(false, 'Line#createAudio: Wrong type of arguments.');
}

function createLocation(
{ title, address, latitude, longitude },
options = {})
{
  return _objectSpread({
    type: 'location',
    title,
    address,
    latitude,
    longitude },
  (0, _lodash.default)(options, 'accessToken'));

}

function createSticker(
packageIdOrSticker,
stickerIdOrOptions)
{
  if (
  typeof packageIdOrSticker === 'string' &&
  typeof stickerIdOrOptions === 'string')
  {
    return {
      type: 'sticker',
      packageId: packageIdOrSticker,
      stickerId: stickerIdOrOptions };

  }

  if (
  typeof packageIdOrSticker === 'object' && (
  !stickerIdOrOptions || typeof stickerIdOrOptions === 'object'))
  {
    const sticker = packageIdOrSticker;
    const options = stickerIdOrOptions || {};
    return _objectSpread({
      type: 'sticker',
      packageId: sticker.packageId,
      stickerId: sticker.stickerId },
    (0, _lodash.default)(options, 'accessToken'));

  }

  (0, _invariant.default)(false, 'Line#createSticker: Wrong type of arguments.');
}

function createImagemap(
altText,
{
  baseUrl,
  baseSize,
  baseHeight,
  baseWidth,
  video,
  actions },











options = {})
{
  return _objectSpread({
    type: 'imagemap',
    baseUrl,
    altText,
    baseSize: baseSize || {
      height: baseHeight,
      width: baseWidth },

    video,
    actions },
  (0, _lodash.default)(options, 'accessToken'));

}

function createTemplate(
altText,
template,
options = {})
{
  return _objectSpread({
    type: 'template',
    altText,
    template },
  (0, _lodash.default)(options, 'accessToken'));

}

function createButtonTemplate(
altText,
{
  thumbnailImageUrl,
  imageAspectRatio,
  imageSize,
  imageBackgroundColor,
  title,
  text,
  defaultAction,
  actions },










options = {})
{
  return createTemplate(
  altText,
  {
    type: 'buttons',
    thumbnailImageUrl,
    imageAspectRatio,
    imageSize,
    imageBackgroundColor,
    title,
    text,
    defaultAction,
    actions },

  (0, _lodash.default)(options, 'accessToken'));

}

function createConfirmTemplate(
altText,
{
  text,
  actions },




options = {})
{
  return createTemplate(
  altText,
  {
    type: 'confirm',
    text,
    actions },

  (0, _lodash.default)(options, 'accessToken'));

}

function createCarouselTemplate(
altText,
columns,
{
  imageAspectRatio,
  imageSize,
  quickReply } =




{})
{
  return createTemplate(
  altText,
  {
    type: 'carousel',
    columns,
    imageAspectRatio,
    imageSize },

  { quickReply });

}

function createImageCarouselTemplate(
altText,
columns,
options = {})
{
  return createTemplate(
  altText,
  {
    type: 'image_carousel',
    columns },

  (0, _lodash.default)(options, 'accessToken'));

}

function createFlex(
altText,
contents,
options = {})
{
  return _objectSpread({
    type: 'flex',
    altText,
    contents },
  (0, _lodash.default)(options, 'accessToken'));

}

const Line = {
  createText,
  createImage,
  createVideo,
  createAudio,
  createLocation,
  createSticker,
  createImagemap,
  createTemplate,
  createButtonsTemplate: createButtonTemplate,
  createButtonTemplate,
  createConfirmTemplate,
  createCarouselTemplate,
  createImageCarouselTemplate,
  createFlex };var _default =


Line;exports.default = _default;