How to use bottender - 10 common examples

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 Yoctol / bottender / examples / telegram-long-polling / index.js View on Github external
const { TelegramBot } = require('bottender');

const bot = new TelegramBot({
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
});

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

bot.createLongPollingRuntime({
  limit: 10, // Limits the number of updates to be retrieved. Defaults to 100.
  timeout: 60, // Timeout in seconds for long polling. Defaults to 0.
  allowed_updates: ['message', 'callback_query'], // List the types of updates you want your bot to receive
});
github Yoctol / bottender / examples / with-unit-tests / bot.js View on Github external
const { ConsoleBot } = require('bottender');

const handler = require('./handler');

const bot = new ConsoleBot();

bot.onEvent(handler);

module.exports = bot;
github Yoctol / bottender / examples / server-koa / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/koa');

const bot = new MessengerBot({
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
  appSecret: '__FILL_YOUR_SECRET_HERE__',
});

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot);

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / with-config / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');

const config = require('./bottender.config');

const bot = new MessengerBot(config.messenger);

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot, config);

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / server-restify / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/restify');

const bot = new MessengerBot({
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
  appSecret: '__FILL_YOUR_SECRET_HERE__',
});

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot);

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / server-express / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');

const bot = new MessengerBot({
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
  appSecret: '__FILL_YOUR_SECRET_HERE__',
});

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot);

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / telegram-builder / index.js View on Github external
});

const handler = new TelegramHandler()
  .onText(/yo/i, async context => {
    const options = {
      parse_mode: 'Markdown',
    };
    await context.sendMessage('*Hi* there!', options);
  })
  .onEvent(async context => {
    await context.sendMessage("Sorry, I don't know what you say.");
  });

bot.onEvent(handler);

const server = createServer(bot);
server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / with-config / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');

const config = require('./bottender.config');

const bot = new MessengerBot(config.messenger);

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot, config);

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});
github Yoctol / bottender / examples / with-ngrok / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');

const bot = new MessengerBot({
  accessToken: '__FILL_YOUR_TOKEN_HERE__',
  appSecret: '__FILL_YOUR_SECRET_HERE__',
});

bot.onEvent(async context => {
  await context.sendText('Hello World');
});

const server = createServer(bot, { ngrok: true });

server.listen(5000, () => {
  console.log('server is running on 5000 port...');
});