botframework
Advanced tools
Comparing version 0.7.1 to 0.8.0
@@ -26,3 +26,3 @@ "use strict"; | ||
method: 'GET', | ||
path: '/facebook/receive', | ||
path: this.settings.fb.callback_path, | ||
handler: this.verifyRequest.bind(this) | ||
@@ -32,3 +32,3 @@ }); | ||
method: 'POST', | ||
path: '/facebook/receive', | ||
path: this.settings.fb.callback_path, | ||
handler: this.receiveMessage.bind(this) | ||
@@ -35,0 +35,0 @@ }); |
@@ -77,2 +77,3 @@ export interface IBotUser { | ||
port: number; | ||
callback_path: string; | ||
access_token: string; | ||
@@ -79,0 +80,0 @@ verify_token: string; |
@@ -6,3 +6,6 @@ | ||
fb: { | ||
page_id: process.env.FB_PAGE_ID, verify_id: process.env.FB_VERIFY_ID, port: process.env.FB_PORT, | ||
page_id: process.env.FB_PAGE_ID, | ||
verify_id: process.env.FB_VERIFY_ID, | ||
port: process.env.FB_PORT, | ||
callback_path: process.env.FB_CALLBACK_PATH, | ||
access_token: process.env.FB_ACCESS_TOKEN | ||
@@ -9,0 +12,0 @@ } |
{ | ||
"name": "botframework", | ||
"version": "0.7.1", | ||
"version": "0.8.0", | ||
"description": "Framework for messaging bots", | ||
@@ -43,2 +43,2 @@ "main": "./dist/es5/src/bot.js", | ||
} | ||
} | ||
} |
@@ -15,2 +15,18 @@ [![Build Status](https://travis-ci.org/amitevski/botframework.svg?branch=master)](https://travis-ci.org/amitevski/botframework) | ||
### Plan where you will deploy your bot | ||
In order to setup the Facebook Bot in next step you need to define a | ||
* callback url e.g. https://www.myhost.com/facebook/receive | ||
* verify id e.g. "my-secure-id" | ||
For testing I can recommend [http://localtunnel.me/](http://localtunnel.me/) | ||
### Setup your facebook bot | ||
follow https://developers.facebook.com/docs/messenger-platform/quickstart to set up your bot. | ||
Note the access_token. We will need it | ||
### general | ||
### JavaScript | ||
@@ -22,4 +38,7 @@ | ||
fb: { | ||
page_id: process.env.FB_PAGE_ID, verify_id: process.env.FB_VERIFY_ID, port: process.env.FB_PORT, | ||
access_token: process.env.FB_ACCESS_TOKEN | ||
page_id: <your facebook page id>, | ||
verify_id: <your verify id>, | ||
port: 3000, | ||
callback_path: '/facebook/receive', | ||
access_token: <access_token from facebook> | ||
} | ||
@@ -36,6 +55,7 @@ }, new ctrl()); | ||
}; | ||
// imageMessage?(imageMessage: IImageMessage): void; | ||
// linkMessage?(linkMessage: ILinkMessage): void; | ||
// locationMessage?(locationMessage: ILocationMessage): void; | ||
// catchAll?(user: IBotUser, msg: Object): void; | ||
// newUser?(msg: INewUserMessage, reply: IBotReply): void; | ||
// imageMessage?(imageMessage: IImageMessage, reply: IBotReply): void; | ||
// linkMessage?(linkMessage: ILinkMessage, reply: IBotReply): void; | ||
// locationMessage?(locationMessage: ILocationMessage, reply: IBotReply): void; | ||
// catchAll?(user: IBotUser, msg: Object, reply: IBotReply): void; | ||
} | ||
@@ -52,4 +72,7 @@ ``` | ||
fb: { | ||
page_id: process.env.FB_PAGE_ID, verify_token: process.env.FB_VERIFY_ID, port: process.env.FB_PORT, | ||
access_token: process.env.FB_ACCESS_TOKEN | ||
page_id: <your facebook page id>, | ||
verify_id: <your verify id>, | ||
port: 3000, | ||
callback_path: '/facebook/receive', | ||
access_token: <access_token from facebook> | ||
} | ||
@@ -62,4 +85,58 @@ } ; | ||
} | ||
// newUser?(msg: INewUserMessage, reply: IBotReply): void; | ||
// imageMessage?(imageMessage: IImageMessage, reply: IBotReply): void; | ||
// linkMessage?(linkMessage: ILinkMessage, reply: IBotReply): void; | ||
// locationMessage?(locationMessage: ILocationMessage, reply: IBotReply): void; | ||
// catchAll?(user: IBotUser, msg: Object, reply: IBotReply): void; | ||
} | ||
var bot = new Bot(botSettings, new BotController()); | ||
``` | ||
### Handling other message types like Location, Image, Authentication | ||
Botframework detects the facebook message type and calls the according handler callback function if its defined. | ||
You can implement more handlers. Following callbacks are currently supported: | ||
```javascript | ||
export interface IBotController { | ||
newUser?(msg: INewUserMessage, reply: IBotReply): void; // handles facebook Authentication callback | ||
textMessage?(textMessage: ITextMessage, reply: IBotReply): void; // handles text only messages | ||
imageMessage?(imageMessage: IImageMessage, reply: IBotReply): void; // handles received images | ||
linkMessage?(linkMessage: ILinkMessage, reply: IBotReply): void; // handles received links from mobile phone sendTo Plugin | ||
locationMessage?(locationMessage: ILocationMessage, reply: IBotReply): void; // handles received locations | ||
catchAll?(user: IBotUser, msg: Object, reply: IBotReply): void; | ||
} | ||
``` | ||
### Replying | ||
The Reply interfaces currently supports replying with a simple text message and a list message. | ||
```javascript | ||
// reply with list | ||
let botItems: Array<IBotReplyListItem> = response.data.map( (obj: Object) => { | ||
let buttons = [ | ||
{ | ||
title: 'Open Link', | ||
url: obj.href, | ||
type: 'web_url' | ||
} | ||
]; | ||
return { | ||
title: obj.name, | ||
image_url: obj.img_url | ||
subtitle: obj.desc || '', | ||
buttons | ||
} | ||
}); | ||
reply.list(botItems); | ||
////// | ||
//reply with text | ||
reply.text('Hi there'); | ||
``` |
@@ -34,3 +34,3 @@ import {IBotSettings} from '../interfaces'; | ||
method: 'GET', | ||
path: '/facebook/receive', | ||
path: this.settings.fb.callback_path, | ||
handler: this.verifyRequest.bind(this) | ||
@@ -40,3 +40,3 @@ }); | ||
method: 'POST', | ||
path: '/facebook/receive', | ||
path: this.settings.fb.callback_path, | ||
handler: this.receiveMessage.bind(this) | ||
@@ -43,0 +43,0 @@ }); |
@@ -100,2 +100,3 @@ | ||
port: number; | ||
callback_path: string; | ||
access_token: string; | ||
@@ -102,0 +103,0 @@ verify_token: string; |
Sorry, the diff of this file is not supported yet
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
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
773593
64
15539
137
5