How to use the bottender.Bot function in bottender

To help you get started, we’ve selected a few bottender 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 bottenderjs / bottender-facebook / examples / facebook-batch / server.js View on Github external
const { Bot } = require('bottender');
const { createServer } = require('bottender/koa');
const { FacebookConnector } = require('bottender-facebook');
const { isError613 } = require('messenger-batch');

require('dotenv').config();

const ACCESS_TOKEN = process.env.ACCESS_TOKEN;
const APP_SECRET = process.env.APP_SECRET;
const VERIFY_TOKEN = process.env.VERIFY_TOKEN;

const bot = new Bot({
  connector: new FacebookConnector({
    accessToken: ACCESS_TOKEN,
    appSecret: APP_SECRET,
    batchConfig: {
      delay: 1000,
      shouldRetry: isError613, // (#613) Calls to this api have exceeded the rate limit.
      retryTimes: 2,
    },
  }),
});

bot.onEvent(async context => {
  console.log(context.event);

  if (context.event.isCommentAdd && !context.event.isSentByPage) {
    try {
github bottenderjs / bottender-facebook / examples / single-page / server.js View on Github external
const { Bot } = require('bottender');
const { createServer } = require('bottender/koa');
const { FacebookConnector } = require('bottender-facebook');

require('dotenv').config();

const ACCESS_TOKEN = process.env.ACCESS_TOKEN;
const APP_SECRET = process.env.APP_SECRET;
const VERIFY_TOKEN = process.env.VERIFY_TOKEN;

const bot = new Bot({
  connector: new FacebookConnector({
    accessToken: ACCESS_TOKEN,
    appSecret: APP_SECRET,
  }),
});

bot.onEvent(async context => {
  console.log(context.event);

  if (context.event.isCommentAdd && !context.event.isSentByPage) {
    try {
      await context.sendPrivateReply('OK!');
      await context.sendComment('Public Reply!');
      await context.sendLike();
    } catch (err) {
      console.log(err.response.data);
github bottenderjs / bottender-facebook / examples / multi-pages / server.js View on Github external
const PAGE_2_ACCESS_TOKEN = process.env.PAGE_2_ACCESS_TOKEN;

const APP_SECRET = process.env.APP_SECRET;
const VERIFY_TOKEN = process.env.VERIFY_TOKEN;

const mapPageToAccessToken = pageId => {
  switch (pageId) {
    case PAGE_1_PAGE_ID:
      return PAGE_1_ACCESS_TOKEN;
    case PAGE_2_PAGE_ID:
    default:
      return PAGE_2_ACCESS_TOKEN;
  }
};

const bot = new Bot({
  connector: new FacebookConnector({
    appSecret: APP_SECRET,
    mapPageToAccessToken,
  }),
});

bot.onEvent(async context => {
  if (context.event.isCommentAdd && !context.event.isSentByPage) {
    try {
      await context.sendPrivateReply('OK!');
      await context.sendComment('Public reply!');
      await context.sendLike();
    } catch (err) {
      console.log(err);
    }
  }