Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@cs-chatbots/wingbot-facebook

Package Overview
Dependencies
Maintainers
7
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cs-chatbots/wingbot-facebook

Facebook Messenger plugin for wingbot

  • 3.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
7
Created
Source

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.

{
  "sender":{
    "id":"<PSID>"
  },
  "recipient":{
    "id":"<PAGE_ID>"
  },
  "timestamp":1458692752478,
  "pass_thread_control":{
    "new_owner_app_id":"123456789",
    "metadata":"{\"action\":\"your-action\",\"data\":{}}"
  }
}

API

Classes

Facebook
Settings
MenuComposer

Functions

userLoader(pageToken, [logger])

User loader middleware

Typedefs

AttachmentCache : object

Facebook

Kind: global class

new Facebook(processor, options, [senderLogger])

ParamTypeDescription
processorProcessor
optionsobject
options.pageTokenstringfacebook page token
options.appIdstringfacebook app id
[options.botToken]stringbotToken for webhook verification
[options.appSecret]stringprovide app secret to verify requests
[options.passThreadAction]stringtrigger this action for pass thread event
[options.takeThreadAction]stringtrigger this action for take thread event
[options.requestThreadAction]stringtrigger this action when thread request
[options.allowEventKeys]Array.<string>list of keys, allowed to process
[options.throwsExceptions]booleanallows processEvents method to thow exception
[options.apiUrl]stringoverride Facebook API url
[options.attachmentStorage]AttachmentCachecache for reusing attachments
[options.requestLib]functionrequest library replacement
[senderLogger]consoleoptional console like chat logger

facebook.DEFAULT_EVENT_KEYS

Kind: instance property of Facebook
Properties

NameTypeDescription
DefaultArray.<string>keys allowed to process

facebook.verifyWebhook(queryString) ⇒ string

Verifies Bots webhook against Facebook

Kind: instance method of Facebook
Throws:

  • Error when the request is invalid
ParamType
queryStringobject

facebook.verifyRequest(body, headers) ⇒ Promise

Verify Facebook webhook event

Kind: instance method of Facebook
Throws:

  • Error when x-hub-signature does not match body signature
ParamType
bodyBuffer | string
headersobject

facebook.processMessage(message, senderId, pageId, data) ⇒ Promise.<{status:number}>

Kind: instance method of Facebook

ParamTypeDescription
messageobjectwingbot chat event
senderIdstringchat event sender identifier
pageIdstringchannel/page identifier
dataobjectcontextual data (will be available in res.data)
[data.appId]stringpossibility to override appId

facebook.processEvent(body, [data]) ⇒ Promise.<Array.<{message:object, pageId:string}>>

Process Facebook request

Kind: instance method of Facebook
Returns: Promise.<Array.<{message:object, pageId:string}>> - - unprocessed events

ParamTypeDescription
bodyobjectevent body
[data]objectevent context data

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

ParamTypeDefaultDescription
[text]stringfalseleave empty to clear

settings.getStartedButton([payload]) ⇒ Promise

Sets up the Get Started Button

Kind: instance method of Settings

ParamTypeDefaultDescription
[payload]string | objectfalseleave blank to remove button, or provide the action

Example

const settings = new Settings(config.facebook.pageToken);
settings.getStartedButton('/start'); // just an action

settings.whitelistDomain(domains) ⇒ Promise

Useful for using facebook extension in webviews

Kind: instance method of Settings

ParamType
domainsstring | Array.<string>

settings.noMenu() ⇒ Promise

Drops the menu

Kind: instance method of Settings

settings.menu([locale], [inputDisabled]) ⇒ MenuComposer

Sets up the persistent menu

Kind: instance method of Settings

ParamTypeDefault
[locale]string"default"
[inputDisabled]booleanfalse

Example

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.Settings

Kind: static class of Settings

new Settings(token, [log], [req])

Creates an instance of Settings.

ParamTypeDescription
tokenstring
[log]Object
[req]functionrequest library for resting purposes

MenuComposer

Kind: global class

new MenuComposer(onDone, [isTopLevel])

ParamTypeDefault
onDonefunction
[isTopLevel]booleantrue

menuComposer.addPostBack(title, action, [data]) ⇒ this

Add postback to menu

Kind: instance method of MenuComposer

ParamType
titlestring
actionstring
[data]object

menuComposer.addUrl(title, url, [hasExtension], [webviewHeight]) ⇒ this

Add webview to menu

Kind: instance method of MenuComposer

ParamTypeDefault
titlestring
urlstring
[hasExtension]booleanfalse
[webviewHeight]stringnull

menuComposer.addNested(title) ⇒ MenuComposer

Add Nested menu component

Kind: instance method of MenuComposer

ParamType
titlestring

menuComposer.done() ⇒ this | Promise

Finish the menu

Last call of "done" returns a promise

Kind: instance method of MenuComposer

menuComposer.menu([locale], [inputDisabled]) ⇒ MenuComposer

Finish the menu for the locale and starts a new menu

Kind: instance method of MenuComposer

ParamTypeDefault
[locale]string"default"
[inputDisabled]booleanfalse

userLoader(pageToken, [logger])

User loader middleware

Kind: global function

ParamType
pageTokenstring
[logger]console

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}!`);
});

AttachmentCache : object

Kind: global typedef
Properties

NameType
findAttachmentByUrlfunction
saveAttachmentIdfunction

Keywords

FAQs

Package last updated on 01 Feb 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc