Skip to content

Commit 632bde7

Browse files
updated skills from latest [email protected] bot
1 parent 2932b45 commit 632bde7

File tree

12 files changed

+330
-16
lines changed

12 files changed

+330
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- introducing ACCESS_TOKEN env variable
55
- backward compatibility for SPARK_TOKEN env variable
66
- documentation updates (removing spark mentions)
7+
- added popular skills from [email protected]
78

89
### v0.6 (2017-11-17): legacy version for Cisco Spark
910
- configuration through environment variables or hard-coded values in the .env file

skills/color.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// Simplest use of Botkit's conversation system
3+
//
14
module.exports = function (controller) {
25

36
controller.hears([/^color$/], 'direct_message,direct_mention', function (bot, message) {

skills/help.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ module.exports = function (controller) {
66
controller.hears([/^help$/], 'direct_message,direct_mention', function (bot, message) {
77
var text = "Here are my skills:";
88
text += "\n- " + bot.appendMention(message, "color") + ": ask to pick a random color";
9+
text += "\n- " + bot.enrichCommand(message, "loop") + ": example of a menu that loops until explicitly stopped";
10+
text += "\n- " + bot.enrichCommand(message, "menu") + ": implement a menu via a conversation";
11+
text += "\n- " + bot.enrichCommand(message, "quiz") + ": multi-threaded conversation with timeout";
912
text += "\n- " + bot.appendMention(message, "restricted") + ": let a user pick a color among a set of options";
1013
text += "\n- " + bot.appendMention(message, "storage") + ": store picked color as a user preference";
14+
text += "\n- " + bot.enrichCommand(message, "timeout") + ": experience Botkit timeout";
1115
text += "\n- " + bot.appendMention(message, "threads") + ": branch to another thread";
1216
text += "\n- " + bot.appendMention(message, "variables") + ": enriched user-context among threads";
1317
text += "\n\nI also understand:";

skills/loop.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//
2+
// Example of a conversation with a menu that loops until explicitly stopped
3+
//
4+
module.exports = function (controller) {
5+
6+
controller.hears([/^loop$/], 'direct_message,direct_mention', function (bot, message) {
7+
8+
bot.startConversation(message, function (err, convo) {
9+
10+
var question = "Here are a few proposed DevNet activities:";
11+
question += "<br/> `1)` join a Community Of Interest (**communities**)";
12+
question += "<br/> `2)` take a Learning Lab (**labs**)";
13+
question += "<br/> `3)` check Upcoming Events (**events**)";
14+
question += "\n\nWhat do you want to check?<br/>_(type a number, a **bold keyword** or `stop`)_";
15+
convo.ask(question, [
16+
{
17+
pattern: "1|community|communities",
18+
callback: function (response, convo) {
19+
convo.gotoThread('menu_1');
20+
},
21+
}
22+
, {
23+
pattern: "2|lab|track|learn",
24+
callback: function (response, convo) {
25+
convo.gotoThread('menu_2');
26+
},
27+
}
28+
, {
29+
pattern: "3|event|express",
30+
callback: function (response, convo) {
31+
convo.gotoThread('menu_3');
32+
},
33+
}
34+
, {
35+
pattern: "cancel|stop",
36+
callback: function (response, convo) {
37+
convo.gotoThread('action_cancel');
38+
},
39+
}
40+
, {
41+
default: true,
42+
callback: function (response, convo) {
43+
convo.gotoThread('bad_response');
44+
}
45+
}
46+
]);
47+
48+
// Menu option 1)
49+
convo.addMessage({
50+
text: "Excellent choice: now [discover the DevNet communities](https://developer.cisco.com/site/coi/) online, and pick your favorite...",
51+
action: 'default'
52+
}, 'menu_1');
53+
54+
// Menu option 2)
55+
convo.addMessage({
56+
text: "Learnings **labs** are step-by-step tutorials. They are grouped into **tracks** to help you on your rampup journey. Just browse through [the learnings tracks](https://learninglabs.cisco.com/login) and pick the labs that suits your learning appetite!",
57+
action: 'default'
58+
}, 'menu_2');
59+
60+
// Menu option 3)
61+
convo.addMessage({
62+
text: "Nothing's like meeting in person at a conference, training or a hackathon. Check the list of [DevNet events](https://developer.cisco.com/site/devnet/events-contests/events/) or ask the bot: invite `[email protected]` to chat in a Webex Teams space.",
63+
action: 'default'
64+
}, 'menu_3');
65+
66+
// Cancel
67+
convo.addMessage({
68+
text: "Got it, cancelling...",
69+
action: 'stop', // this marks the converation as unsuccessful
70+
}, 'action_cancel');
71+
72+
// Bad response
73+
convo.addMessage({
74+
text: "Sorry, I did not understand.",
75+
action: 'default',
76+
}, 'bad_response');
77+
78+
});
79+
});
80+
};

skills/menu.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
//
2+
// Example of a conversation with an hard-coded menu
3+
//
4+
// say: Hello, we have lots of activities at DevNet
5+
// 1. join a community of interest (communities)
6+
// 2. take a learning lab (labs)
7+
// 3. check upcoming events (events)
8+
//
9+
// ask: what do you want to do ? (type a number, the word in bold, or cancel)
10+
//
11+
module.exports = function (controller) {
12+
13+
controller.hears([/^menu$/], 'direct_message,direct_mention', function (bot, message) {
14+
15+
bot.startConversation(message, function (err, convo) {
16+
17+
var question = "Here are a few proposed DevNet activities:";
18+
question += "<br/> `1)` join a Community Of Interest (**communities**)";
19+
question += "<br/> `2)` take a Learning Lab (**labs**)";
20+
question += "<br/> `3)` check Upcoming Events (**events**)";
21+
question += "\n\nWhat do you want to do ?<br/>_(type a number, a **bold keyword** or `cancel`)_";
22+
convo.ask(question, [
23+
{
24+
pattern: "1|community|communities",
25+
callback: function (response, convo) {
26+
convo.say("Excellent choice: now [check the DevNet communities](https://developer.cisco.com/site/coi/) online, and pick your favorite...");
27+
convo.next();
28+
},
29+
}
30+
, {
31+
pattern: "2|lab|track|learn",
32+
callback: function (response, convo) {
33+
convo.say("Learnings **labs** are step-by-step tutorials. They are grouped into **tracks** to help you on your rampup journey. Just browse through [the learnings tracks](https://learninglabs.cisco.com/login) and pick the labs that suits your learning appetite!");
34+
convo.next();
35+
},
36+
}
37+
, {
38+
pattern: "3|event|express",
39+
callback: function (response, convo) {
40+
convo.say("Nothing's like meeting in person at a conference, training or a hackathon. Check the list of [DevNet events](https://developer.cisco.com/site/devnet/events-contests/events/) or ask the bot: invite `[email protected]` to chat in a Webex Teams space.");
41+
convo.next();
42+
},
43+
}
44+
, {
45+
pattern: "cancel|stop",
46+
callback: function (response, convo) {
47+
convo.say("Got it, cancelling...");
48+
convo.next();
49+
},
50+
}
51+
, {
52+
default: true,
53+
callback: function (response, convo) {
54+
convo.gotoThread('bad_response');
55+
}
56+
}
57+
]);
58+
59+
// Bad response
60+
convo.addMessage({
61+
text: "Sorry, I did not understand.",
62+
action: 'default',
63+
}, 'bad_response');
64+
});
65+
});
66+
};

skills/quiz.js

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
//
2+
// Example of a muti-threaded conversation with timeout
3+
//
4+
module.exports = function (controller) {
5+
6+
controller.hears([/^quiz$/], 'direct_message,direct_mention', function (bot, message) {
7+
8+
bot.startConversation(message, function (err, convo) {
9+
10+
// Default thread
11+
convo.ask("Ready for a challenge (yes/no/cancel)", [
12+
{
13+
pattern: "yes|yeh|sure|oui|si",
14+
callback: function (response, convo) {
15+
16+
// Apply elaps time (in milliseconds) to next askQuestion
17+
convo.setTimeout(5000);
18+
convo.onTimeout(function (convo) {
19+
convo.gotoThread("missed");
20+
});
21+
22+
convo.gotoThread('quiz');
23+
},
24+
}
25+
, {
26+
pattern: "no|neh|non|na|birk",
27+
callback: function (response, convo) {
28+
convo.say("Too bad, looking forward to play with you later...");
29+
convo.next();
30+
},
31+
}
32+
, {
33+
pattern: "cancel|stop|exit",
34+
callback: function (response, convo) {
35+
convo.gotoThread('cancel');
36+
},
37+
}
38+
, {
39+
default: true,
40+
callback: function (response, convo) {
41+
convo.say("Sorry, I did not understand.");
42+
convo.repeat();
43+
convo.next();
44+
}
45+
}
46+
]);
47+
48+
// Cancel thread
49+
convo.addMessage({
50+
text: "Got it, cancelling...",
51+
action: 'stop', // this marks the converation as unsuccessful
52+
}, 'cancel');
53+
54+
// Quiz thread
55+
convo.addMessage("Let's start", "quiz");
56+
var challenge = pickChallenge();
57+
convo.addQuestion("Question: " + challenge.question, [
58+
{
59+
pattern: "^"+ challenge.answer + "$",
60+
callback: function (response, convo) {
61+
convo.gotoThread('success');
62+
},
63+
}
64+
, {
65+
pattern: "cancel|stop|exit",
66+
callback: function (response, convo) {
67+
convo.gotoThread('cancel');
68+
},
69+
}
70+
, {
71+
default: true,
72+
callback: function (response, convo) {
73+
convo.say("Sorry, wrong answer. Try again!");
74+
convo.repeat();
75+
convo.next();
76+
}
77+
}
78+
], {}, 'quiz');
79+
80+
// Success thread
81+
convo.addMessage("Congrats, you did it!", "success");
82+
83+
// Missed thread
84+
convo.addMessage("Time elapsed! you missed it, sorry.", "missed");
85+
});
86+
});
87+
};
88+
89+
90+
function pickChallenge() {
91+
var a = Math.round(Math.random()*5) + 4;
92+
var b = Math.round(Math.random()*5) + 4;
93+
return {
94+
question : "" + a + " x " + b + " =",
95+
answer : "" + (a * b)
96+
}
97+
}

skills/restricted.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// Forces the user to pick among a predefined list of options
3+
//
14
module.exports = function (controller) {
25

36
controller.hears([/^restricted$/], "direct_message,direct_mention", function (bot, message) {

skills/storage.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Stores a user choice in botkit 'users' storage, so that the value can be retreived later
2+
// Stores a user choice in Botkit 'users' storage, so that the value can be retreived later
33
//
44
module.exports = function (controller) {
55

skills/threads.js

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,51 @@
1+
//
2+
// Illustrates a muti-threaded conversation
3+
//
4+
// Q: "What about coffee (yes / no / cancel)"
5+
// A: no
6+
// Q: "What would you like to drink?"
7+
// A: Coke
8+
//
19
module.exports = function (controller) {
210

3-
controller.hears([/^threads$/], "direct_message,direct_mention", function (bot, message) {
11+
controller.hears([/^threads$/], 'direct_message,direct_mention', function (bot, message) {
412

513
bot.startConversation(message, function (err, convo) {
14+
convo.addQuestion('What would you like to drink?', function (response, convo) {
15+
convo.say('I love ' + response.text + ' too');
16+
convo.next();
17+
}, {}, 'ask-drink');
618

7-
convo.ask("What is your favorite color?", [
19+
convo.ask("What about coffee (yes/**no**/cancel)", [
820
{
9-
pattern: "^blue|green|pink|red|yellow$",
21+
pattern: "yes|yeh|sure|oui|si",
1022
callback: function (response, convo) {
11-
convo.gotoThread("success");
23+
convo.say("Go, get some !");
24+
convo.next();
1225
},
13-
},
14-
{
26+
}
27+
, {
28+
pattern: "no|neh|non|na|birk",
29+
callback: function (response, convo) {
30+
convo.gotoThread('ask-drink');
31+
},
32+
}
33+
, {
34+
pattern: "cancel|stop|exit",
35+
callback: function (response, convo) {
36+
convo.say("Got it, cancelling...");
37+
convo.next();
38+
},
39+
}
40+
, {
1541
default: true,
1642
callback: function (response, convo) {
17-
convo.say("Sorry, I don't know this color. Try another one...");
43+
convo.say("Sorry, I did not understand.");
1844
convo.repeat();
1945
convo.next();
2046
}
2147
}
22-
], { key: "answer" });
23-
24-
// Success thread
25-
convo.addMessage(
26-
"Cool, I love '{{responses.answer}}' too",
27-
"success");
48+
]);
2849
});
2950
});
3051
};

skills/timeout.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Show Botkit timeouts behave in a conversation
3+
// https://github.com/howdyai/botkit/blob/master/docs/readme.md#handling-conversation-timeouts
4+
//
5+
module.exports = function (controller) {
6+
7+
controller.hears([/^timeout$/], 'direct_message,direct_mention', function (bot, message) {
8+
9+
bot.startConversation(message, function (err, convo) {
10+
convo.sayFirst("Then you're this kind of people that do not answer? let's check that...");
11+
12+
convo.ask("What's your favorite color ?", function(response, convo) {
13+
convo.say('Cool, I like ' + response.text + ' too!');
14+
convo.next();
15+
});
16+
17+
// If no answer after a minute, we want to give a few chances, then cancel the flow
18+
convo.setVar('chances', 1);
19+
convo.setTimeout(5000); // in milliseconds
20+
convo.onTimeout(function (convo) {
21+
var chances = convo.vars["chances"];
22+
if (chances < 3) {
23+
chances++;
24+
convo.setVar('chances', chances);
25+
26+
convo.say('Did not hear from you :-(, giving you another chance ');
27+
convo.repeat();
28+
convo.next();
29+
}
30+
else {
31+
convo.say("Looks like you're gone, cancelling...");
32+
convo.next();
33+
}
34+
});
35+
});
36+
});
37+
};

skills/variables.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//
2+
// Threaded conversation where variables are set to store user choices
3+
//
14
module.exports = function (controller) {
25

36
controller.hears([/^variables$/], "direct_message,direct_mention", function (bot, message) {

0 commit comments

Comments
 (0)