bottender-handovers
v0.3.0
Published
An experimental package for Messenger Handover Protocol with Bottender.
Downloads
4
Readme
bottender-handovers
An experimental package for Messenger Handover Protocol with Bottender.
Installation
npm install bottender-handovers
Usage
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.');
}
},
])
);
Using Request Thread Control
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 } = 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: context =>
context.event.isRequestThreadControlFromPageInbox,
});
Options
shouldControlPass(context): boolean
Default: () => false
.
shouldControlTake(context): boolean
Default: () => false
.
willControlPass(context)
Default: () => {}
.
willControlTake(context)
Default: () => {}
.
didControlPass(context)
Default: () => {}
.
didControlTake(context)
Default: () => {}
.
targetAppId
Default: 263902037430900
(Page Inbox).
License
MIT © Yoctol