node-fb-messenger npm

:envelope: Facebook Messenger Platform NodeJS API Wrapper

node-fb-messenger npm npm js-standard-style npm

Facebook Messenger Platform NodeJS API Wrapper

bitHound Overall Score Codacy Badge Code Climate

Installation

npm install fb-messenger --save

API

You must require fb-messenger and create an instance

// Constructor
var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(token[, notificationType])

// Functions
messenger.sendTextMessage(id, message[, notificationType][, cb]) // Sends a text message

messenger.sendImageMessage(id, imageURL[, notificationType][, cb]) // Sends an image from URL

messenger.sendHScrollMessage(id, elements[, notificationType][, cb]) // Sends an H-SCroll generic message

messenger.sendButtonsMessage(id, message, buttons[, notificationType][, cb]) // Sends a buttons message

messenger.sendReceiptMessage(id, payload[, notificationType][, cb]) // Sends a receipt message (No need for template_type in payload) 

messenger.sendQuickRepliesMessage(id, attachment, quickReplies[, notificationType][, cb]) // Sends a Quick Replies Message

messenger.sendMessage(id, messageData[, notificationType][, cb]) // Send a message from custom data

messenger.sendAction(id, actionType) // Send an action type (One of 'mark_seen', 'typing_on', 'typing_off')

messenger.getProfile(id, cb) // Gets user information

messenger.setWelcomeMessage(pageId, message[, cb]) // Sets Page's Welcome Message (message can be a text string or a strucuted message)

messenger.setGreetingText (pageId, message[, cb]) // Sets Page's Greeting Text

messenger.setPersistentMenu (pageId, menuItems[, cb]) // Set's Page's Persistent Menu

messenger.sendThreadSettingsMessage (pageId, jsonObject[, cb]) // Send Manually Page's Thread Settings

Notification Types:

  • REGULAR
  • SILENT_PUSH
  • NO_PUSH

Examples

Basic Example

var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(<YOUR TOKEN>)

messenger.sendTextMessage(<ID>, 'Hello')

Callback Example

var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(<YOUR TOKEN>)

messenger.sendTextMessage(<ID>, 'Hello', function (err, body) {
  if(err) return console.error(err)
  console.log(body)
})

No push Example

var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(<YOUR TOKEN>)

messenger.sendTextMessage(<ID>, 'Hello', 'NO_PUSH')

Default to silent push Example

var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(<YOUR TOKEN>, 'SILENT_PUSH')

messenger.sendTextMessage(<ID>, 'Hello')

Complete Example

var FBMessenger = require('fb-messenger')
var messenger = new FBMessenger(<YOUR TOKEN>, 'NO_PUSH')

messenger.sendTextMessage(<ID>, 'Hello') // Send a message with NO_PUSH, no callback

// Send an image overriding default notification type with callback
messenger.sendImageMessage(<ID>, <IMG URL>, 'REGULAR', function (err, body) {
  if (err) return console.error(err)
  console.log('Image sent successfully')
})

License

MIT. Copyright © Diego Rodríguez Baquero.

Related Repositories

node-fb-messenger

node-fb-messenger

:envelope: Facebook Messenger Platform NodeJS API Wrapper ...

fb-messenger-bot

fb-messenger-bot

Node.js application that serves webhook for Facebook Messenger API ...

fbmessenger-node

fbmessenger-node

FB messenger for node ...

anonbot-fb

anonbot-fb

Messenger chatbot in Node.js for anonymous chatting with random strangers using Facebook Messenger platform ...


Top Contributors

DiegoRBaquero tyvdh greenkeeperio-bot ryanscottaudio

Releases

-   v1.0.0 zip tar
-   v0.1.7 zip tar