Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 {
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);
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);
}
}