Facebook Messenger plugin for wingbot
Connector plugin for wingbot chatbot framework
Advanced features
Transfering action as a metadata of handover event
You can include a full JSON Action string to run a certain interaction in your bot using metadata in a handover event.
API
Classes
Functions
- userLoader(pageToken, [logger])
User loader middleware
Typedefs
- AttachmentCache :
object
Kind: global class
- Facebook
- new Facebook(processor, options, [senderLogger])
- .verifyWebhook(queryString) ⇒
string
- .verifyRequest(body, headers) ⇒
Promise
- .processMessage(message, senderId, pageId, data) ⇒
Promise.<{status:number}>
- .processEvent(body, [data]) ⇒
Promise.<Array.<{message:object, pageId:string}>>
new Facebook(processor, options, [senderLogger])
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 |
string
facebook.verifyWebhook(queryString) ⇒ Verifies Bots webhook against Facebook
Kind: instance method of Facebook
Throws:
Error
when the request is invalid
Param | Type |
---|---|
queryString | object |
Promise
facebook.verifyRequest(body, headers) ⇒ Verify Facebook webhook event
Kind: instance method of Facebook
Throws:
Error
when x-hub-signature does not match body signature
Param | Type |
---|---|
body | Buffer | string |
headers | object |
Promise.<{status:number}>
facebook.processMessage(message, senderId, pageId, data) ⇒ Kind: instance method of 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 |
Promise.<Array.<{message:object, pageId:string}>>
facebook.processEvent(body, [data]) ⇒ Process Facebook request
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
Kind: global class
- Settings
- new Settings()
- instance
- .greeting([text]) ⇒
Promise
- .getStartedButton([payload]) ⇒
Promise
- .whitelistDomain(domains) ⇒
Promise
- .noMenu() ⇒
Promise
- .menu([locale], [inputDisabled]) ⇒
MenuComposer
- .greeting([text]) ⇒
- static
new Settings()
Utility, which helps us to set up chatbot behavior
Promise
settings.greeting([text]) ⇒ Sets or clears bot's greeting
Kind: instance method of Settings
Param | Type | Default | Description |
---|---|---|---|
[text] | string |
false |
leave empty to clear |
Promise
settings.getStartedButton([payload]) ⇒ Sets up the Get Started Button
Kind: instance method of Settings
Param | Type | Default | Description |
---|---|---|---|
[payload] | string | object |
false |
leave blank to remove button, or provide the action |
Example
const settings = configfacebookpageToken;settings; // just an action
Promise
settings.whitelistDomain(domains) ⇒ Useful for using facebook extension in webviews
Kind: instance method of Settings
Param | Type |
---|---|
domains | string | Array.<string> |
Promise
settings.noMenu() ⇒ Drops the menu
Kind: instance method of Settings
MenuComposer
settings.menu([locale], [inputDisabled]) ⇒ Sets up the persistent menu
Kind: instance method of Settings
Param | Type | Default |
---|---|---|
[locale] | string |
"default" |
[inputDisabled] | boolean |
false |
Example
const Settings = ; const settings = 'page-token-string'; settings // the default menu ;
Settings.Settings
Kind: static class of 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
Kind: global class
new MenuComposer(onDone, [isTopLevel])
Param | Type | Default |
---|---|---|
onDone | function |
|
[isTopLevel] | boolean |
true |
this
menuComposer.addPostBack(title, action, [data]) ⇒ Add postback to menu
Kind: instance method of MenuComposer
Param | Type |
---|---|
title | string |
action | string |
[data] | object |
this
menuComposer.addUrl(title, url, [hasExtension], [webviewHeight]) ⇒ Add webview to menu
Kind: instance method of MenuComposer
Param | Type | Default |
---|---|---|
title | string |
|
url | string |
|
[hasExtension] | boolean |
false |
[webviewHeight] | string |
null |
MenuComposer
menuComposer.addNested(title) ⇒ Add Nested menu component
Kind: instance method of MenuComposer
Param | Type |
---|---|
title | string |
this
| Promise
menuComposer.done() ⇒ Finish the menu
Last call of "done" returns a promise
Kind: instance method of MenuComposer
MenuComposer
menuComposer.menu([locale], [inputDisabled]) ⇒ Finish the menu for the locale and starts a new menu
Kind: instance method of MenuComposer
Param | Type | Default |
---|---|---|
[locale] | string |
"default" |
[inputDisabled] | boolean |
false |
userLoader(pageToken, [logger])
User loader middleware
Kind: global function
Param | Type |
---|---|
pageToken | string |
[logger] | console |
Example
const userLoader = ; bot; bot;
object
AttachmentCache : Kind: global typedef
Properties
Name | Type |
---|---|
findAttachmentByUrl | function |
saveAttachmentId | function |