-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcage.js
105 lines (73 loc) · 2.76 KB
/
cage.js
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
______ ______ ______ __ __ __ ______
/\ == \ /\ __ \ /\__ _\ /\ \/ / /\ \ /\__ _\
\ \ __< \ \ \/\ \ \/_/\ \/ \ \ _"-. \ \ \ \/_/\ \/
\ \_____\ \ \_____\ \ \_\ \ \_\ \_\ \ \_\ \ \_\
\/_____/ \/_____/ \/_/ \/_/\/_/ \/_/ \/_/
This is a sample Slack bot built with Botkit.
This bot demonstrates a multi-stage conversation
# RUN THE BOT:
Get a Bot token from Slack:
-> http://my.slack.com/services/new/bot
Run your bot from the command line:
token=xoxb-111716916304-QpIuIXUcTIm8I4lqG3kSzGz2 node cage.js
# USE THE BOT:
Find your bot inside Slack
Say: "pizzatime"
The bot will reply "What flavor of pizza do you want?"
Say what flavor you want.
The bot will reply "Awesome" "What size do you want?"
Say what size you want.
The bot will reply "Ok." "So where do you want it delivered?"
Say where you want it delivered.
The bot will reply "Ok! Goodbye."
...and will refrain from billing your card because this is just a demo :P
# EXTEND THE BOT:
Botkit has many features for building cool and useful bots!
Read all about it here:
-> http://howdy.ai/botkit
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
var Botkit = require('./lib/Botkit.js');
if (!process.env.token) {
console.log('Error: Specify token in environment');
process.exit(1);
}
var controller = Botkit.slackbot({
debug: false
});
controller.spawn({
token: process.env.token
}).startRTM(function(err) {
if (err) {
throw new Error(err);
}
});
controller.on('direct_mention',function(bot,message) {
bot.reply(message,':cage: LOL :cage:');
});
controller.on('direct_message',function(bot,message) {
bot.reply(message,':doge: WOW :doge: :doge: SO SCARE :doge: :doge:');
});
controller.hears(['cage', 'lol', 'tsais bien', 'ncage'],['ambient'],function(bot,message) {
bot.startConversation(message, askAgent);
});
askAgent = function(response, convo) {
convo.ask(":cage: LOL :cage: :cage: LOL :cage: :cage: LOL :cage: :cage: LOL :cage: :cage: LOL :cage: :cage: LOL :cage:", function(response, convo) {
convo.say(":cage:");
askSize(response, convo);
convo.next();
});
}
askSize = function(response, convo) {
convo.ask(":doge: WOW :doge: :doge: SO SCARE :doge: :doge:", function(response, convo) {
convo.say(":doge: WOW :doge: :doge: SO SCARE :doge: :doge: :doge: WOW :doge: :doge: SO SCARE :doge: :doge:")
askWhereDeliver(response, convo);
convo.next();
});
}
askWhereDeliver = function(response, convo) {
convo.ask(":cage:", function(response, convo) {
convo.say(":cage:b");
convo.next();
});
}