Facebook Messenger Platform NodeJS API Wrapper
Installation
Requires Node 8+
npm install fb-messenger --save
API
You must require fb-messenger and create an instance
// Constructorconst FBMessenger = const messenger = token notificationType// token is optional, if not included, must be sent in each method, notificationType is optional, default = 'REGULAR' messenger // Sets the instance token messenger // Sets the instance notificationType // Methods (notificationType and token are optional)messenger // Sends a text message messenger // Sends an audio from URL messenger // Sends an video from URL messenger // Sends an image from URL messenger // Sends an file from URL messenger // Sends a Quick Replies Message messenger // Sends a buttons template message messenger // Sends a generic template message messenger // Sends a list template message messenger // Sends a media template message messenger // Sends an open graph template message messenger // Sends a receipt template message (No need for template_type in payload) messenger // Send an action type (One of 'mark_seen', 'typing_on', 'typing_off') messenger // Send a message from custom data messenger // Gets user information messenger // Sets Page's Welcome Message (message can be a text string or a strucuted message) messenger // Sets Page's Greeting Text messenger // Set's Page's Persistent Menu messenger // Set's Page's Whitelisted Domains messenger // Send Manually Page's Thread Settings
Notification Types:
- REGULAR
- SILENT_PUSH
- NO_PUSH
Examples
Basic Example
const FBMessenger = const messenger = token: '<YOUR TOKEN>' // Will always use this page's token for request unless sent on each method messenger
Catch errors Example
const FBMessenger = const messenger = token: '<YOUR TOKEN>' try const response = await messenger console catch e console
No push Example
const FBMessenger = const messenger = token: '<YOUR TOKEN>' messenger
Default to silent push Example
const FBMessenger = const messenger = token: '<YOUR TOKEN>' notificationType: 'SILENT_PUSH'
Complete Example
const FBMessenger = const messenger = token: '<YOUR TOKEN>' notificationType: 'NO_PUSH' try await messenger // Send a message with NO_PUSH, ignoring response console catche console // Send an image overriding default notification type with callbacktry const response = await messenger console consoledirresponse catche console messenger // Send message on another page
License
MIT. Copyright © Diego Rodríguez Baquero