Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Simple Facebook Messenger Platform Bot API
npm i botly --save
const express = require("express");
const bodyParser = require("body-parser");
const Botly = require("botly");
const botly = new Botly({
accessToken: pageAccessToken, // page access token provided by facebook
verifyToken: verificationToken, // needed when using express - the verification token you provided when defining the webhook in facebook
webHookPath: yourWebHookPath, // defaults to "/",
notificationType: Botly.CONST.REGULAR, // already the default (optional)
FB_URL: 'https://graph.facebook.com/v2.6/' // this is the default - allows overriding for testing purposes
});
botly.on("message", (senderId, message, data) => {
let text = `echo: ${data.text}`;
botly.sendText({
id: senderId,
text: text
});
});
const app = express();
app.use(bodyParser.json({
verify: botly.getVerifySignature(process.env.APP_SECRET) //allow signature verification based on the app secret
}));
app.use(bodyParser.urlencoded({ extended: false }));
app.use("/webhook", botly.router());
app.listen(3000);
You can also clone the repository and run a complete bot example from the example
folder.
botly.send({
id: userId,
message: {text: "Hi There!"}
}, function (err, data) {
//log it
});
botly.upload({
type: Botly.CONST.ATTACHMENT_TYPE.IMAGE,
payload: {url: "http://example.com/image.png"}
}, (err, data) => {
//save data.attachment_id
});
botly.sendText({id: userId, text: "Hi There!"}, function (err, data) {
//log it
});
Also supports options.filedata = '@/tmp/receipt.pdf'
.
botly.sendAttachment({
id: userId,
type: Botly.CONST.ATTACHMENT_TYPE.IMAGE,
payload: {url: "http://example.com/image.png"}
}, (err, data) => {
//log it
});
botly.sendImage({id: userId, url: "http://example.com/image.png"}, (err, data) => {
//log it
});
let buttons = [];
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com"));
buttons.push(botly.createPostbackButton("Continue", "continue"));
botly.sendButtons({id: userId, text: "What do you want to do next?", buttons: buttons}
, (err, data) => {
//log it
});
let buttons = [];
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com"));
buttons.push(botly.createPostbackButton("Continue", "continue"));
let element = {
title: "What do you want to do next?",
item_url: "http://example.com",
image_url: "http://example.com/image.png",
subtitle: "Choose now!",
buttons: buttons
}
botly.sendGeneric({id: userId, elements: element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.HORIZONTAL}, (err, data) => {
console.log("send generic cb:", err, data);
});
const element = botly.createListElement({
title: 'First Element',
image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
subtitle: 'subtitle text',
buttons: [
{title: 'Payload Button', payload: 'first_element'},
],
default_action: {
'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection',
}
});
const element2 = botly.createListElement({
title: 'Other Element',
image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png',
subtitle: 'even more subtitle',
buttons: [
{title: "Go to Askrround", url: "http://askrround.com"},
],
default_action: {
'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection',
}
});
botly.sendList({id: sender, elements: [element, element2], buttons: botly.createPostbackButton('More Plans', 'MORE_PLANS'), top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE},function (err, data) {
console.log('send list cb:', err, data);
});
botly.sendAction({id: userId, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, (err, data) => {
//log it
});
let payload = {
"recipient_name": "Stephane Crozatier",
"order_number": "12345678902",
"currency": "USD",
"payment_method": "Visa 2345",
"order_url": "http://petersapparel.parseapp.com/order?order_id=123456",
"timestamp": "1428444852",
"elements": [
{
"title": "Classic White T-Shirt",
"subtitle": "100% Soft and Luxurious Cotton",
"quantity": 2,
"price": 50,
"currency": "USD",
"image_url": "http://petersapparel.parseapp.com/img/whiteshirt.png"
},
{
"title": "Classic Gray T-Shirt",
"subtitle": "100% Soft and Luxurious Cotton",
"quantity": 1,
"price": 25,
"currency": "USD",
"image_url": "http://petersapparel.parseapp.com/img/grayshirt.png"
}
],
"address": {
"street_1": "1 Hacker Way",
"street_2": "",
"city": "Menlo Park",
"postal_code": "94025",
"state": "CA",
"country": "US"
},
"summary": {
"subtotal": 75.00,
"shipping_cost": 4.95,
"total_tax": 6.19,
"total_cost": 56.14
},
"adjustments": [
{
"name": "New Customer Discount",
"amount": 20
},
{
"name": "$10 Off Coupon",
"amount": 10
}
]
};
botly.sendReceipt({id: sender, payload: payload}, function (err, data) {
console.log("send generic cb:", err, data);
});
botly.setGetStarted({pageId: "myPage", payload: "GET_STARTED_CLICKED"}, (err, body) => {
//log it
});
botly.setGreetingText({
pageId: "myPage",
greeting: [{
"locale":"default",
"text":"Hello!"
}, {
"locale":"en_US",
"text":"Timeless apparel for the masses."
}]}, (err, body) => {
//log it
});
botly.setTargetAudience({
pageId: "myPage",
audience: {
"audience_type":"custom",
"countries":{
"whitelist":["US", "CA"]
}
}}, (err, body) => {
//log it
});
botly.setWhitelist({whiteList: ["https://askhaley.com"]}, (err, body) => {
//log it
});
botly.setPersistentMenu({
pageId: "myPage",
menu: [
{
"locale":"default",
"composer_input_disabled":true,
"call_to_actions":[
{
"title":"My Account",
"type":"nested",
"call_to_actions":[
{
"title":"Pay Bill",
"type":"postback",
"payload":"PAYBILL_PAYLOAD"
},
{
"title":"History",
"type":"postback",
"payload":"HISTORY_PAYLOAD"
},
{
"title":"Contact Info",
"type":"postback",
"payload":"CONTACT_INFO_PAYLOAD"
}
]
},
{
"type":"web_url",
"title":"Latest News",
"url":"http://petershats.parseapp.com/hat-news",
"webview_height_ratio":"full"
}
]
},
{
"locale":"zh_CN",
"composer_input_disabled":false
}
]}, (err, body) => {
//log it
});
botly.removePersistentMenu(
{
pageId: "myPage",
},
(err, body) => {
//log it
});
Also supports passing an object as {id: userId, accessToken: OTHER_TOKEN}
botly.getUserProfile(userId, function (err, info) {
//cache it
});
Used to retrieve the user page-scoped ID (PSID) during the linking flow.
Also supports passing an object as {token: accountLinkingToken, accessToken: OTHER_TOKEN}
botly.getUserProfile(accountLinkingToken, function (err, info) {
//cache it
});
sendAttachment
and sendText
both support optional quick_replies
share location quick reply
Will create a list element. default_action
will be added web_url
type, and will create button according to properties (url
means web_url
and payload
means postback
)
Where buttons
can be a single button or an array of buttons.
Where elements
can be a single element or an array of elements.
and aspectRatio
defaults to horizontal
Where options
has bottons
and elements
- an array will be created automatically if a single item was passed.
If you are not using express, you can use this function to parse the request from facebook in order to generate the proper events.
req
should have a body property.
botly.on("message", (sender, message, data) => {
/**
* where data can be a text message or an attachment
* data = {
* text: "text entered by user"
* }
* OR
* data = {
* attachments: {
* image: ["imageURL1", "imageURL2"],
* video: ["videoURL"],
* audio: ["audioURL1"],
* location: [{coordinates}]
* }
* }
*/
});
botly.on("postback", (sender, message, postback, ref) => {
/**
* where postback is the postback payload
* and ref will arrive if m.me params were passed on a get started button (if defined)
*/
});
botly.on("delivery", (sender, message, mids) => {
/**
* where mids is an array of mids
*/
});
botly.on("optin", (sender, message, optin) => {
/**
* where optin is the ref pass through param
*/
});
botly.on("error", (ex) => {
/* handle exceptions */
});
botly.on("sent", (to, message) => {
/* track it */
});
botly.on("echo", (sender, message, content, recipient) => {
/* track it */
});
botly.on("account_link", (sender, message, link) => {
/**
* where link is the the object containing the status and authorization code
*/
});
botly.on("referral", (sender, message, ref) => {
/**
* where ref is the data in the m.me param
*/
});
messaging_type
parameter when sending messageFB_URL
for testing purposesgetVerifySignature(APP_SECRET)
function to allow signature verification - provide the result to bodyParser.json({verify})
setPersistentMenu
API aligned with v1.4setGreetingText
, setAccountLinkingURL
, setTargetAudience
APIsendAttachment
sendAction
(mark seen/ typing on/ typing off)createTemplate
function - was too verboseFAQs
Simple Facebook Messenger Bot API
We found that botly demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.