How to use the bottender.MessengerBot 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 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 / analytics-botanalytics / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');
const botanalyticsMiddleware = require('bottender-botanalytics/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, {
  verifyToken: '__FILL_YOUR_VERIFY_TOKEN_HERE__',
  webhookMiddleware: botanalyticsMiddleware(bot, {
    apiToken: '__FILL_YOUR_BOTANALYTICS_TOKEN_HERE__',
  }),
});

server.listen(5000, () => {
github Yoctol / bottender / examples / with-nextjs-webview / index.js View on Github external
const { parse } = require('url');

const nextjs = require('next');
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');
});

async function createServerWithNext() {
  const nextApp = nextjs({
    dev: process.env.NODE_ENV !== 'production',
  });

  const handle = nextApp.getRequestHandler();

  await nextApp.prepare();
github Yoctol / bottender / examples / messenger-builder / index.js View on Github external
const { MessengerBot, MessengerHandler } = require('bottender');
const { createServer } = require('bottender/express');

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

const bot = new MessengerBot({
  accessToken: config.accessToken,
  appSecret: config.appSecret,
});

const handler = new MessengerHandler()
  .onText(/yo/i, async context => {
    await context.sendText('Hi there!');
  })
  .onEvent(async context => {
    await context.sendText("I don't know what you say.");
  })
  .onError(async context => {
    await context.sendText('Something wrong happened.');
  });

bot.onEvent(handler);
github Yoctol / bottender / examples / server-micro / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createRequestHandler } = require('bottender/micro');

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

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

module.exports = createRequestHandler(bot);
github Yoctol / bottender / examples / messenger-attachment-upload / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');
const { getAttachment } = require('bottender/utils');

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

const bot = new MessengerBot({
  accessToken: config.accessToken,
  appSecret: config.appSecret,
});

bot.onEvent(async context => {
  if (context.event.text === 'video') {
    const attachment = getAttachment('video.mp4');
    await context.sendVideo({ attachment_id: attachment.id });
  } else {
    const attachment = getAttachment('bottender.png');
    await context.sendImage({ attachment_id: attachment.id });
  }
});

const server = createServer(bot, { verifyToken: config.verifyToken });
github Yoctol / bottender / examples / analytics-dashbot / index.js View on Github external
const { MessengerBot } = require('bottender');
const { createServer } = require('bottender/express');
const dashbotMiddleware = require('bottender-dashbot/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, {
  verifyToken: '__FILL_YOUR_VERIFY_TOKEN_HERE__',
  webhookMiddleware: dashbotMiddleware(bot, {
    apiKey: '__FILL_YOUR_DASHBOT_KEY_HERE__',
    platform: 'facebook',
  }),
});