How to use messaging-api-viber - 5 common examples

To help you get started, we’ve selected a few messaging-api-viber 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 / cli / providers / viber / __tests__ / deleteWebhook.spec.ts View on Github external
it('reject when Viber return not success', () => {
    setup();

    const ctx = {
      argv: {},
    };

    ViberClient.connect().removeWebhook.mockRejectedValueOnce(
      new Error('removeWebhook failed')
    );

    expect(deleteWebhook(ctx).then).toThrow();
  });
github Yoctol / bottender / packages / bottender / src / viber / __tests__ / ViberConnector.spec.ts View on Github external
function setup() {
  const mockViberClient = new ViberClient({
    accessToken: ACCESS_TOKEN,
    sender: { name: 'sender' },
  });
  ViberClient.connect = jest.fn();
  ViberClient.connect.mockReturnValue(mockViberClient);

  return {
    mockViberClient,
    connector: new ViberConnector({
      accessToken: ACCESS_TOKEN,
      sender: { name: 'sender' },
    }),
  };
}
github Yoctol / bottender / packages / bottender / src / viber / ViberConnector.ts View on Github external
constructor(options: ConstructorOptions) {
    if ('client' in options) {
      this._client = options.client;
    } else {
      const { accessToken, sender, origin } = options;

      this._client = ViberClient.connect(
        {
          accessToken,
          sender,
          origin,
        },
        sender
      );
    }

    this._accessToken = this._client.accessToken;
  }
github Yoctol / bottender / packages / bottender / src / cli / providers / viber / webhook.ts View on Github external
export async function deleteWebhook(_: CliContext): Promise {
  try {
    const config: ViberConfig = getChannelConfig(Channel.Viber);

    const { accessToken, sender } = config;

    invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );
    invariant(
      sender,
      '`sender` is not found in the `bottender.config.js` file'
    );

    const client = ViberClient.connect(
      {
        accessToken,
        sender,
      },
      sender
    );

    await client.removeWebhook();

    print('Successfully delete Viber webhook');
  } catch (err) {
    error('Failed to delete Viber webhook');
    if (err.response) {
      error(`status: ${bold(err.response.status)}`);
      if (err.response.data) {
        error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
github Yoctol / bottender / packages / bottender / src / cli / providers / viber / webhook.ts View on Github external
try {
    const config: ViberConfig = getChannelConfig(Channel.Viber);

    const { accessToken, sender, path = '/webhooks/viber' } = config;

    invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );
    invariant(
      sender,
      '`sender` is not found in the `bottender.config.js` file'
    );

    const client = ViberClient.connect(
      {
        accessToken,
        sender,
      },
      sender
    );

    if (!webhook) {
      warn('We can not find the webhook callback url you provided.');

      const prompt = new Confirm(
        `Are you using ngrok (get url from ngrok server on http://127.0.0.1:${ngrokPort})?`
      );

      const result = await prompt.run();

messaging-api-viber

Messaging API client for Viber

MIT
Latest version published 3 years ago

Package Health Score

51 / 100
Full package analysis