All Projects → remixz → Messenger Bot

remixz / Messenger Bot

Licence: mit
A Node client for the Facebook Messenger Platform

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Messenger Bot

Node Fb Messenger
✉️ Facebook Messenger Platform Node.js API Wrapper
Stars: ✭ 206 (-80.94%)
Mutual labels:  bot, facebook
Swiftybot
How to create a Telegram, Facebook Messenger, and Google Assistant bot with Swift using Vapor on Ubuntu / macOS.
Stars: ✭ 247 (-77.15%)
Mutual labels:  bot, facebook
Miscord
Facebook Messenger to Discord bridge
Stars: ✭ 225 (-79.19%)
Mutual labels:  bot, facebook
Magento Chatbot
Magento Chatbot Integration with Telegram, Messenger, Whatsapp, WeChat, Skype and wit.ai.
Stars: ✭ 149 (-86.22%)
Mutual labels:  bot, facebook
Fbi
Facebook Information
Stars: ✭ 660 (-38.95%)
Mutual labels:  bot, facebook
Messenger Platform Postman Collection
A delicious Postman collection for all your Messenger Platform needs.
Stars: ✭ 150 (-86.12%)
Mutual labels:  bot, facebook
Fbmessenger Node
FB messenger for node
Stars: ✭ 52 (-95.19%)
Mutual labels:  bot, facebook
Fb Botmill
A Java framework for building bots on Facebook's Messenger Platform.
Stars: ✭ 67 (-93.8%)
Mutual labels:  bot, facebook
Pymessager
Python API to develop chatbot on Facebook Messenger Platform
Stars: ✭ 580 (-46.35%)
Mutual labels:  bot, facebook
Fb Messenger Bot
A starter Facebook Messenger Bot built in Python
Stars: ✭ 427 (-60.5%)
Mutual labels:  bot, facebook
Botkit
Botkit is an open source developer tool for building chat bots, apps and custom integrations for major messaging platforms.
Stars: ✭ 10,555 (+876.41%)
Mutual labels:  bot, facebook
Spotify Bot
Spotify Messenger Bot
Stars: ✭ 12 (-98.89%)
Mutual labels:  bot, facebook
Facebookautolikeprofessional
Auto Like reactions and unlike Facebook Status, Comments, Photos, group posts, page posts, change facebook theme and skin colors, auto tag members in group post.. Auto Comment and Auto Reply to all Comments... Facebook Auto Like Unlimited 2019 is 100% safe to use...
Stars: ✭ 101 (-90.66%)
Mutual labels:  bot, facebook
Messenger4j
A Java library for building Chatbots on the Facebook Messenger Platform - easy and fast.
Stars: ✭ 199 (-81.59%)
Mutual labels:  bot, facebook
Spam Bot 3000
Social media research and promotion, semi-autonomous CLI bot
Stars: ✭ 79 (-92.69%)
Mutual labels:  bot, facebook
Facebooktoolkit
a tool to get Facebook data, and some Facebook bots, and extra tools found on Facebook Toolkit ++.
Stars: ✭ 227 (-79%)
Mutual labels:  bot, facebook
Jbot
Make Slack and Facebook Bots in Java.
Stars: ✭ 1,148 (+6.2%)
Mutual labels:  bot, facebook
Socialmanagertools Gui
🤖 👻 Desktop application for Instagram Bot, Twitter Bot and Facebook Bot
Stars: ✭ 293 (-72.9%)
Mutual labels:  bot, facebook
Facebook Messenger
Definitely the best way to make Bots on Facebook Messenger with Ruby
Stars: ✭ 927 (-14.25%)
Mutual labels:  bot, facebook
Bootbot
Facebook Messenger Bot Framework for Node.js
Stars: ✭ 886 (-18.04%)
Mutual labels:  bot, facebook

messenger-bot

Build Status Coverage Status npm version js-standard-style

A Node client for the Facebook Messenger Platform.

Requires Node >=4.0.0.

Installation

npm install messenger-bot

Example

See more examples in the examples folder.

Run this example in the cloud: Nitrous Quickstart

  • Setup PAGE_TOKEN, VERIFY_TOKEN, APP_SECRET and start the example by Run > Start Messenger Echo Bot.
  • Your Webhook URL is available at Preview > 3000 in the IDE.
const http = require('http')
const Bot = require('messenger-bot')

let bot = new Bot({
  token: 'PAGE_TOKEN',
  verify: 'VERIFY_TOKEN',
  app_secret: 'APP_SECRET'
})

bot.on('error', (err) => {
  console.log(err.message)
})

bot.on('message', (payload, reply) => {
  let text = payload.message.text

  bot.getProfile(payload.sender.id, (err, profile) => {
    if (err) throw err

    reply({ text }, (err) => {
      if (err) throw err

      console.log(`Echoed back to ${profile.first_name} ${profile.last_name}: ${text}`)
    })
  })
})

http.createServer(bot.middleware()).listen(3000)
console.log('Echo bot server running at port 3000.')

Usage

Functions

let bot = new Bot(opts)

Returns a new Bot instance.

opts - Object

  • token - String: Your Page Access Token, found in your App settings. Required.
  • verify - String: A verification token for the first-time setup of your webhook. Optional, but will be required by Facebook when you first set up your webhook.
  • app_secret - String: Your App Secret token used for message integrity check. If specified, every POST request will be tested for spoofing. Optional.

bot.middleware()

The main middleware for your bot's webhook. Returns a function. Usage:

const http = require('http')
const Bot = require('messenger-bot')

let bot = new Bot({
  token: 'PAGE_TOKEN',
  verify: 'VERIFY_TOKEN'
})

http.createServer(bot.middleware()).listen(3000)

As well, it mounts /_status, which will return {"status": "ok"} if the middleware is running. If verify is specified in the bot options, it will mount a handler for GET requests that verifies the webhook.

bot.sendMessage(recipient, payload, [callback], [messagingType], [tag])

Sends a message with the payload to the target recipient, and calls the callback if any. Returns a promise. See Send API.

  • recipient - Number: The Facebook ID of the intended recipient.
  • payload - Object: The message payload. Should follow the Send API format.
  • callback - (Optional) Function: Called with (err, info) once the request has completed. err contains an error, if any, and info contains the response from Facebook, usually with the new message's ID.
  • messagingType - (Optional) String: The message type. Supported Messaging Type.
  • tag - (Optional) String: The tag's message. Supported Tags.

bot.getAttachmentUploadId(url, is_reusable, type, [callback])

Sends the media to the Attachment Upload API and calls the callback if the upload is successful, including the attachment_id. See Attachment Upload API.

  • url - String: Link where can be fetched the media.
  • is_reusable - Boolean: Defined if the saved asset will be sendable to other message recipients.
  • type - String: The type of media. Can be one of: image, video, audio, file.
  • callback - (Optional) Function: Called with (err, info) once the request has completed. err contains an error, if any, and info contains the response from Facebook, usually with the media's ID.

bot.sendSenderAction(recipient, senderAction, [callback])

Sends the sender action senderAction to the target recipient, and calls the callback if any. Returns a promise.

  • recipient - Number: The Facebook ID of the intended recipient.
  • senderAction - String: The sender action to execute. Can be one of: typing_on, 'typing_off', 'mark_seen'. See the Sender Actions API reference for more information.
  • callback - (Optional) Function: Called with (err, info) once the request has completed. err contains an error, if any, and info contains the response from Facebook, usually with the new message's ID.

bot.unlinkAccount(psid, [callback])

Unlinks the user with the corresponding psid, and calls the callback if any. Returns a promise. See [Account Unlink Endpoint].(https://developers.facebook.com/docs/messenger-platform/identity/account-linking?locale=en_US#unlink)

  • psid - Number: The Facebook ID of the user who has to be logged out.
  • callback - (Optional) Function: Called with (err, info) once the request has completed. err contains an error, if any, and info contains the response from Facebook.

bot.setGetStartedButton(payload, [callback])

bot.setPersistentMenu(payload, [callback])

Sets settings for the Get Started Button / Persistent Menu. See the Messenger Profile Reference for what to put in the payload.

bot.removeGetStartedButton([callback])

bot.removePersistentMenu([callback])

Removes the Get Started Button / Persistent Menu.

bot.getProfile(target, [callback])

Returns a promise of the profile information of the target, also called in the callback if any. See User Profile API.

  • target - Number: The Facebook ID of the intended target.
  • callback - (Optional) Function: Called with (err, profile) once the request has completed. err contains an error, if any, and info contains the response from Facebook, in this format:
{
  "first_name": "Zach",
  "last_name": "Bruggeman",
  "profile_pic": "<url to profile picture>",
  "locale": "en",
  "timezone": "PST",
  "gender": "M"
}

bot._handleMessage(payload)

The underlying method used by bot.middleware() to parse the message payload, and fire the appropriate events. Use this if you've already implemented your own middleware or route handlers to receive the webhook request, and just want to fire the events on the bot instance. See the echo bot implemented in Express for an example.

  • payload - Object: The payload sent by Facebook to the webhook.

bot._verify(req, res)

The underlying method used by bot.middleware() for the initial webhook verification. Use this if you've already implemented your own middleware or route handlers, and wish to handle the request without implementing bot.middleware(). See the echo bot implemented in Express for an example.

  • req - Request: The http request object.
  • res - Response: The http response object.

Events

bot.on('message', (payload, reply, actions))

Triggered when a message is sent to the bot.

  • payload - Object: An object containing the message event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
bot.on('message', (payload, reply, actions) => {
  reply({ text: 'hey!'}, (err, info) => {})
})
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().

bot.on('postback', (payload, reply, actions))

Triggered when a postback is triggered by the sender in Messenger.

  • payload - Object: An object containing the postback event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('postback', (payload, reply, actions) => {
  reply({ text: 'hey!'}, (err, info) => {})
})

bot.on('delivery', (payload, reply, actions))

Triggered when a message has been successfully delivered.

  • payload - Object: An object containing the delivery event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('delivery', (payload, reply, actions) => {
  reply({ text: 'hey!'}, (err, info) => {})
})

bot.on('authentication', (payload, reply, actions))

Triggered when a user authenticates with the "Send to Messenger" plugin.

  • payload - Object: An object containing the authentication event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('authentication', (payload, reply, actions) => {
  reply({ text: 'thanks!'}, (err, info) => {})
})

bot.on('referral', (payload, reply, actions))

Triggered when an m.me link is used with a referral param and only in a case this user already has a thread with this bot (for new threads see 'postback' event)

  • payload - Object: An object containing the authentication event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('referral', (payload, reply, actions) => {
  reply({ text: 'welcome!'}, (err, info) => {})
})

bot.on('accountLinked', (payload, reply, actions))

Triggered when an account is linked with the Account Linking Process.

  • payload - Object: An object containing the linking account event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('accountLinked', (payload, reply, actions) => {
  reply({ text: 'Logged in!'}, (err, info) => {})
})

bot.on('accountUnlinked', (payload, reply, actions))

Triggered when an account is unlinked with the Account Unlink Endpoint or with an Log Out Button.

  • payload - Object: An object containing the unlinking account event's payload from Facebook. See Facebook's documentation for the format.
  • reply - Function: A convenience function that calls bot.sendMessage, with the recipient automatically set to the message sender's Facebook ID. Example usage:
  • actions - Object: An object with two functions: setTyping(status: Boolean), and markRead().
bot.on('accountLinked', (payload, reply, actions) => {
  reply({ text: 'Logged out!'}, (err, info) => {})
})
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].