An experimental package for Messenger Handover Protocol with Bottender.
npm install bottender-handovers
const { middleware } = require('bottender');
const handovers = require('bottender-handovers');
const handleHandovers = handovers({
shouldControlPass: context => context.event.text === '/help',
shouldControlTake: context =>
context.event.isStandby && context.event.text === '/back',
willControlPass: async context => {
await context.sendText('Passing thread control to the page inbox.');
},
didControlTake: async context => {
await context.sendText('Took thread control back.');
},
});
// This bot should be assigned as primary receiver app
bot.onEvent(
middleware([
handleHandovers,
async context => {
if (!context.event.isStandby) {
await context.sendText('Respond by bot.');
}
},
])
);
bottender-handovers
provide two built-in functions to utilize Messenger Platform's Request Thread Control events. Simply pass them to shouldControlPass
option.
const { middleware } = require('bottender');
const handovers = require('bottender-handovers');
const {
isRequestThreadControlFrom,
isRequestThreadControlFromPageInbox,
} = handovers;
// request from and pass to 3rd party CRM service
const myCRMAppId = 123456;
const handleHandovers = handovers({
shouldControlPass: isRequestThreadControlFrom(myCRMAppId),
targetAppId: myCRMAppId,
});
// request from and pass to Facebook Page Inbox
const handleHandovers = handovers({
shouldControlPass: isRequestThreadControlFromPageInbox,
});
Default: () => false
.
Default: () => false
.
Default: () => {}
.
Default: () => {}
.
Default: () => {}
.
Default: () => {}
.
Default: 263902037430900
(Page Inbox).
MIT © Yoctol