How to use messaging-api-line - 10 common examples

To help you get started, we’ve selected a few messaging-api-line examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Yoctol / bottender / packages / bottender / src / line / __tests__ / LineContext.spec.ts View on Github external
beforeEach(() => {
  /* eslint-disable global-require */
  Line = require('messaging-api-line').Line;
  LineClient = require('messaging-api-line').LineClient;
  LineContext = require('../LineContext').default;
  LineEvent = require('../LineEvent').default;
  sleep = require('delay');
  warning = require('warning');
  /* eslint-enable global-require */
});
github Yoctol / bottender / packages / bottender / src / line / __tests__ / LineContext.spec.ts View on Github external
beforeEach(() => {
  /* eslint-disable global-require */
  Line = require('messaging-api-line').Line;
  LineClient = require('messaging-api-line').LineClient;
  LineContext = require('../LineContext').default;
  LineEvent = require('../LineEvent').default;
  sleep = require('delay');
  warning = require('warning');
  /* eslint-enable global-require */
});
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / deleteLineMenu.spec.js View on Github external
it('should delete all online rich menus if using force', async () => {
    const ctx = setup(true);

    LineClient.connect().getRichMenuList.mockResolvedValueOnce([
      {
        richMenuId: '1234567890',
      },
      {
        richMenuId: '0987654321',
      },
    ]);

    await deleteLineMenu(ctx);

    expect(LineClient.connect().deleteRichMenu.mock.calls.length).toBe(2);
    expect(print.mock.calls.length).toBe(1);
  });
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / setLineMenus.spec.js View on Github external
it('should not call deleteRichMenu when online rich menus and local rich menus are same', async () => {
    const ctx = setup();

    LineClient.connect().getRichMenuList.mockResolvedValueOnce([
      {
        richMenuId: '1234567890',
        size: {
          width: 2500,
          height: 1686,
        },
        selected: false,
        name: 'Nice richmenu',
        chatBarText: 'Tap here',
        areas: [
          {
            bounds: {
              x: 0,
              y: 0,
              width: 2500,
              height: 1686,
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / deleteLineMenu.spec.js View on Github external
it('should exit when failed to find rich menu', async () => {
    const ctx = setup(false);

    LineClient.connect().getRichMenuList.mockResolvedValueOnce(null);

    await deleteLineMenu(ctx);

    expect(error).toBeCalled();
    expect(process.exit).toBeCalled();
  });
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / getLineMenu.spec.js View on Github external
it('should print rich menus', async () => {
    const ctx = setup();

    LineClient.connect().getRichMenuList.mockResolvedValueOnce([
      {
        richMenuId: '1234567890',
        size: {
          width: 2500,
          height: 1686,
        },
        selected: false,
        name: 'Nice richmenu',
        chatBarText: 'Tap here',
        areas: [
          {
            bounds: {
              x: 0,
              y: 0,
              width: 2500,
              height: 1686,
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / setLineMenus.spec.js View on Github external
width: 2500,
              height: 1686,
            },
            action: {
              type: 'postback',
              data: 'action=sell&itemid=321',
            },
          },
        ],
      },
    ]);

    await setLineMenus(ctx);

    expect(LineClient.connect().deleteRichMenu.mock.calls.length).toBe(2);
    expect(LineClient.connect().createRichMenu.mock.calls.length).toBe(1);
    expect(print.mock.calls.length).toBe(1);
    expect(log.mock.calls.length).toBe(1);
  });
});
github Yoctol / bottender / packages / bottender / src / cli / providers / line / __tests__ / setLineMenus.spec.js View on Github external
y: 0,
              width: 2500,
              height: 1686,
            },
            action: {
              type: 'postback',
              data: 'action=sell&itemid=321',
            },
          },
        ],
      },
    ]);

    await setLineMenus(ctx);

    expect(LineClient.connect().deleteRichMenu.mock.calls.length).toBe(2);
    expect(LineClient.connect().createRichMenu.mock.calls.length).toBe(1);
    expect(print.mock.calls.length).toBe(1);
    expect(log.mock.calls.length).toBe(1);
  });
});
github Yoctol / bottender / packages / bottender / src / cli / providers / line / menu.ts View on Github external
export async function setLineMenus(_: CliContext) {
  try {
    const config = getConfig('line');
    const { richMenus: localRichMenus } = config;

    invariant(config.accessToken, 'accessToken is not found in config file');

    const accessToken = config.accessToken;

    const client = LineClient.connect(accessToken);

    const onlineRichMenus = await client.getRichMenuList();
    invariant(
      onlineRichMenus,
      `Failed to get ${bold('LINE rich menu')} response.`
    );

    const existedRichMenus = onlineRichMenus.map(richMenu =>
      omit(richMenu, 'richMenuId')
    );

    const shouldDeleteRichMenus = differenceWith(
      existedRichMenus,
      localRichMenus,
      isEqual
    );
github Yoctol / bottender / packages / bottender / src / line / LineConnector.ts View on Github external
constructor(options: ConstructorOptions) {
    const {
      mapDestinationToAccessToken,
      shouldBatch,
      sendMethod,
      skipProfile,
    } = options;
    if ('client' in options) {
      this._client = options.client;

      this._channelSecret = '';
    } else {
      const { accessToken, channelSecret, origin } = options;

      this._client = LineClient.connect({
        accessToken,
        channelSecret,
        origin,
      });

      this._channelSecret = channelSecret;
    }

    this._mapDestinationToAccessToken = mapDestinationToAccessToken || null;

    this._shouldBatch = typeof shouldBatch === 'boolean' ? shouldBatch : true;
    warning(
      !sendMethod || sendMethod === 'reply' || sendMethod === 'push',
      'sendMethod should be one of `reply` or `push`'
    );
    this._sendMethod = sendMethod || 'reply';