Comparing version 1.3.5 to 1.4.0
#!/usr/bin/env node | ||
"use strict"; | ||
'use strict'; | ||
const express = require('express'); | ||
@@ -11,5 +11,5 @@ const path = require('path'); | ||
const Botly = require("../index"); | ||
const Botly = require('../index'); | ||
const botly = new Botly({ | ||
verifyToken: "this_is_a_token", | ||
verifyToken: 'this_is_a_token', | ||
accessToken: process.env.ACCESS_TOKEN | ||
@@ -26,19 +26,19 @@ }); | ||
if (users[sender]) { | ||
if (data && data.text && data.text.indexOf("image") !== -1) { | ||
botly.sendImage({id: sender, url:"https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg"}, function (err, whatever) { | ||
if (data && data.text && data.text.indexOf('image') !== -1) { | ||
botly.sendImage({id: sender, url:'https://upload.wikimedia.org/wikipedia/en/9/93/Tanooki_Mario.jpg'}, function (err, whatever) { | ||
console.log(err); | ||
}); | ||
} | ||
else if (data && data.text &&data.text.indexOf("buttons") !== -1) { | ||
else if (data && data.text &&data.text.indexOf('buttons') !== -1) { | ||
let buttons = []; | ||
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com")); | ||
buttons.push(botly.createPostbackButton("Continue", "continue")); | ||
botly.sendButtons({id: sender, text: "What do you want to do next?", buttons: buttons}, function (err, data) { | ||
console.log("send buttons cb:", err, data); | ||
buttons.push(botly.createWebURLButton('Go to Askrround', 'http://askrround.com')); | ||
buttons.push(botly.createPostbackButton('Continue', 'continue')); | ||
botly.sendButtons({id: sender, text: 'What do you want to do next?', buttons: buttons}, function (err, data) { | ||
console.log('send buttons cb:', err, data); | ||
}); | ||
} | ||
else if (data && data.text && data.text.indexOf("generic") !== -1) { | ||
else if (data && data.text && data.text.indexOf('generic') !== -1) { | ||
let buttons = []; | ||
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com")); | ||
buttons.push(botly.createPostbackButton("Continue", "continue")); | ||
buttons.push(botly.createWebURLButton('Go to Askrround', 'http://askrround.com')); | ||
buttons.push(botly.createPostbackButton('Continue', 'continue')); | ||
let element = { | ||
@@ -51,86 +51,86 @@ title: 'What do you want to do next?', | ||
}; | ||
botly.sendGeneric({id: sender, elements:element}, function (err, data) { | ||
console.log("send generic cb:", err, data); | ||
botly.sendGeneric({id: sender, elements:element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.SQUARE}, function (err, data) { | ||
console.log('send generic cb:', err, data); | ||
}); | ||
} | ||
else if (data && data.text && data.text.indexOf("list") !== -1) { | ||
else if (data && data.text && data.text.indexOf('list') !== -1) { | ||
let element = botly.createListElement({ | ||
title: "Classic T-Shirt Collection", | ||
image_url: "https://peterssendreceiveapp.ngrok.io/img/collection.png", | ||
subtitle: "See all our colors", | ||
title: 'Classic T-Shirt Collection', | ||
image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png', | ||
subtitle: 'See all our colors', | ||
buttons: [ | ||
{title: "DO WORK", payload: "DO_WORK"}, | ||
{title: 'DO WORK', payload: 'DO_WORK'}, | ||
], | ||
default_action: { | ||
"url": "https://peterssendreceiveapp.ngrok.io/shop_collection", | ||
'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection', | ||
} | ||
}); | ||
let element2 = botly.createListElement({ | ||
title: "Number 2", | ||
image_url: "https://peterssendreceiveapp.ngrok.io/img/collection.png", | ||
subtitle: "See all our colors", | ||
title: 'Number 2', | ||
image_url: 'https://peterssendreceiveapp.ngrok.io/img/collection.png', | ||
subtitle: 'See all our colors', | ||
buttons: [ | ||
{title: "Go to Askrround", url: "http://askrround.com"}, | ||
{title: 'Go to Askrround', url: 'http://askrround.com'}, | ||
], | ||
default_action: { | ||
"url": "https://peterssendreceiveapp.ngrok.io/shop_collection", | ||
'url': 'https://peterssendreceiveapp.ngrok.io/shop_collection', | ||
} | ||
}); | ||
botly.sendList({id: sender, elements: [element, element2], buttons: botly.createPostbackButton("Continue", "continue"), top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE},function (err, data) { | ||
console.log("send list cb:", err, data); | ||
botly.sendList({id: sender, elements: [element, element2], buttons: botly.createPostbackButton('Continue', 'continue'), top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE},function (err, data) { | ||
console.log('send list cb:', err, data); | ||
}); | ||
} | ||
else if (data && data.text && data.text.indexOf("quick") !== -1) { | ||
botly.sendText({id: sender, text:"some question?", quick_replies: [botly.createQuickReply('option1', 'option_1')]}, function (err, data) { | ||
console.log("send generic cb:", err, data); | ||
else if (data && data.text && data.text.indexOf('quick') !== -1) { | ||
botly.sendText({id: sender, text:'some question?', quick_replies: [botly.createQuickReply('option1', 'option_1')]}, function (err, data) { | ||
console.log('send generic cb:', err, data); | ||
}); | ||
} | ||
else if (data && data.text && data.text.indexOf("receipt") !== -1) { | ||
else if (data && data.text && data.text.indexOf('receipt') !== -1) { | ||
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": [ | ||
'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 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" | ||
'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" | ||
'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 | ||
'summary': { | ||
'subtotal': 75.00, | ||
'shipping_cost': 4.95, | ||
'total_tax': 6.19, | ||
'total_cost': 56.14 | ||
}, | ||
"adjustments": [ | ||
'adjustments': [ | ||
{ | ||
"name": "New Customer Discount", | ||
"amount": 20 | ||
'name': 'New Customer Discount', | ||
'amount': 20 | ||
}, | ||
{ | ||
"name": "$10 Off Coupon", | ||
"amount": 10 | ||
'name': '$10 Off Coupon', | ||
'amount': 10 | ||
} | ||
@@ -140,3 +140,3 @@ ] | ||
botly.sendReceipt({id: sender, payload: payload}, function (err, data) { | ||
console.log("send generic cb:", err, data); | ||
console.log('send generic cb:', err, data); | ||
}); | ||
@@ -148,3 +148,3 @@ } | ||
}}, function (err, data) { | ||
console.log("regular send cb:", err, data); | ||
console.log('regular send cb:', err, data); | ||
}); | ||
@@ -158,3 +158,3 @@ } | ||
botly.sendText({id: sender, text: `${text} ${users[sender].first_name}`}, function (err, data) { | ||
console.log("send text cb:", err, data); | ||
console.log('send text cb:', err, data); | ||
}); | ||
@@ -166,15 +166,15 @@ }); | ||
botly.on('postback', (sender, message, postback) => { | ||
console.log("postback:", sender, message, postback); | ||
console.log('postback:', sender, message, postback); | ||
}); | ||
botly.on('delivery', (sender, message, mids) => { | ||
console.log("delivery:", sender, message, mids); | ||
console.log('delivery:', sender, message, mids); | ||
}); | ||
botly.on('optin', (sender, message, optin) => { | ||
console.log("optin:", sender, message, optin); | ||
console.log('optin:', sender, message, optin); | ||
}); | ||
botly.on('error', (ex) => { | ||
console.log("error:", ex); | ||
console.log('error:', ex); | ||
}); | ||
@@ -184,7 +184,55 @@ | ||
botly.setGetStarted({pageId: process.env.PAGE_ID, payload: 'GET_STARTED_CLICKED'}, function (err, body) { | ||
console.log("welcome cb:", err, body); | ||
console.log('welcome cb:', err, body); | ||
}); | ||
botly.setPersistentMenu({pageId: process.env.PAGE_ID, buttons: [botly.createPostbackButton('reset', 'reset_me')]}, function (err, body) { | ||
console.log("persistent menu cb:", err, body); | ||
}) | ||
botly.setPersistentMenu({pageId: process.env.PAGE_ID, 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) => { | ||
console.log('persistent menu cb:', err, body); | ||
}); | ||
botly.setTargetAudience({ | ||
pageId: process.env.PAGE_ID, | ||
audience: { | ||
'audience_type':'custom', | ||
'countries':{ | ||
'whitelist':['US', 'CA'] | ||
} | ||
}}, (err, body) => { | ||
console.log('set target audience', err, body); | ||
}); | ||
} | ||
@@ -191,0 +239,0 @@ |
126
lib/Botly.js
@@ -61,2 +61,7 @@ 'use strict'; | ||
const IMAGE_ASPECT_RATIO = { | ||
HORIZONTAL: 'horizontal', | ||
SQUARE: 'square' | ||
}; | ||
function Botly(options) { | ||
@@ -152,54 +157,47 @@ if (!(this instanceof Botly)) { | ||
Botly.prototype.setGetStarted = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`; | ||
options.body = { | ||
get_started: { | ||
payload: options.payload | ||
} | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
request.post( | ||
{ | ||
url: PAGE_URL, | ||
json: true, | ||
qs: { | ||
access_token: this.accessToken || options.accessToken | ||
}, | ||
body: { | ||
setting_type: 'call_to_actions', | ||
thread_state: 'new_thread', | ||
call_to_actions: [ | ||
{ | ||
payload: options.payload | ||
} | ||
] | ||
} | ||
Botly.prototype.setGreetingText = function (options, callback) { | ||
options.body = { | ||
greeting: options.greeting | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
}, (err, res, body) => { | ||
if (callback) { | ||
callback(err, body); | ||
} | ||
}); | ||
Botly.prototype.setPersistentMenu = function (options, callback) { | ||
options.body = { | ||
persistent_menu: options.menu | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
Botly.prototype.setGreetingText = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`; | ||
Botly.prototype.setWhiteList = function (options, callback) { | ||
options.body = { | ||
whitelisted_domains: options.whiteList, | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
request.post( | ||
{ | ||
url: PAGE_URL, | ||
json: true, | ||
qs: { | ||
access_token: this.accessToken || options.accessToken | ||
}, | ||
body: { | ||
setting_type: 'greeting', | ||
"greeting":{ | ||
"text": options.text | ||
} | ||
} | ||
Botly.prototype.setTargetAudience = function (options, callback) { | ||
options.body = { | ||
target_audience: options.audience, | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
}, (err, res, body) => { | ||
if (callback) { | ||
callback(err, body); | ||
} | ||
}); | ||
Botly.prototype.setAccountLinkingURL = function (options, callback) { | ||
options.body = { | ||
account_linking_url: options.url, | ||
}; | ||
this.setProfile(options, callback); | ||
}; | ||
Botly.prototype.setPersistentMenu = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`; | ||
Botly.prototype.setProfile = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/messenger_profile`; | ||
@@ -213,7 +211,3 @@ request.post( | ||
}, | ||
body: { | ||
setting_type: 'call_to_actions', | ||
thread_state: 'existing_thread', | ||
call_to_actions: options.buttons | ||
} | ||
body: options.body | ||
@@ -227,5 +221,13 @@ }, (err, res, body) => { | ||
Botly.prototype.setWhiteList = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/thread_settings`; | ||
Botly.prototype.upload = function (options, callback) { | ||
const PAGE_URL = `${FB_URL}${options.pageId}/message_attachments`; | ||
options.message = options.message || { | ||
attachment: { | ||
type: options.type, | ||
payload: options.payload | ||
} | ||
}; | ||
if (options.filedata) { | ||
options.message.filedata = options.filedata; | ||
} | ||
request.post( | ||
@@ -239,7 +241,4 @@ { | ||
body: { | ||
setting_type: 'domain_whitelisting', | ||
whitelisted_domains: options.whiteList, | ||
domain_action_type: options.actionType || 'add' | ||
message: options.message | ||
} | ||
}, (err, res, body) => { | ||
@@ -302,2 +301,5 @@ if (callback) { | ||
}; | ||
if (options.filedata) { | ||
options.message.filedata = options.filedata; | ||
} | ||
if (options.quick_replies) { | ||
@@ -337,3 +339,3 @@ options.message.quick_replies = options.quick_replies; | ||
Botly.prototype.sendGeneric = function (options, callback) { | ||
options.payload = this.createGenericTemplate(options.elements); | ||
options.payload = this.createGenericTemplate(options.elements, options.aspectRatio); | ||
options.type = ATTACHMENT_TYPE.TEMPLATE; | ||
@@ -436,3 +438,3 @@ this.sendAttachment(options, callback); | ||
if (buttons) { | ||
if(!Array.isArray(buttons)) { | ||
if (!Array.isArray(buttons)) { | ||
buttons = [buttons]; | ||
@@ -465,3 +467,3 @@ } | ||
Botly.prototype.createGenericTemplate = function (elements) { | ||
Botly.prototype.createGenericTemplate = function (elements, aspectRatio) { | ||
if (!Array.isArray(elements)) { | ||
@@ -471,2 +473,3 @@ elements = [elements]; | ||
return { | ||
image_aspect_ratio: aspectRatio || IMAGE_ASPECT_RATIO.HORIZONTAL, | ||
template_type: TEMPLATE_TYPE.GENERIC, | ||
@@ -489,3 +492,3 @@ elements: elements | ||
if (buttons) { | ||
if(!Array.isArray(buttons)) { | ||
if (!Array.isArray(buttons)) { | ||
buttons = [buttons]; | ||
@@ -591,5 +594,6 @@ } | ||
WEBVIEW_HEIGHT_RATIO: WEBVIEW_HEIGHT_RATIO, | ||
TOP_ELEMENT_STYLE: TOP_ELEMENT_STYLE | ||
TOP_ELEMENT_STYLE: TOP_ELEMENT_STYLE, | ||
IMAGE_ASPECT_RATIO: IMAGE_ASPECT_RATIO | ||
}; | ||
module.exports = Botly; |
{ | ||
"name": "botly", | ||
"version": "1.3.5", | ||
"version": "1.4.0", | ||
"description": "Simple Facebook Messenger Bot API", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
115
README.md
@@ -19,2 +19,3 @@ <img src="https://raw.githubusercontent.com/miki2826/botly/master/botly_logo.png" width="250" height="250" /> | ||
- [send (options[, callback])](#send-options-callback) | ||
- [upload (options[, callback])](#upload-options-callback) | ||
- [sendText (options[, callback])](#sendtext-options-callback) | ||
@@ -29,2 +30,4 @@ - [sendAttachment (options[, callback])](#sendattachment-options-callback) | ||
- [setGetStarted (options[, callback])](#setgetstarted-options-callback) | ||
- [setGreetingText (options[, callback])](#setgreetingtext-options-callback) | ||
- [setTargetAudience (options[, callback])](#settargetaudience-options-callback) | ||
- [setWhitelist (options[, callback])](#setwhitelist-options-callback) | ||
@@ -42,3 +45,3 @@ - [setPersistentMenu (options[, callback])](#setpersistentmenue-options-callback) | ||
- [createButtonTemplate (text, buttons)](#createbuttontemplate-text-buttons) | ||
- [createGenericTemplate (elements)](#creategenerictemplate-elements) | ||
- [createGenericTemplate (elements[, aspectRatio])](#creategenerictemplate-elements-aspectratio) | ||
- [createListTemplate (options)](#createlisttemplate-options) | ||
@@ -91,2 +94,12 @@ - [handleMessage (req)](#handlemessage-req) | ||
#### upload (options[, callback]) | ||
```javascript | ||
botly.upload({ | ||
type: Botly.CONST.ATTACHMENT_TYPE.IMAGE, | ||
payload: {url: "http://example.com/image.png"} | ||
}, (err, data) => { | ||
//save data.attachment_id | ||
}); | ||
``` | ||
#### sendText (options[, callback]) | ||
@@ -100,2 +113,3 @@ ```javascript | ||
#### sendAttachment (options[, callback]) | ||
Also supports `options.filedata = '@/tmp/receipt.pdf'`. | ||
```javascript | ||
@@ -106,3 +120,3 @@ botly.sendAttachment({ | ||
payload: {url: "http://example.com/image.png"} | ||
}, function (err, data) { | ||
}, (err, data) => { | ||
//log it | ||
@@ -114,3 +128,3 @@ }); | ||
```javascript | ||
botly.sendImage({id: userId, url: "http://example.com/image.png"}, function (err, data) { | ||
botly.sendImage({id: userId, url: "http://example.com/image.png"}, (err, data) => { | ||
//log it | ||
@@ -126,3 +140,3 @@ }); | ||
botly.sendButtons({id: userId, text: "What do you want to do next?", buttons: buttons} | ||
, function (err, data) { | ||
, (err, data) => { | ||
//log it | ||
@@ -144,3 +158,3 @@ }); | ||
} | ||
botly.sendGeneric({id: userId, elements: element}, function (err, data) { | ||
botly.sendGeneric({id: userId, elements: element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.HORIZONTAL}, (err, data) => { | ||
console.log("send generic cb:", err, data); | ||
@@ -163,3 +177,3 @@ }); | ||
}); | ||
botly.sendList({id: userId, elements: element, buttons: buttons}, function (err, data) { | ||
botly.sendList({id: userId, elements: element, buttons: buttons}, (err, data) => { | ||
console.log("send generic cb:", err, data); | ||
@@ -171,3 +185,3 @@ }); | ||
```javascript | ||
botly.sendAction({id: userId, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, function (err, data) { | ||
botly.sendAction({id: userId, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, (err, data) => { | ||
//log it | ||
@@ -236,3 +250,3 @@ }); | ||
```javascript | ||
botly.setGetStarted({pageId: "myPage", payload: "GET_STARTED_CLICKED"}, function (err, body) { | ||
botly.setGetStarted({pageId: "myPage", payload: "GET_STARTED_CLICKED"}, (err, body) => { | ||
//log it | ||
@@ -242,5 +256,34 @@ }); | ||
#### setGreetingText (options[, callback]) | ||
```javascript | ||
botly.setGreetingText({ | ||
pageId: "myPage", | ||
greeting: [{ | ||
"locale":"default", | ||
"text":"Hello!" | ||
}, { | ||
"locale":"en_US", | ||
"text":"Timeless apparel for the masses." | ||
}]}, (err, body) => { | ||
//log it | ||
}); | ||
``` | ||
#### setTargetAudience (options[, callback]) | ||
```javascript | ||
botly.setTargetAudience({ | ||
pageId: "myPage", | ||
audience: { | ||
"audience_type":"custom", | ||
"countries":{ | ||
"whitelist":["US", "CA"] | ||
} | ||
}}, (err, body) => { | ||
//log it | ||
}); | ||
``` | ||
#### setWhitelist (options[, callback]) | ||
```javascript | ||
botly.setWhitelist({whiteList: ["https://askhaley.com"], actionType: "add" /*default*/}, function (err, body) { | ||
botly.setWhitelist({whiteList: ["https://askhaley.com"]}, (err, body) => { | ||
//log it | ||
@@ -252,3 +295,43 @@ }); | ||
```javascript | ||
botly.setPersistentMenu({pageId: "myPage", buttons: [botly.createPostbackButton('reset', 'reset_me')]}, function (err, body) { | ||
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 | ||
@@ -297,4 +380,5 @@ }); | ||
#### createGenericTemplate (elements) | ||
#### createGenericTemplate (elements[, aspectRatio]) | ||
Where `elements` can be a single element or an array of elements. | ||
and `aspectRatio` defaults to `horizontal` | ||
@@ -373,2 +457,11 @@ #### createListTemplate (options) | ||
### version 1.4.0 | ||
- support version 1.4 of messenger api | ||
- new `setPersistentMenu` API aligned with v1.4 | ||
- added `setGreetingText`, `setAccountLinkingURL`, `setTargetAudience` API | ||
- aligned all thread settings to the new profile API | ||
- added support for filedata upload in the `sendAttachment` | ||
- added support for the new upload attachment API, | ||
- support for new image_aspect_ratio in generic template | ||
### version 1.3.0 | ||
@@ -375,0 +468,0 @@ - support version 1.3 of messenger including the new list template |
@@ -83,3 +83,3 @@ var expect = require('chai').expect; | ||
}); | ||
it('should provide an express router and reject correct verify_token if hub.mode is not "subscribe"', () => { | ||
@@ -325,4 +325,4 @@ | ||
var linkContent = { | ||
"status":"linked", | ||
"authorization_code":"PASS_THROUGH_AUTHORIZATION_CODE" | ||
"status": "linked", | ||
"authorization_code": "PASS_THROUGH_AUTHORIZATION_CODE" | ||
}; | ||
@@ -542,3 +542,3 @@ var botly = new Botly({ | ||
botly.sendText({id: USER_ID, text: 'hi'}, ()=> { | ||
botly.sendText({id: USER_ID, text: 'hi'}, () => { | ||
}); | ||
@@ -568,3 +568,3 @@ | ||
botly.sendAction({id: USER_ID, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, ()=> { | ||
botly.sendAction({id: USER_ID, action: Botly.CONST.ACTION_TYPES.TYPING_ON}, () => { | ||
}); | ||
@@ -591,3 +591,7 @@ | ||
botly.sendText({id: USER_ID, text: 'hi', quick_replies: [botly.createQuickReply('option1', 'option_1', 'http://google.com/someimage.png'), botly.createShareLocation()]}, ()=> { | ||
botly.sendText({ | ||
id: USER_ID, | ||
text: 'hi', | ||
quick_replies: [botly.createQuickReply('option1', 'option_1', 'http://google.com/someimage.png'), botly.createShareLocation()] | ||
}, () => { | ||
}); | ||
@@ -648,2 +652,27 @@ | ||
it('should upload attachment', () => { | ||
var botly = new Botly({ | ||
accessToken: 'myToken', | ||
verifyToken: 'myVerifyToken', | ||
webHookPath: '/webhook', | ||
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH | ||
}); | ||
botly.upload({type: Botly.CONST.ATTACHMENT_TYPE.IMAGE, payload: {url: 'http://image.com', is_reusable: true}}); | ||
expect(request.post.calledOnce).to.be.true; | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'message': { | ||
'attachment': { | ||
'payload': { | ||
'url': 'http://image.com', | ||
'is_reusable': true | ||
}, | ||
'type': 'image' | ||
} | ||
} | ||
}); | ||
}); | ||
it('should send button messages', () => { | ||
@@ -706,3 +735,3 @@ var botly = new Botly({ | ||
}; | ||
botly.sendGeneric({id: USER_ID, elements: element}); | ||
botly.sendGeneric({id: USER_ID, elements: element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.HORIZONTAL}); | ||
@@ -736,2 +765,3 @@ expect(request.post.calledOnce).to.be.true; | ||
], | ||
'image_aspect_ratio': 'horizontal', | ||
'template_type': 'generic' | ||
@@ -771,3 +801,8 @@ }, | ||
}); | ||
botly.sendList({id: USER_ID, elements: element, buttons: botly.createPostbackButton("Continue", "continue"), top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE}); | ||
botly.sendList({ | ||
id: USER_ID, | ||
elements: element, | ||
buttons: botly.createPostbackButton("Continue", "continue"), | ||
top_element_style: Botly.CONST.TOP_ELEMENT_STYLE.LARGE | ||
}); | ||
@@ -866,2 +901,3 @@ expect(request.post.calledOnce).to.be.true; | ||
], | ||
'image_aspect_ratio': 'horizontal', | ||
'template_type': 'generic' | ||
@@ -901,3 +937,3 @@ }, | ||
}; | ||
botly.sendGeneric({id: USER_ID, elements: element}); | ||
botly.sendGeneric({id: USER_ID, elements: element, aspectRatio: Botly.CONST.IMAGE_ASPECT_RATIO.SQUARE}); | ||
@@ -927,2 +963,3 @@ expect(request.post.calledOnce).to.be.true; | ||
], | ||
'image_aspect_ratio': 'square', | ||
'template_type': 'generic' | ||
@@ -1000,3 +1037,3 @@ }, | ||
}; | ||
botly.sendReceipt({id: USER_ID, payload: payload, notificationType:Botly.CONST.NOTIFICATION_TYPE.REGULAR}); | ||
botly.sendReceipt({id: USER_ID, payload: payload, notificationType: Botly.CONST.NOTIFICATION_TYPE.REGULAR}); | ||
@@ -1174,3 +1211,3 @@ expect(request.post.calledOnce).to.be.true; | ||
botly.setGetStarted({pageId: PAGE_ID, payload: 'GET_STARTED_CLICKED'}, ()=> { | ||
botly.setGetStarted({pageId: PAGE_ID, payload: 'GET_STARTED_CLICKED'}, () => { | ||
}); | ||
@@ -1180,9 +1217,40 @@ | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'call_to_actions': [ | ||
'get_started': { | ||
'payload': 'GET_STARTED_CLICKED' | ||
} | ||
}); | ||
}); | ||
it('should set greeting text', () => { | ||
request.post.yields(null, {}); | ||
var botly = new Botly({ | ||
accessToken: 'myToken', | ||
verifyToken: 'myVerifyToken', | ||
webHookPath: '/webhook', | ||
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH | ||
}); | ||
botly.setGreetingText({pageId: PAGE_ID, greeting: [ | ||
{ | ||
"locale":"default", | ||
"text":"Hello!" | ||
}, { | ||
"locale":"en_US", | ||
"text":"Timeless apparel for the masses." | ||
} | ||
]}, () => { | ||
}); | ||
expect(request.post.calledOnce).to.be.true; | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'greeting': [ | ||
{ | ||
'payload': 'GET_STARTED_CLICKED' | ||
"locale":"default", | ||
"text":"Hello!" | ||
}, { | ||
"locale":"en_US", | ||
"text":"Timeless apparel for the masses." | ||
} | ||
], | ||
'setting_type': 'call_to_actions', | ||
'thread_state': 'new_thread' | ||
] | ||
}); | ||
@@ -1192,3 +1260,2 @@ | ||
it('should setwhitelist', () => { | ||
@@ -1203,3 +1270,3 @@ request.post.yields(null, {}); | ||
botly.setWhiteList({whiteList: ["https://askhaley.com"], actionType: 'add'}, ()=> { | ||
botly.setWhiteList({whiteList: ["https://askhaley.com"]}, () => { | ||
}); | ||
@@ -1209,5 +1276,3 @@ | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'whitelisted_domains': ["https://askhaley.com"], | ||
'setting_type': 'domain_whitelisting', | ||
'domain_action_type': 'add' | ||
'whitelisted_domains': ["https://askhaley.com"] | ||
}); | ||
@@ -1217,2 +1282,31 @@ | ||
it('should set target audience', () => { | ||
request.post.yields(null, {}); | ||
var botly = new Botly({ | ||
accessToken: 'myToken', | ||
verifyToken: 'myVerifyToken', | ||
webHookPath: '/webhook', | ||
notificationType: Botly.CONST.NOTIFICATION_TYPE.NO_PUSH | ||
}); | ||
botly.setTargetAudience({audience: { | ||
"audience_type":"custom", | ||
"countries":{ | ||
"whitelist":["US", "CA"] | ||
} | ||
}}, () => { | ||
}); | ||
expect(request.post.calledOnce).to.be.true; | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'target_audience': { | ||
"audience_type":"custom", | ||
"countries":{ | ||
"whitelist":["US", "CA"] | ||
} | ||
} | ||
}); | ||
}); | ||
it('should set persistent menu', () => { | ||
@@ -1227,3 +1321,43 @@ request.post.yields(null, {}); | ||
botly.setPersistentMenu({pageId: PAGE_ID, buttons: [botly.createPostbackButton('reset', 'reset_me')]}, ()=> { | ||
botly.setPersistentMenu({ | ||
pageId: PAGE_ID, 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 | ||
} | ||
] | ||
}, () => { | ||
}); | ||
@@ -1233,11 +1367,41 @@ | ||
expect(request.post.args[0][0].body).to.eql({ | ||
'call_to_actions': [ | ||
'persistent_menu': [ | ||
{ | ||
type: 'postback', | ||
title: 'reset', | ||
payload: 'reset_me' | ||
"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 | ||
} | ||
], | ||
'setting_type': 'call_to_actions', | ||
'thread_state': 'existing_thread' | ||
] | ||
}); | ||
@@ -1248,2 +1412,2 @@ | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
120822
22
2086
489
7