How to use the messaging-api-messenger.MessengerClient.connect function in messaging-api-messenger

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

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 <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 <name> to specify persona name'
    );
    invariant(
      personaUrl,
      '`pic` is required but not found. Use --pic <url> 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 <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) {
github Yoctol / bottender / packages / bottender / src / cli / providers / messenger / get-started.ts View on Github external
export async function getGetStarted(_: 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);

    const getStarted = await client.getGetStarted();

    if (getStarted && getStarted.payload) {
      print(`Get started payload is: ${bold(getStarted.payload)}`);
    } else {
      error(`Failed to find ${bold('get_started')} setting`);
    }
    return;
  } catch (err) {
    error(`Failed to get ${bold('get_started')} setting`);
    if (err.response) {
      error(`status: ${bold(err.response.status)}`);
      if (err.response.data) {
        error(`data: ${bold(JSON.stringify(err.response.data, null, 2))}`);
      }

messaging-api-messenger

Messaging API client for Messenger

MIT
Latest version published 12 months ago

Package Health Score

74 / 100
Full package analysis

Similar packages