Facebook Messenger plugin for wingbot
Connector plugin for wingbot chatbot framework
API
Classes
- Facebook
- Settings
- MenuComposer
Functions
- userLoader(pageToken)
User loader middleware
Facebook
Kind: global class
new Facebook(processor, options)
Param | Type | Description |
---|
processor | Processor | |
options | Object | |
options.pageToken | string | facebook page token |
[options.botToken] | string | botToken for webhook verification |
[options.appSecret] | string | provide app secret to verify requests |
[options.requestLib] | function | request library replacement |
[options.senderLogger] | console | optional console like chat logger |
facebook.verifyWebhook(queryString) ⇒ string
Verifies Bots webhook against Facebook
Kind: instance method of Facebook
Throws:
Error
when the request is invalid
Param | Type |
---|
queryString | Object |
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 |
facebook.processEvent(body) ⇒ Promise.<Array.<{message:Object, pageId:string}>>
Process Facebook request
Kind: instance method of Facebook
Returns: Promise.<Array.<{message:Object, pageId:string}>>
- - unprocessed events
Param | Type | Description |
---|
body | Object | event body |
Settings
Kind: global class
new Settings()
Utility, which helps us to set up chatbot behavior
settings.greeting([text]) ⇒ Promise
Sets or clears bot's greeting
Kind: instance method of Settings
Param | Type | Default | Description |
---|
[text] | string | false | leave empty to clear |
settings.getStartedButton([payload]) ⇒ Promise
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 = new Settings(config.facebook.pageToken);
settings.getStartedButton('/start');
settings.whitelistDomain(domains) ⇒ Promise
Useful for using facebook extension in webviews
Kind: instance method of Settings
Param | Type |
---|
domains | string | Array.<string> |
Sets up the persistent menu
Kind: instance method of Settings
Param | Type | Default |
---|
[locale] | string | "default" |
[inputDisabled] | boolean | false |
Example
const { Settings } = require(''wingbot');
const settings = new Settings('page-token-string');
settings
.menu('fr_FR')
.addNested('Nested Menu')
.addUrl('Aller à google', 'https:
.done()
.addPostBack('Faire quelque chose', '/the/action')
.menu()
.addNested('Nested Menu')
.addUrl('Go to google', 'https://google.com')
.done()
.addPostBack('Do something', '/the/action')
.done();
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 |
Kind: global class
Param | Type | Default |
---|
onDone | function | |
[isTopLevel] | boolean | true |
Add postback to menu
Kind: instance method of MenuComposer
Param | Type |
---|
title | string |
action | string |
[data] | Object |
Add webview to menu
Kind: instance method of MenuComposer
Param | Type | Default |
---|
title | string | |
url | string | |
[hasExtension] | boolean | false |
[webviewHeight] | string | null |
Add Nested menu component
Kind: instance method of MenuComposer
Finish the menu
Last call of "done" returns a promise
Kind: instance method of MenuComposer
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)
User loader middleware
Kind: global function
Example
const { userLoader } = require('wingbot-facebook');
bot.use(userLoader('<page token here>'));
bot.use((req, res) => {
const {
firstName,
lastName,
profilePic,
locale,
gender
} = req.state.user;
res.text(`Hello ${firstName}!`);
});