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

To help you get started, we’ve selected a few messaging-api-messenger 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 / context / __tests__ / MessengerContext.spec.ts View on Github external
beforeEach(() => {
  /* eslint-disable global-require */
  MessengerClient = require('messaging-api-messenger').MessengerClient;
  MessengerContext = require('../MessengerContext').default;
  MessengerEvent = require('../MessengerEvent').default;
  warning = require('warning');
  /* eslint-enable global-require */
});
github Yoctol / bottender / packages / bottender / src / context / __tests__ / MessengerContext-sendTemplate.spec.ts View on Github external
beforeEach(() => {
  /* eslint-disable global-require */
  MessengerClient = require('messaging-api-messenger').MessengerClient;
  MessengerContext = require('../MessengerContext').default;
  MessengerEvent = require('../MessengerEvent').default;
  warning = require('warning');
  /* eslint-enable global-require */
});
github Yoctol / bottender / packages / bottender / src / messenger / __tests__ / MessengerContext-send.spec.ts View on Github external
beforeEach(() => {
  /* eslint-disable global-require */
  MessengerClient = require('messaging-api-messenger').MessengerClient;
  MessengerContext = require('../MessengerContext').default;
  MessengerEvent = require('../MessengerEvent').default;
  sleep = require('delay');
  warning = require('warning');
  /* eslint-enable global-require */
});
github Yoctol / bottender / packages / bottender / src / messenger / MessengerConnector.ts View on Github external
constructor(options: ConstructorOptions) {
    const {
      appId,
      appSecret,
      mapPageToAccessToken,
      verifyToken,
      batchConfig,

      skipProfile,
    } = options;

    if ('client' in options) {
      this._client = options.client;
    } else {
      const { accessToken, origin, skipAppSecretProof } = options;
      this._client = MessengerClient.connect({
        accessToken: accessToken || '',
        appSecret,
        origin,
        skipAppSecretProof,
      });
    }

    this._appId = appId;
    this._appSecret = appSecret;

    this._mapPageToAccessToken = mapPageToAccessToken || null;
    this._verifyToken = verifyToken || shortid.generate();

    // FIXME: maybe set this default value as true
    this._skipProfile = typeof skipProfile === 'boolean' ? skipProfile : false;
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / greeting.ts View on Github external
export async function deleteGreeting(_: CliContext) {
  try {
    const config = getConfig('messenger');

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

    const accessToken = config.accessToken;

    const client = MessengerClient.connect(accessToken);

    await client.deleteGreeting();

    print(`Successfully delete ${bold('greeting')} setting`);
    return;
  } catch (err) {
    error(`Failed to delete ${bold('greeting')} setting`);
    if (err.response) {
      error(`status: ${bold(err.response.status)}`);
      if (err.response.data) {
        error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
      }
    } else {
      error(err.message);
    }
    return process.exit(1);
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / whitelisted-domains.ts View on Github external
export async function deleteWhitelistedDomains(_: CliContext) {
  try {
    const config = getConfig('messenger');

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

    const accessToken = config.accessToken;

    const client = MessengerClient.connect(accessToken);

    await client.deleteWhitelistedDomains();

    print(`Successfully delete ${bold('whitelisted-domains')} setting`);
    return;
  } catch (err) {
    error(`Failed to delete ${bold('whitelisted-domains')} setting`);
    if (err.response) {
      error(`status: ${bold(err.response.status)}`);
      if (err.response.data) {
        error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
      }
    } else {
      error(err.message);
    }
    return process.exit(1);
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / persona.ts View on Github external
try {
    const config = getChannelConfig(Channel.Messenger);

    const { accessToken } = config;

    invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );
    invariant(
      personaId,
      '`id` is required but not found. Use --id  to specify persona id'
    );

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

    const persona = await client.getPersona(personaId as string);

    if (persona !== undefined) {
      print(`Information of persona ${bold(personaId as string)}:`);
      print(`Name: ${bold(persona.name)}`);
      print(`Profile picture: ${bold(persona.profilePictureUrl)}`);
    } else {
      print(`Cannot get persona of ID ${bold(personaId as string)}`);
    }
  } catch (err) {
    error(
      `Failed to get ${bold('persona')} of ID ${bold(personaId as string)}`
    );
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / persona.ts View on Github external
invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );

    invariant(
      personaName,
      '`name` is required but not found. Use --name  to specify persona name'
    );
    invariant(
      personaUrl,
      '`pic` is required but not found. Use --pic  to specify persona profile picture url'
    );

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

    const persona = {
      name: personaName as string,
      profilePictureUrl: personaUrl as string,
    };

    const personaID = await client.createPersona(persona);

    print(`Successfully create ${bold('persona')} ${bold(personaID.id)}`);
  } catch (err) {
    error(`Failed to create ${bold('persona')}`);

    if (err.response) {
      error(`status: ${bold(err.response.status)}`);
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / webhook.ts View on Github external
invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );
    invariant(appId, '`appId` is not found in the `bottender.config.js` file');
    invariant(
      appSecret,
      '`appSecret` is not found in the `bottender.config.js` file'
    );
    invariant(
      verifyToken,
      '`verifyToken` is not found in the `bottender.config.js` file'
    );

    const client = MessengerClient.connect({
      accessToken,
      appId,
      appSecret,
    });

    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();
      if (result) {
        webhook = `${await getWebhookFromNgrok(ngrokPort)}${path}`;
      }
    }
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / persona.ts View on Github external
try {
    const config = getChannelConfig(Channel.Messenger);

    const { accessToken } = config;

    invariant(
      accessToken,
      '`accessToken` is not found in the `bottender.config.js` file'
    );
    invariant(
      personaId,
      '`id` is required but not found. Use --id  to specify persona id'
    );

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

    const res = await client.deletePersona(personaId as string);

    if (res.success === true || res.success === 'true') {
      print(`Sucessfully delete persona of ID ${bold(personaId as string)}`);
    } else {
      print(`Cannot get persona of ID ${bold(personaId as string)}`);
    }
  } catch (err) {
    error(
      `Failed to delete ${bold('persona')} of ID ${bold(personaId as string)}`
    );

    if (err.response) {

messaging-api-messenger

Messaging API client for Messenger

MIT
Latest version published 3 years ago

Package Health Score

54 / 100
Full package analysis