Comparing version 1.4.2 to 1.4.3
@@ -22,3 +22,4 @@ 'use strict'; | ||
GENERIC: 'generic', | ||
LIST: 'list' | ||
LIST: 'list', | ||
OPEN_GRAPH: 'open_graph' | ||
}; | ||
@@ -356,2 +357,8 @@ | ||
Botly.prototype.sendOpenGraph = function (options, callback) { | ||
options.payload = this.createOpenGraphTemplate(options.elements); | ||
options.type = ATTACHMENT_TYPE.TEMPLATE; | ||
this.sendAttachment(options, callback); | ||
}; | ||
Botly.prototype.sendList = function (options, callback) { | ||
@@ -492,2 +499,20 @@ options.payload = this.createListTemplate(options); | ||
Botly.prototype.createOpenGraphElement = function (url, title) { | ||
let button = Botly.prototype.createWebURLButton(title, url); | ||
return { | ||
url: url, | ||
buttons: [ button ] | ||
}; | ||
}; | ||
Botly.prototype.createOpenGraphTemplate = function (elements) { | ||
if (!Array.isArray(elements)) { | ||
elements = [elements]; | ||
} | ||
return { | ||
template_type: TEMPLATE_TYPE.OPEN_GRAPH, | ||
elements: elements | ||
}; | ||
}; | ||
Botly.prototype.createListTemplate = function (options) { | ||
@@ -518,3 +543,4 @@ let elements = options.elements; | ||
body.entry.forEach(entry => { | ||
entry.messaging.forEach(message => { | ||
if (entry.messaging && entry.messaging.length) { | ||
entry.messaging.forEach(message => { | ||
_handleOptIn.call(this, message); | ||
@@ -528,3 +554,4 @@ _handleDelivery.call(this, message); | ||
_handleEcho.call(this, message); | ||
}, this); | ||
}, this); | ||
} | ||
}, this); | ||
@@ -531,0 +558,0 @@ }; |
{ | ||
"name": "botly", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "Simple Facebook Messenger Bot API", | ||
@@ -42,3 +42,3 @@ "main": "index.js", | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"chai": "^4.1.2", | ||
"grunt": "^1.0.1", | ||
@@ -48,11 +48,11 @@ "grunt-available-tasks": "^0.6.2", | ||
"grunt-env": "^0.4.4", | ||
"grunt-istanbul": "^0.7.0", | ||
"grunt-istanbul": "^0.8.0", | ||
"grunt-mocha-test": "^0.13.2", | ||
"load-grunt-config": "^0.19.2", | ||
"mocha": "^3.1.2", | ||
"mocha": "^4.0.1", | ||
"mockery": "^2.0.0", | ||
"node-mocks-http": "^1.5.2", | ||
"sinon": "^1.17.4", | ||
"sinon": "^4.1.2", | ||
"time-grunt": "^1.3.0" | ||
} | ||
} |
<img src="https://raw.githubusercontent.com/miki2826/botly/master/botly_logo.png" width="250" height="250" /> | ||
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.svg)](http://gruntjs.com/) | ||
[![Build Status](https://travis-ci.org/Askrround/botly.svg)](https://travis-ci.org/Askrround/botly) | ||
[![Build Status](https://travis-ci.org/miki2826/botly.svg)](https://travis-ci.org/miki2826/botly) | ||
[![Test Coverage](https://codeclimate.com/github/Askrround/botly/badges/coverage.svg)](https://codeclimate.com/github/Askrround/botly/coverage) | ||
@@ -26,2 +26,3 @@ [![npm version](https://badge.fury.io/js/botly.svg)](http://badge.fury.io/js/botly) | ||
- [sendList (options[, callback])](#sendlist-options-callback) | ||
- [sendOpenGraph (options[, callback])](#sendopengraph-options-callback) | ||
- [sendAction (options[, callback])](#sendaction-options-callback) | ||
@@ -44,5 +45,7 @@ - [sendReceipt (options[, callback])](#sendreceipt-options-callback) | ||
- [createListElement (options)](#createlistelement-options) | ||
- [createOpenGraphElement (options)](#createopengraphelement-options) | ||
- [createButtonTemplate (text, buttons)](#createbuttontemplate-text-buttons) | ||
- [createGenericTemplate (elements[, aspectRatio])](#creategenerictemplate-elements-aspectratio) | ||
- [createListTemplate (options)](#createlisttemplate-options) | ||
- [createOpenGraphTemplate (elements])](#createopengraphtemplate-elements-aspectratio) | ||
- [handleMessage (req)](#handlemessage-req) | ||
@@ -58,2 +61,3 @@ - [Events](#events) | ||
const express = require("express"); | ||
const bodyParser = require("body-parser"); | ||
const Botly = require("botly"); | ||
@@ -77,2 +81,4 @@ const botly = new Botly({ | ||
const app = express(); | ||
app.use(bodyParser.json()); | ||
app.use(bodyParser.urlencoded({ extended: false })); | ||
app.use("/webhook", botly.router()); | ||
@@ -162,16 +168,28 @@ app.listen(3000); | ||
```javascript | ||
let buttons = []; | ||
buttons.push(botly.createPostbackButton("Continue", "continue")); | ||
let element = botly.createListElement({ | ||
title: "Classic T-Shirt Collection", | ||
image_url: "https://peterssendreceiveapp.ngrok.io/img/collection.png", | ||
subtitle: "See all our colors", | ||
buttons: {title: "Go to Askrround", url: "http://askrround.com"}, | ||
default_action: { | ||
"url": "https://peterssendreceiveapp.ngrok.io/shop_collection", | ||
} | ||
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', | ||
} | ||
}); | ||
botly.sendList({id: userId, elements: element, buttons: buttons}, (err, data) => { | ||
console.log("send generic cb:", err, data); | ||
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); | ||
}); | ||
``` | ||
@@ -178,0 +196,0 @@ |
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
123253
2136
519