-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbot.js
More file actions
46 lines (38 loc) · 1.32 KB
/
bot.js
File metadata and controls
46 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
var facebook = require('../../../yowl-platform-facebook');
var memory = require('yowl-session-memory');
var yowl = require('../../../yowl');
var bot = yowl();
bot.name = 'Echo Bot';
/**
* Facebook Platform
*
* You need to setup an app/page on Facebook for the facebook platform. Visit
* https://developers.facebook.com/docs/messenger-platform/guides/quick-start
* for more info.
*
* Facebook requires that the server hosting a bot be exposed to the internet.
* If you are running this example locally, you will want to expose your local
* server to the internet via tunneling. An easy way to do this is with
* ngrok. (https://ngrok.com/)
*/
bot.extend(facebook({ verificationToken: "your-verification-token",
accessToken: "your-access-token",
webhook: "/facebook/webhook/" }));
bot.use(memory);
bot.use(function(context, event) {
return !context.session.profile;
}, function(context, event, next) {
context.profile(function(err, profile) {
context.session.profile = profile;
next();
});
});
bot.use(function(context, event, callback) {
context.session.echo = event.message;
setTimeout(function() {
console.log(context.session);
event.send("{profile.first_name} says '{echo}'", callback);
}, 500);
});
bot.run(5000);
console.log("Running on port 5000...");