https://github.com/bottenderjs/bottender-handovers
An experimental package for Messenger Handover Protocol with Bottender.
https://github.com/bottenderjs/bottender-handovers
Last synced: 11 months ago
JSON representation
An experimental package for Messenger Handover Protocol with Bottender.
- Host: GitHub
- URL: https://github.com/bottenderjs/bottender-handovers
- Owner: bottenderjs
- License: mit
- Created: 2018-01-29T04:48:07.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-07-26T09:05:12.000Z (almost 8 years ago)
- Last Synced: 2025-04-13T00:53:08.873Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 114 KB
- Stars: 4
- Watchers: 4
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# bottender-handovers
[](https://www.npmjs.com/package/bottender-handovers)
[](https://travis-ci.org/bottenderjs/bottender-handovers)
[](https://opensource.org/licenses/MIT)
> An experimental package for [Messenger Handover Protocol](https://developers.facebook.com/docs/messenger-platform/handover-protocol) with [Bottender](https://github.com/Yoctol/bottender).
## Installation
```sh
npm install bottender-handovers
```
## Usage
```js
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.
```js
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,
});
```
## 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](https://github.com/bottenderjs/bottender-handovers)