Comparing version 0.0.1 to 0.1.3
{ | ||
"name": "botly", | ||
"version": "0.0.1", | ||
"version": "0.1.3", | ||
"description": "Simple Facebook Messenger Bot API", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "grunt default --verbose" | ||
}, | ||
@@ -18,2 +18,3 @@ "repository": { | ||
"bot", | ||
"platform", | ||
"askrround", | ||
@@ -30,3 +31,15 @@ "robot" | ||
}, | ||
"homepage": "https://github.com/Askrround/botly#readme" | ||
"homepage": "https://github.com/Askrround/botly#readme", | ||
"dependencies": { | ||
"body-parser": "^1.15.1", | ||
"express": "^4.13.4", | ||
"request": "^2.72.0" | ||
}, | ||
"devDependencies": { | ||
"grunt": "^1.0.1", | ||
"grunt-available-tasks": "^0.6.2", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"load-grunt-config": "^0.19.2", | ||
"time-grunt": "^1.3.0" | ||
} | ||
} |
250
README.md
botly | ||
--------- | ||
Coming soon. | ||
[![Built with Grunt](https://cdn.gruntjs.com/builtwith.png)](http://gruntjs.com/) | ||
[![Build Status](https://travis-ci.com/Askrround/botly.svg?token=d9DyBzKtc6v8W4BUJ1pp&branch=master)](https://travis-ci.com/Askrround/botly) | ||
[![npm version](https://badge.fury.io/js/botly.svg)](http://badge.fury.io/js/botly) | ||
[![Dependency Status](https://david-dm.org/Askrround/botly.svg?theme=shields.io)](https://david-dm.org/Askrround/botly) | ||
[![devDependency Status](https://david-dm.org/Askrround/botly/dev-status.svg?theme=shields.io)](https://david-dm.org/Askrround/botly#info=devDependencies) | ||
[![npm downloads](https://img.shields.io/npm/dm/botly.svg)](https://img.shields.io/npm/dm/botly.svg) | ||
[![NPM](https://nodei.co/npm/botly.png)](https://nodei.co/npm/botly/) | ||
> Simple Facebook Messenger Platform Bot API | ||
- [Install](#install) | ||
- [Example](#example) | ||
- [API](#api) | ||
- [send (recipientId, message[, callback])](#send-recipientid-message-callback) | ||
- [sendText (recipientId, text[, callback])](#sendtext-recipientid-text-callback) | ||
- [sendAttachment (recipientId, type, payload[, callback])](#sendattachment-recipientid-type-payload-callback) | ||
- [sendImage (recipientId, imageURL[, callback])](#sendimage-recipientid-imageurl-callback) | ||
- [sendButtons (recipientId, text, buttons[, callback])](#sendbuttons-recipientid-text-buttons-callback) | ||
- [sendGeneric (recipientId, elements[, callback])](#sendgeneric-recipientid-elements-callback) | ||
- [sendReceipt (recipientId, payload[, callback])](#sendreceipt-recipientid-payload-callback) | ||
- [setWelcomeScreen (pageId, message[, callback])](#setwelcomescreen-pageid-message-callback) | ||
- [getUserProfile (userId[, callback])](#getuserprofile-userid-callback) | ||
- [createWebURLButton (title, url)](#createweburlbutton-title-url) | ||
- [createPostbackButton (title, payload)](#createpostbackbutton-title-payload) | ||
- [createButtonTemplate (text, buttons)](#createbuttontemplate-text-buttons) | ||
- [createGenericTemplate (elements)](#creategenerictemplate-elements) | ||
- [createElement (title, itemURL, imageURL, subtitle, buttons)](#createelement-title-itemurl-imageurl-subtitle-buttons) | ||
- [handleMessage (req)](#handlemessage-req) | ||
- [Events](#events) | ||
### Install | ||
`npm i botly --save` | ||
### Example | ||
```javascript | ||
const express = require("express"); | ||
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) | ||
}); | ||
botly.on("message", (senderId, message, data) => { | ||
let text = `echo: ${data.text}`; | ||
botly.sendText(senderId, text); | ||
}); | ||
const app = express(); | ||
app.use("/webhook", botly.router()); | ||
app.listen(3000); | ||
``` | ||
You can also clone the repository and run a complete bot example from the `example` folder. | ||
### API | ||
#### send (recipientId, message[, callback]) | ||
```javascript | ||
botly.send(userId, { | ||
text: "Hi There!" | ||
}, function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendText (recipientId, text[, callback]) | ||
```javascript | ||
botly.sendText(userId, "Hi There!", function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendAttachment (recipientId, type, payload[, callback]) | ||
```javascript | ||
botly.sendAttachment(userId, Botly.CONST.ATTACHMENT_TYPE.IMAGE, | ||
{ | ||
url: "http://example.com/image.png" | ||
}, function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendImage (recipientId, imageURL[, callback]) | ||
```javascript | ||
botly.sendImage(userId, "http://example.com/image.png", function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendButtons (recipientId, text, buttons[, callback]) | ||
```javascript | ||
let buttons = []; | ||
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com")); | ||
buttons.push(botly.createPostbackButton("Continue", "continue")); | ||
botly.sendButtons(userId, "What do you want to do next?", buttons | ||
, function (err, data) { | ||
//log it | ||
}); | ||
``` | ||
#### sendGeneric (recipientId, elements[, callback]) | ||
```javascript | ||
let buttons = []; | ||
buttons.push(botly.createWebURLButton("Go to Askrround", "http://askrround.com")); | ||
buttons.push(botly.createPostbackButton("Continue", "continue")); | ||
let element = botly.createElement("What do you want to do next?", | ||
"http://example.com", /*itemURL*/ | ||
"http://example.com/image.png", /*imageURL*/ | ||
"Choose now!", buttons); | ||
botly.sendGeneric(sender, element, function (err, data) { | ||
console.log("send generic cb:", err, data); | ||
}); | ||
``` | ||
#### sendReceipt (recipientId, payload[, callback]) | ||
```javascript | ||
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(sender, payload, function (err, data) { | ||
console.log("send generic cb:", err, data); | ||
}); | ||
``` | ||
#### setWelcomeScreen (pageId, message[, callback]) | ||
```javascript | ||
botly.setWelcomeScreen("myPage", { | ||
text: "Welcome to my page!" | ||
}, function (err, body) { | ||
//log it | ||
}); | ||
``` | ||
#### getUserProfile (userId[, callback]) | ||
```javascript | ||
botly.getUserProfile(senduserIder, function (err, info) { | ||
//cache it | ||
}); | ||
``` | ||
#### createWebURLButton (title, url) | ||
#### createPostbackButton (title, payload) | ||
#### createButtonTemplate (text, buttons) | ||
Where `buttons` can be a single button or an array of buttons. | ||
#### createGenericTemplate (elements) | ||
Where `elements` can be a single element or an array of elements. | ||
#### createElement (title, itemURL, imageURL, subtitle, buttons) | ||
Where `buttons` can be a single button or an array of buttons. | ||
#### handleMessage (req) | ||
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. | ||
### Events | ||
```javascript | ||
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) => { | ||
/** | ||
* where postback is the postback payload | ||
*/ | ||
}); | ||
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 */ | ||
}); | ||
``` |
Sorry, the diff of this file is not supported yet
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Network access
Supply chain riskThis module accesses the network.
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
Empty package
Supply chain riskPackage does not contain any code. It may be removed, is name squatting, or the result of a faulty package publish.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
27067
13
448
1
252
3
5
2
+ Addedbody-parser@^1.15.1
+ Addedexpress@^4.13.4
+ Addedrequest@^2.72.0
+ Addedaccepts@1.3.8(transitive)
+ Addedajv@6.12.6(transitive)
+ Addedarray-flatten@1.1.1(transitive)
+ Addedasn1@0.2.6(transitive)
+ Addedassert-plus@1.0.0(transitive)
+ Addedasynckit@0.4.0(transitive)
+ Addedaws-sign2@0.7.0(transitive)
+ Addedaws4@1.13.2(transitive)
+ Addedbcrypt-pbkdf@1.0.2(transitive)
+ Addedbody-parser@1.20.3(transitive)
+ Addedbytes@3.1.2(transitive)
+ Addedcall-bind@1.0.7(transitive)
+ Addedcaseless@0.12.0(transitive)
+ Addedcombined-stream@1.0.8(transitive)
+ Addedcontent-disposition@0.5.4(transitive)
+ Addedcontent-type@1.0.5(transitive)
+ Addedcookie@0.7.1(transitive)
+ Addedcookie-signature@1.0.6(transitive)
+ Addedcore-util-is@1.0.2(transitive)
+ Addeddashdash@1.14.1(transitive)
+ Addeddebug@2.6.9(transitive)
+ Addeddefine-data-property@1.1.4(transitive)
+ Addeddelayed-stream@1.0.0(transitive)
+ Addeddepd@2.0.0(transitive)
+ Addeddestroy@1.2.0(transitive)
+ Addedecc-jsbn@0.1.2(transitive)
+ Addedee-first@1.1.1(transitive)
+ Addedencodeurl@1.0.22.0.0(transitive)
+ Addedes-define-property@1.0.0(transitive)
+ Addedes-errors@1.3.0(transitive)
+ Addedescape-html@1.0.3(transitive)
+ Addedetag@1.8.1(transitive)
+ Addedexpress@4.21.1(transitive)
+ Addedextend@3.0.2(transitive)
+ Addedextsprintf@1.3.0(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
+ Addedfast-json-stable-stringify@2.1.0(transitive)
+ Addedfinalhandler@1.3.1(transitive)
+ Addedforever-agent@0.6.1(transitive)
+ Addedform-data@2.3.3(transitive)
+ Addedforwarded@0.2.0(transitive)
+ Addedfresh@0.5.2(transitive)
+ Addedfunction-bind@1.1.2(transitive)
+ Addedget-intrinsic@1.2.4(transitive)
+ Addedgetpass@0.1.7(transitive)
+ Addedgopd@1.0.1(transitive)
+ Addedhar-schema@2.0.0(transitive)
+ Addedhar-validator@5.1.5(transitive)
+ Addedhas-property-descriptors@1.0.2(transitive)
+ Addedhas-proto@1.0.3(transitive)
+ Addedhas-symbols@1.0.3(transitive)
+ Addedhasown@2.0.2(transitive)
+ Addedhttp-errors@2.0.0(transitive)
+ Addedhttp-signature@1.2.0(transitive)
+ Addediconv-lite@0.4.24(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedipaddr.js@1.9.1(transitive)
+ Addedis-typedarray@1.0.0(transitive)
+ Addedisstream@0.1.2(transitive)
+ Addedjsbn@0.1.1(transitive)
+ Addedjson-schema@0.4.0(transitive)
+ Addedjson-schema-traverse@0.4.1(transitive)
+ Addedjson-stringify-safe@5.0.1(transitive)
+ Addedjsprim@1.4.2(transitive)
+ Addedmedia-typer@0.3.0(transitive)
+ Addedmerge-descriptors@1.0.3(transitive)
+ Addedmethods@1.1.2(transitive)
+ Addedmime@1.6.0(transitive)
+ Addedmime-db@1.52.0(transitive)
+ Addedmime-types@2.1.35(transitive)
+ Addedms@2.0.02.1.3(transitive)
+ Addednegotiator@0.6.3(transitive)
+ Addedoauth-sign@0.9.0(transitive)
+ Addedobject-inspect@1.13.3(transitive)
+ Addedon-finished@2.4.1(transitive)
+ Addedparseurl@1.3.3(transitive)
+ Addedpath-to-regexp@0.1.10(transitive)
+ Addedperformance-now@2.1.0(transitive)
+ Addedproxy-addr@2.0.7(transitive)
+ Addedpsl@1.13.0(transitive)
+ Addedpunycode@2.3.1(transitive)
+ Addedqs@6.13.06.5.3(transitive)
+ Addedrange-parser@1.2.1(transitive)
+ Addedraw-body@2.5.2(transitive)
+ Addedrequest@2.88.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsafer-buffer@2.1.2(transitive)
+ Addedsend@0.19.0(transitive)
+ Addedserve-static@1.16.2(transitive)
+ Addedset-function-length@1.2.2(transitive)
+ Addedsetprototypeof@1.2.0(transitive)
+ Addedside-channel@1.0.6(transitive)
+ Addedsshpk@1.18.0(transitive)
+ Addedstatuses@2.0.1(transitive)
+ Addedtoidentifier@1.0.1(transitive)
+ Addedtough-cookie@2.5.0(transitive)
+ Addedtunnel-agent@0.6.0(transitive)
+ Addedtweetnacl@0.14.5(transitive)
+ Addedtype-is@1.6.18(transitive)
+ Addedunpipe@1.0.0(transitive)
+ Addeduri-js@4.4.1(transitive)
+ Addedutils-merge@1.0.1(transitive)
+ Addeduuid@3.4.0(transitive)
+ Addedvary@1.1.2(transitive)
+ Addedverror@1.10.0(transitive)