Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

botly

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

botly - npm Package Compare versions

Comparing version 1.1.6 to 1.2.0

87

lib/Botly.js

@@ -13,3 +13,4 @@ 'use strict';

WEB_URL: 'web_url',
ACCOUNT_LINK: 'account_link'
ACCOUNT_LINK: 'account_link',
SHARE: 'element_share'
};

@@ -37,2 +38,7 @@

const CONTENT_TYPE = {
TEXT: 'text',
LOCATION: 'location'
};
const ACTION_TYPES = {

@@ -44,2 +50,8 @@ MARK_SEEN: 'mark_seen',

const WEBVIEW_HEIGHT_RATIO = {
FULL: 'full',
TALL: 'tall',
COMPACT: 'compact'
};
function Botly(options) {

@@ -67,3 +79,4 @@ if (!(this instanceof Botly)) {

router.get(this.webHookPath, (req, res) => {
if (req.query['hub.verify_token'] === this.verifyToken) {
if (req.query['hub.mode'] === 'subscribe' &&
req.query['hub.verify_token'] === this.verifyToken) {
res.send(req.query['hub.challenge']);

@@ -184,2 +197,25 @@ } else {

Botly.prototype.setWhiteList = function (options, callback) {
const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`;
request.post(
{
url: PAGE_URL,
json: true,
qs: {
access_token: this.accessToken || options.accessToken
},
body: {
setting_type: 'domain_whitelisting',
whitelisted_domains: options.whiteList,
domain_action_type: options.actionType || 'add'
}
}, (err, res, body) => {
if (callback) {
callback(err, body);
}
});
};
Botly.prototype.send = function (options, callback) {

@@ -243,4 +279,7 @@ options.notificationType = options.notificationType || this.notificationType;

options.payload = options.payload || {
url: options.url
url: options.url,
};
if (options.is_reusable) {
options.payload.is_reusable = options.is_reusable;
}
options.type = ATTACHMENT_TYPE.IMAGE;

@@ -278,4 +317,4 @@ this.sendAttachment(options, callback);

Botly.prototype.createWebURLButton = function (title, url) {
return {
Botly.prototype.createWebURLButton = function (title, url, heightRatio, supportExtension, fallbackURL) {
let button = {
type: BUTTON_TYPE.WEB_URL,

@@ -285,2 +324,12 @@ title: title,

};
if (heightRatio) {
button.webview_height_ratio = heightRatio;
}
if (supportExtension) {
button.messenger_extensions = supportExtension;
}
if (fallbackURL) {
button.fallback_url = fallbackURL;
}
return button;
};

@@ -295,2 +344,8 @@

Botly.prototype.createShareButton = function () {
return {
type: BUTTON_TYPE.SHARE,
};
};
Botly.prototype.createPostbackButton = function (title, payload) {

@@ -304,10 +359,20 @@ return {

Botly.prototype.createQuickReply = function (title, payload) {
return {
'content_type': 'text',
Botly.prototype.createQuickReply = function (title, payload, imageURL) {
let reply = {
'content_type': CONTENT_TYPE.TEXT,
'title': title,
'payload': payload
'payload': payload,
};
if (imageURL) {
reply.image_url = imageURL;
}
return reply;
};
Botly.prototype.createShareLocation = function () {
return {
'content_type': CONTENT_TYPE.LOCATION,
};
};
Botly.prototype.createButtonTemplate = function (text, buttons) {

@@ -415,5 +480,7 @@ if (!Array.isArray(buttons)) {

NOTIFICATION_TYPE: NOTIFICATION_TYPE,
ACTION_TYPES: ACTION_TYPES
ACTION_TYPES: ACTION_TYPES,
CONTENT_TYPE: CONTENT_TYPE,
WEBVIEW_HEIGHT_RATIO: WEBVIEW_HEIGHT_RATIO
};
module.exports = Botly;

6

package.json
{
"name": "botly",
"version": "1.1.6",
"version": "1.2.0",
"description": "Simple Facebook Messenger Bot API",

@@ -23,3 +23,5 @@ "main": "index.js",

"Botly",
"msg"
"msg",
"sdk",
"api"
],

@@ -26,0 +28,0 @@ "author": {

@@ -27,2 +27,3 @@ <img src="https://raw.githubusercontent.com/Askrround/botly/master/botly_logo.png" width="250" height="250" />

- [setGetStarted (options[, callback])](#setgetstarted-options-callback)
- [setWhitelist (options[, callback])](#setwhitelist-options-callback)
- [setPersistentMenu (options[, callback])](#setpersistentmenue-options-callback)

@@ -34,3 +35,5 @@ - [getUserProfile (userId[, callback])](#getuserprofile-userid-callback)

- [createPostbackButton (title, payload)](#createpostbackbutton-title-payload)
- [createQuickReply (title, payload)](#createquickreply-title-payload)
- [createShareButton ()](#createsharebutton)
- [createQuickReply (title, payload[, imageURL])](#createquickreply-title-payload-imageurl)
- [createShareLocation ()](#createsharelocation)
- [createButtonTemplate (text, buttons)](#createbuttontemplate-text-buttons)

@@ -59,3 +62,6 @@ - [createGenericTemplate (elements)](#creategenerictemplate-elements)

botly.sendText(senderId, text);
botly.sendText({
id: senderId,
text: text
});
});

@@ -206,2 +212,9 @@

#### setWhitelist (options[, callback])
```javascript
botly.setWhitelist({whiteList: ["https://askhaley.com"], actionType: "add" /*default*/}, function (err, body) {
//log it
});
```
#### setPersistentMenu (options[, callback])

@@ -233,3 +246,3 @@ ```javascript

#### createWebURLButton (title, url)
#### createWebURLButton (title, url[, heightRatio][, supportExtension][, fallbackURL])

@@ -240,5 +253,10 @@ #### createAccountLinkButton (url)

#### createQuickReply (title, payload)
### createShareButton ()
#### createQuickReply (title, payload[, imageURL])
`sendAttachment` and `sendText` both support optional `quick_replies`
### createShareLocation ()
share location quick reply
#### createButtonTemplate (text, buttons)

@@ -313,2 +331,9 @@ Where `buttons` can be a single button or an array of buttons.

### version 1.2.0
- added support for webview height in web url button
- added support setWhitelist for webview items
- added createShare button
- added support for location share quick reply
- added imageURL to quick reply
#### version 1.1.6

@@ -315,0 +340,0 @@ - Send 403 status code when verify token is invalid

@@ -73,2 +73,3 @@ var expect = require('chai').expect;

query: {
'hub.mode': 'subscribe',
'hub.verify_token': 'myVerifyToken',

@@ -83,3 +84,30 @@ 'hub.challenge': '42'

});
it('should provide an express router and reject correct verify_token if hub.mode is not "subscribe"', () => {
var botly = new Botly({
accessToken: 'myToken',
verifyToken: 'myVerifyToken',
webHookPath: '/webhook',
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});
var router = botly.router();
expect(router).to.be.defined;
var response = http.createResponse();
var request = http.createRequest({
method: 'GET',
url: '/webhook',
query: {
'hub.mode': 'SubscribE',
'hub.verify_token': 'myVerifyToken',
'hub.challenge': '42'
}
});
router.handle(request, response);
expect(response.statusCode).to.equal(403);
expect(response._getData()).to.equal('Error, wrong validation token');
});
it('should provide an express router and handle bad verify_token', () => {

@@ -101,2 +129,3 @@

query: {
'hub.mode': 'subscribe',
'hub.verify_token': '111',

@@ -561,3 +590,3 @@ 'hub.challenge': '42'

botly.sendText({id: USER_ID, text: 'hi', quick_replies: [botly.createQuickReply('option1', 'option_1')]}, ()=> {
botly.sendText({id: USER_ID, text: 'hi', quick_replies: [botly.createQuickReply('option1', 'option_1', 'http://google.com/someimage.png'), botly.createShareLocation()]}, ()=> {
});

@@ -573,3 +602,7 @@

'title': 'option1',
'payload': 'option_1'
'payload': 'option_1',
'image_url': 'http://google.com/someimage.png'
},
{
'content_type': 'location'
}

@@ -594,3 +627,3 @@ ]

botly.sendImage({id: USER_ID, url: 'http://image.com'});
botly.sendImage({id: USER_ID, url: 'http://image.com', is_reusable: true});

@@ -602,3 +635,4 @@ expect(request.post.calledOnce).to.be.true;

'payload': {
'url': 'http://image.com'
'url': 'http://image.com',
'is_reusable': true
},

@@ -627,3 +661,3 @@ 'type': 'image'

text: 'What do you want to do next?',
buttons: botly.createPostbackButton('Continue', 'continue')
buttons: botly.createPostbackButton('Continue', 'continue'),
}, function (err, data) {

@@ -672,3 +706,3 @@ });

subtitle: 'Choose now!',
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com'), botly.createAccountLinkButton('http://askrround.com/login')]
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com'), botly.createAccountLinkButton('http://askrround.com/login'), botly.createShareButton()]
};

@@ -693,2 +727,5 @@ botly.sendGeneric({id: USER_ID, elements: element});

'url': 'http://askrround.com/login'
},
{
'type': 'element_share'
}

@@ -715,2 +752,56 @@ ],

it('should send webview buttons', () => {
var botly = new Botly({
accessToken: 'myToken',
verifyToken: 'myVerifyToken',
webHookPath: '/webhook',
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});
var element = {
title: 'What do you want to do next?',
item_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
image_url: 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
subtitle: 'Choose now!',
buttons: [botly.createWebURLButton('Go to Askrround', 'http://askrround.com', Botly.CONST.WEBVIEW_HEIGHT_RATIO.COMPACT, true, 'http://askrround.com')]
};
botly.sendGeneric({id: USER_ID, elements: element});
expect(request.post.calledOnce).to.be.true;
expect(request.post.args[0][0].body).to.eql({
'message': {
'attachment': {
'payload': {
'elements': [
{
'buttons': [
{
'title': 'Go to Askrround',
'type': 'web_url',
'url': 'http://askrround.com',
'webview_height_ratio': 'compact',
'messenger_extensions': true,
'fallback_url': 'http://askrround.com'
}
],
'image_url': 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
'item_url': 'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg',
'subtitle': 'Choose now!',
'title': 'What do you want to do next?'
}
],
'template_type': 'generic'
},
'type': 'template'
}
},
'notification_type': 'NO_PUSH',
'recipient': {
'id': '333'
}
});
});
it('should send receipt messages', () => {

@@ -963,2 +1054,24 @@ var botly = new Botly({

it('should setwhitelist', () => {
request.post.yields(null, {});
var botly = new Botly({
accessToken: 'myToken',
verifyToken: 'myVerifyToken',
webHookPath: '/webhook',
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH
});
botly.setWhiteList({whiteList: ["https://askhaley.com"], actionType: 'add'}, ()=> {
});
expect(request.post.calledOnce).to.be.true;
expect(request.post.args[0][0].body).to.eql({
'whitelisted_domains': ["https://askhaley.com"],
'setting_type': 'domain_whitelisting',
'domain_action_type': 'add'
});
});
it('should set persistent menu', () => {

@@ -965,0 +1078,0 @@ request.post.yields(null, {});

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc