Facebook Messenger plugin for wingbot
npm install wingbot-facebookConnector plugin for wingbot chatbot framework
You can include a full JSON Action string to run a certain interaction in your bot using metadata in a handover event.
``json`
{
"sender":{
"id":"
},
"recipient":{
"id":"
},
"timestamp":1458692752478,
"pass_thread_control":{
"new_owner_app_id":"123456789",
"metadata":"{\"action\":\"your-action\",\"data\":{}}"
}
}
-----------------
User loader middleware
object* Facebook
* [new Facebook(processor, options, [senderLogger])](#new_Facebook_new)
* .verifyWebhook(queryString) ⇒ string
* .verifyRequest(body, headers) ⇒ Promise
* .processMessage(message, senderId, pageId, data) ⇒ Promise.<{status:number}>
* [.processEvent(body, [data])](#Facebook+processEvent) ⇒ Promise.<Array.<{message:object, pageId:string}>>
| Param | Type | Description |
| --- | --- | --- |
| processor | Processor | |
| options | object | |
| options.pageToken | string | facebook page token |
| options.appId | string | facebook app id |
| [options.botToken] | string | botToken for webhook verification |
| [options.appSecret] | string | provide app secret to verify requests |
| [options.passThreadAction] | string | trigger this action for pass thread event |
| [options.takeThreadAction] | string | trigger this action for take thread event |
| [options.requestThreadAction] | string | trigger this action when thread request |
| [options.throwsExceptions] | boolean | allows processEvents method to thow exception |
| [options.apiUrl] | string | override Facebook API url |
| [options.attachmentStorage] | AttachmentCache | cache for reusing attachments |
| [options.requestLib] | function | request library replacement |
| [senderLogger] | console | optional console like chat logger |
Kind: instance method of Facebook
Throws:
- Error when the request is invalid
| Param | Type |
| --- | --- |
| queryString | object |
Kind: instance method of Facebook
Throws:
- Error when x-hub-signature does not match body signature
| Param | Type |
| --- | --- |
| body | Buffer \| string |
| headers | object |
Facebook | Param | Type | Description |
| --- | --- | --- |
| message | object | wingbot chat event |
| senderId | string | chat event sender identifier |
| pageId | string | channel/page identifier |
| data | object | contextual data (will be available in res.data) |
| [data.appId] | string | possibility to override appId |
Kind: instance method of Facebook
Returns: Promise.<Array.<{message:object, pageId:string}>> - - unprocessed events
| Param | Type | Description |
| --- | --- | --- |
| body | object | event body |
| [data] | object | event context data |
* Settings
* new Settings()
* _instance_
* [.greeting([text])](#Settings+greeting) ⇒ Promise
* [.getStartedButton([payload])](#Settings+getStartedButton) ⇒ Promise
* .whitelistDomain(domains) ⇒ Promise
* .noMenu() ⇒ Promise
* [.menu([locale], [inputDisabled])](#Settings+menu) ⇒ MenuComposer
* _static_
* .Settings
* [new Settings(token, [log], [req])](#new_Settings.Settings_new)
Kind: instance method of Settings
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [text] | string | false | leave empty to clear |
Kind: instance method of Settings
| Param | Type | Default | Description |
| --- | --- | --- | --- |
| [payload] | string \| object | false | leave blank to remove button, or provide the action |
Example
`javascript`
const settings = new Settings(config.facebook.pageToken);
settings.getStartedButton('/start'); // just an action
Kind: instance method of Settings
| Param | Type |
| --- | --- |
| domains | string \| Array.<string> |
Kind: instance method of Settings
Kind: instance method of Settings
| Param | Type | Default |
| --- | --- | --- |
| [locale] | string | "default" |
| [inputDisabled] | boolean | false |
Example
`javascript
const { Settings } = require('wingbot');
const settings = new Settings('page-token-string');
settings
.menu('fr_FR')
.addNested('Nested Menu')
.addUrl('Aller à google', 'https://google.com')
.done()
.addPostBack('Faire quelque chose', '/the/action')
.menu() // the default menu
.addNested('Nested Menu')
.addUrl('Go to google', 'https://google.com')
.done()
.addPostBack('Do something', '/the/action')
.done();
`
Settings #### new Settings(token, [log], [req])
Creates an instance of Settings.
| Param | Type | Description |
| --- | --- | --- |
| token | string | |
| [log] | Object | |
| [req] | function | request library for resting purposes |
* MenuComposer
* [new MenuComposer(onDone, [isTopLevel])](#new_MenuComposer_new)
* [.addPostBack(title, action, [data])](#MenuComposer+addPostBack) ⇒ this
* [.addUrl(title, url, [hasExtension], [webviewHeight])](#MenuComposer+addUrl) ⇒ this
* .addNested(title) ⇒ MenuComposer
* .done() ⇒ this \| Promise
* [.menu([locale], [inputDisabled])](#MenuComposer+menu) ⇒ MenuComposer
| Param | Type | Default |
| --- | --- | --- |
| onDone | function | |
| [isTopLevel] | boolean | true |
Kind: instance method of MenuComposer
| Param | Type |
| --- | --- |
| title | string |
| action | string |
| [data] | object |
Kind: instance method of MenuComposer
| Param | Type | Default |
| --- | --- | --- |
| title | string | |
| url | string | |
| [hasExtension] | boolean | false |
| [webviewHeight] | string | null |
Kind: instance method of MenuComposer
| Param | Type |
| --- | --- |
| title | string |
Last call of "done" returns a promise
Kind: instance method of MenuComposer
Kind: instance method of MenuComposer
| Param | Type | Default |
| --- | --- | --- |
| [locale] | string | "default" |
| [inputDisabled] | boolean | false |
Kind: global function
| Param | Type |
| --- | --- |
| pageToken | string |
| [logger] | console |
Example
`javascript
const { userLoader } = require('wingbot-facebook');
bot.use(userLoader('
bot.use((req, res) => {
const {
firstName,
lastName,
profilePic,
locale,
gender
} = req.state.user;
res.text(Hello ${firstName}!);``
});
object| Name | Type |
| --- | --- |
| findAttachmentByUrl | function |
| saveAttachmentId | function |