Skip to content

A Botkit middleware to handle Facebook Messenger quick reply intuitively without breaking any existing code

License

Notifications You must be signed in to change notification settings

hey-mako/botkit-fb-quick-reply

Repository files navigation

botkit-fb-quick-reply Build Status npm version

A Botkit middleware to handle Facebook Messenger's quick reply in an intuitive manner.

Using this Botkit middleware allows your controller to "listen" on Facebook Messenger quick reply payloads instead of the quick reply label/text. It also supports backward compatibility to prevent breaking any existing code.

The message object updates to the following:

message.payload = message.quick_reply.payload;
message.text = message.quick_reply.payload;
message.label = message.quick_reply.text;
message.type = eventName || 'facebook_quick_reply';

Install

$ npm install --save botkit-fb-quick-reply

Usage

const quickReplyMiddleware = require('botkit-fb-quick-reply');

// Load the middleware
quickReplyMiddleware(controller);
// Now the controller can handle "facebook_quick_reply" events and set messages accordingly
// messages.label = quick reply text label
// message.payload = quick reply payload

// Listen to events by the payload
controller.hears('MY_QUICK_REPLY_PAYLOAD', 'facebook_quick_reply', doSomething);

// Listen to a payload from a postback OR quick reply
controller.hears('MY_QUICK_REPLY_PAYLOAD', ['facebook_quick_reply', 'facebook_postback'], doSomethingElse);

API

botkitFbQuickReply(controller [, options])

controller

Type: object

A botkit configured controller

options

Configure the middleware

options.eventName

Type: string
Default: facebook_quick_reply

Override the default quick reply event name. For example, you can use facebook_postback if you have overlapping functionalities from the menu or quick replies.

options.backwardsCompatibility

Type: boolean
Default: false

Triggers a message_received in the default behavior, and in the new facebook_quick_reply event. Thus activate this if you want backward compatibility, but want to use the newer means of handling quick reply events.

License

MIT © Mako AI

About

A Botkit middleware to handle Facebook Messenger quick reply intuitively without breaking any existing code

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published