Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
launch-vehicle-fbm
Advanced tools
An event driven SDK for Facebook Messenger chat bots.
FBM is a full-featured, opinionated Facebook Messenger SDK for writing bots. In addition to wrappers around the Messenger API, you get:
const { Messenger } = require('launch-vehicle-fbm');
const messenger = new Messenger(options);
messenger.start(); // Start listening
cache
(default: cacheman memory cache) See Session cachehookPath
(default: /webhook
)pages
: A map of page ids to page access tokens {1029384756: 'ThatsAReallyLongStringYouGotThere'}
. Currently optional but config will migrate to this in the futureport
(default: 3000
)emitGreetings
(default: true)
When enabled, emits common greetings as text.greeting
events.
When disabled, no check is run and text
events will be emitted.
Optionally, can be set to a RexExp
object which will enable the option and use the specified expression instead of the built-in default.Additional options are set via environment variables. See example.env
for an
example.
/webhook
(override with options.hookPath
) -- The Messenger webbhook/pause
-- Dashbot compatible pause for live person takeovers. See Dashbot's docs for usage. Currently, pauses only last for 12 hours in case the operator forgets to unpauseWe emit a variety of events. Attach listeners like:
// General form
// messenger.on(eventName, ({dataItem1, dataItem2}) => {});
const { Messenger, Text, Image } = require('launch-vehicle-fbm');
const messenger = new Messenger();
messenger.on('text', ({reply, text}) => {
if (text.includes('corgis')) {
reply(new Text('aRf aRf!'))
.then(() => reply(new Image('https://i.imgur.com/izwcQLS.jpg')));
}
});
messenger.start();
data
All events contain the following attributes in the data
:
event
The raw eventreply: Function
Reply back to the user with the argumentssenderId
The ID of the sendersession
A Session object you can mutateIn addition, data
contains these attributes on specific events:
text
Text message
source
One of quickReply
, postback
, text
text
Original message content: event.message.text
for text events and payload
for postback
and quickReply
eventsnormalizedText
Normalized message contenttext.greeting
(optional, defaults to enabled) Text messages that match common greetings
firstName
Trimmed first name from the user's public Facebook profilefullName
Concatenating of firstName
and surName
with a single, separating spacesurName
Trimmed first name from the user's public Facebook profiletext.help
(optional, defaults to enabled) Text messages that match requests for assistance
message
Any kind of message event. This is sent in addition to the events for specific message types.
message
Direct access to event.message
message.image
Image (both attached and from user's camera)
url
Direct access to event.message.attachments[0].payload.url
for the url of the imagemessage.quickReply
For conversation, use the text
event, this is for the raw message sent via a quick reply button
payload
Quick reply content, event.quick_reply.payload
message.thumbsup
User clicked the "thumbsup"/"like" button
message.sticker
Sticker
message.text
For conversation, use the text
event
text
Message content: event.message.text
message.quickReply
For conversation, use the text
event, this is for the raw message sent via a quick reply button
payload
Quick reply content: event.quick_reply.payload
postback
For conversation, use the text
event, this is for the raw message sent via a postback
payload
Postback content: event.postback.payload
referral
Fires when a user scans your Messenger code
referral
Referral content (from Facebook):
referral.ref
A custom ref
for a parametric codereferral.source
MESSENGER_CODE
referral.type
OPEN_THREAD
app.starting
signal that the Messenger.start
has been called and the application is in the process of coming online
app.started
signal that the SDK's Express server is now listening on the specified port
and ready for requests
finish
(optional) Signal that you're done processing. This is mostly useful for your tests when you have Promise chains. The SDK currently does nothing
with this event.
To help keep application code simple, the SDK makes these guarantees about normalized text:
If you enable message_echoes
in your Messenger webhooks, you'll get bot
messages too. You'll need to examine event.message.is_echo
in your handlers.
The SDK uses cacheman to maintain session data per user. The session
object is passed through each event
and can be read from or written to as needed. While the session is automatically saved in routeEachMessage
,
there are instances where it may be advantageous to manually trigger a save; this can be accomplished by using
messenger.saveSession
. The session object has a copy of its own session key (pro tip: do not modify or remove
_key
) so the session object is the only parameter that needs to be passed into saveSession
.
The SDK sets some values in the session:
count
: int
how many events have been received from this userlastSeen
: int
The time (in milliseconds since epoch time) we last saw activityprofile
: Object
, the profile as retrieved from Facebook Messenger. See the docs for the most up to date information. If a profile can't be pulled, it's {}
, otherwise, here are some of the more useful fields for quick reference:
profile.first_name
: first nameprofile.last_name
: last nameprofile.profile_pic
: profile picturesource
: string|undefined
A guess of where the user came from for this session:
direct
TODO, not implemented yetreturn
A returning visitorweb
Came from a "Send to Messenger" button on a websiteundefined
UnknownIf you want to customize the cache, you can supply your own cache in the
Messenger
constructor. By default, it uses the cacheman memory cache, but
any cache that follows these simple patterns will work:
cache.get(key: string): ?Promise<Object>
cache.set(key: string, value: Object): Promise<Object>
We strongly suggest using something like Redis that will persist across restarts. There are examples in the wiki.
require('launch-vehicle-fbm').SESSION_TIMEOUT_MS
: This constant is available if you need some sort of magic number for what to consider a session lengthMessenger.app
: The base Express app is available for you hereOptional environment variables:
DASHBOT_KEY
- If this is present, dashbot integration will be on
LOG_FILE
– winston will log conversations to this file. It should be an absolute path
SLACK_CHANNEL
- The Slack channel winston should use, can be a name or an id
SLACK_WEBHOOK_URL
– The webhook url is required for winston to send to Slack
There are many other Messenger Node packages; we made a page to help you decide if this is the appropriate one for your project: https://github.com/CondeNast/launch-vehicle-fbm/wiki/Prior-art
1.10.0
FAQs
An event driven SDK for Facebook Messenger chat bots.
The npm package launch-vehicle-fbm receives a total of 12 weekly downloads. As such, launch-vehicle-fbm popularity was classified as not popular.
We found that launch-vehicle-fbm demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.