
Security News
Python Adopts Standard Lock File Format for Reproducible Installs
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
launch-vehicle-fbm
Advanced tools
An event driven SDK for Facebook Messenger chat bots.
To make writing for the platform easier, this project wraps the Messenger calls up in a library. It also supports a login with Facebook flow since Messenger does not provide this natively.
const { Messenger } = require('launch-vehicle-fbm');
const messenger = new Messenger(options);
messenger.start(); // Start listening
port
(default: 3000
)hookPath
(default: /webhook
)linkPath
(default: /link
)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.
We 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', ({senderId, text}) => {
if (text.includes('corgis')) {
messenger.send(senderId, new Text('aRf aRf!'))
.then(() => messenger.send(senderId, new Image('https://i.imgur.com/izwcQLS.jpg')));
}
});
messenger.start();
The event name and what's in the data
for each event handler:
message
Any kind of message event. This is sent in addition to the events for specific message types.
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatemessage
Direct access to event.message
text
Text message
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatesource
One of quickReply
, postback
, text
text
Message content, event.message.text
for text events, payload
for postback
and quickReply
eventstext.greeting
(optional, defaults to enabled) Text messages that match common greetings
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatefirstName
Trimmed first name from the user's public Facebook profilesurName
Trimmed first name from the user's public Facebook profilefullName
Concatenating of firstName
and surName
with a single, separating spacetext.help
(optional, defaults to enabled) Text messages that match requests for assistance
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatemessage.image
Image (both attached and from user's camera)
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutateurl
Direct access to event.message.attachments[0].payload.url
for the url of the imagemessage.sticker
Sticker
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatemessage.thumbsup
User clicked the "thumbsup"/"like" button
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatemessage.text
For conversation, use the text
event
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatetext
Message content, event.message.text
for text eventsmessage.quickReply
For conversation, use the text
event, this is for the raw message sent via a quick reply button
event
The raw eventsenderId
The ID of the sendersession
A Session object you can mutatesource
One of quickReply
, postback
, text
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
event
The raw eventsenderId
The ID of the senderpayload
Direct access to event.postback.payload
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.
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.
Some factories for generating responses are available at the top level and are
also available in a responses
object if you need a namespace:
const { Text, Image, Generic, ImageQuickReply } = require('launch-vehicle-fbm');
const { responses } = require('launch-vehicle-fbm');
// responses.Text, responses.Image, etc.
The most common response is text:
new Text('Hello World')
Images just need a url. These also show up in the "Shared Photos" rail.
new Image('https://i.imgur.com/ehSTCkO.gif')
There are a few others that are supported too:
new Generic(elements[])
https://developers.facebook.com/docs/messenger-platform/send-api-reference/generic-templatenew ImageQuickReply('https://i.imgur.com/ehSTCkO.gif', quickReplies[])
NOTE: the syntax for quick replies may change in the future since it's orthogonal to Text
and Image
.
https://developers.facebook.com/docs/messenger-platform/send-api-reference/quick-repliesText
translationText
supports gettext-like functionality if your project has a
messages.js
in its root. Using this sample:
module.exports = {
greeting_msg: 'Hello World!'
};
new Text('greeting_msg')
would be equivalent of doing new Text('Hello World!')
.
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 activitysource
: 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
UnknownOptional 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.1.0
f7500fc63a
] - Add: Kill killswitch for events that come in via message_echoes (#37)a343c478ce
] - Docs: Remove example key-value pairs that do not apply to the SDK (#35)FAQs
An event driven SDK for Facebook Messenger chat bots.
The npm package launch-vehicle-fbm receives a total of 24 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
Python has adopted a standardized lock file format to improve reproducibility, security, and tool interoperability across the packaging ecosystem.
Security News
OpenGrep has restored fingerprint and metavariable support in JSON and SARIF outputs, making static analysis more effective for CI/CD security automation.
Security News
Security experts warn that recent classification changes obscure the true scope of the NVD backlog as CVE volume hits all-time highs.