0.1.0 • Published 7 years ago

messenger-body v0.1.0

Weekly downloads
4
License
MIT
Repository
github
Last release
7 years ago

NPM version Build Status

Solid, reliable, extensible, framework agnostic body parser and processor for Facebook Messenger bots.

messenger-body is a solid, reliable, extensible body parser and processor for Facebook Messenger bots. messenger-body parses a Facebook Messenger HTTP body, normalizes each message and executes a handler function for each message.

Key Features

  • Solid. 100% test coverage.
  • Extensible. Augment messages with existing and custom plugins.
  • Framework Agnostic. Works with Express, Koa, Restify and every other HTTP framework.

This module is intended for developers who implement framework or server specific modules on top of messenger-body.

If you are looking to use messenger-body with Express or Restify, please see express-messenger-body.

Installation

$ npm install --save messenger-body

Usage

const app = require('express')()
const MessengerEventLoop = require('messenger-body')
app.use(function(req, res) {

})

function handleMessage(message) {
  ...
}

Implementing your Message Handler function

messenger-body calls your Message Handler function for each incoming message it receives.

express-event-loop creates it

Postback message

{
  topic: 'postback.SHOW_FLIGHTS'
  data:  <parsed JSON payload>
}

quick_reply message

{
  topic: 'quick_reply.BOOK_FLIGHT'
  data:  <parsed JSON payload>
}

Text message

{
  topic: 'text'
  data:  'Hello, World!'
}

Use cases for plugins

  • Load the user’s profile data from facebook
  • Store user data in your own database

Features

Plugins

JSON payloads for postback and quick_reply

100% Test Coverage

Framework Agnostic

Supported Events

Webhook EventDescription
messagesSubscribes to Message Received events
message_deliveriesSubscribes to Message Delivered events
message_readsSubscribes to Message Read events
message_echoesSubscribes to Message Echo events
messaging_postbacksSubscribes to Postback Received events
messaging_optinsSubscribes to Plugin Opt-in events
messaging_referralsSubscribes to Referral events
messaging_checkout_updates (BETA)Subscribes to Checkout Update events
messaging_payments (BETA)Subscribes to Payment events
messaging_account_linkingSubscribes to Account Linking events
messaging_policy_enforcementSubscribes to Policy Enforcement events

License

MIT © Andreas Pizsa