Skip to content

Commit

Permalink
fixes from new skills test run on glitch
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectIsAdvantag committed May 17, 2018
1 parent 632bde7 commit c9b8978
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 62 deletions.
4 changes: 3 additions & 1 deletion skills/about.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ module.exports = function (controller, bot) {
"support-contact": "Stève Sfartz <mailto:[email protected]>",

// Messaging platform
"plaform": bot.type,
// [WORKAROUND] overriding Botkit's integrated support temporarly as 'ciscospark' is still returned
//"plaform": bot.type,
"plaform": "webex",

// the precise bot identity is loaded asynchronously, from a GET /people/me request
"identity": "unknown",
Expand Down
7 changes: 3 additions & 4 deletions skills/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ module.exports = function (controller) {
controller.hears([/^help$/], 'direct_message,direct_mention', function (bot, message) {
var text = "Here are my skills:";
text += "\n- " + bot.appendMention(message, "color") + ": ask to pick a random color";
text += "\n- " + bot.enrichCommand(message, "loop") + ": example of a menu that loops until explicitly stopped";
text += "\n- " + bot.enrichCommand(message, "menu") + ": implement a menu via a conversation";
text += "\n- " + bot.enrichCommand(message, "quiz") + ": multi-threaded conversation with timeout";
text += "\n- " + bot.appendMention(message, "loop") + ": example of a menu that loops until explicitly stopped";
text += "\n- " + bot.appendMention(message, "menu") + ": implement a menu via a conversation";
text += "\n- " + bot.appendMention(message, "quiz") + ": multi-threaded conversation with timeout";
text += "\n- " + bot.appendMention(message, "restricted") + ": let a user pick a color among a set of options";
text += "\n- " + bot.appendMention(message, "storage") + ": store picked color as a user preference";
text += "\n- " + bot.enrichCommand(message, "timeout") + ": experience Botkit timeout";
text += "\n- " + bot.appendMention(message, "threads") + ": branch to another thread";
text += "\n- " + bot.appendMention(message, "variables") + ": enriched user-context among threads";
text += "\n\nI also understand:";
Expand Down
10 changes: 7 additions & 3 deletions skills/restricted.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ module.exports = function (controller) {
{
default: true,
callback: function (response, convo) {
convo.say("Sorry, I don't know this color. Try another one...");
convo.repeat();
convo.next();
convo.gotoThread('bad_response');
}
}
]);

// Bad response
convo.addMessage({
text: "Sorry, I don't know this color.<br/>_Tip: try blue, green, pink, red or yellow!_",
action: 'default',
}, 'bad_response');
});
});
};
33 changes: 16 additions & 17 deletions skills/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ module.exports = function (controller) {
return;
}

// Ask for favorite color
askForFavoriteColor(controller, bot, message, userId);
// Ask for prefrence
askForUserPreference(controller, bot, message, userId);
});
});
}
Expand All @@ -33,19 +33,14 @@ function showUserPreference(controller, bot, message, userId, color) {

convo.sayFirst(`Hey, I know you <@personId:${userId}>!<br/> '${color}' is your favorite color.`);

// Remove user preferences if supported
if (!controller.storage.users.remove) {
convo.say("_To erase your preference, simply restart the bot as you're using in-memory transient storage._");
convo.next();
return;
}

convo.ask("Should I erase your preference? yes/(no)", [
convo.ask("Should I erase your preference? (yes/no)", [
{
pattern: "^yes|ya|da|si|oui$",
callback: function (response, convo) {

controller.storage.users.remove(userId, function (err) {
// [WORKAROUND] use storage.users.delete if in-memory storage and storage.users.remove if redis storage
// controller.storage.users.remove(userId, function (err) {
controller.storage.users.delete(userId, function (err) {
if (err) {
convo.say(message, 'sorry, could not access storage, err: ' + err.message);
convo.repeat();
Expand All @@ -61,15 +56,15 @@ function showUserPreference(controller, bot, message, userId, color) {
{
default: true,
callback: function (response, convo) {
convo.say("Got it, leaving your color preference as is.");
convo.say("Got it, leaving your preference as is.");
convo.next();
}
}
]);
});
}

function askForFavoriteColor(controller, bot, message, userId) {
function askForUserPreference(controller, bot, message, userId) {
bot.startConversation(message, function (err, convo) {

convo.ask("What is your favorite color?", [
Expand All @@ -87,21 +82,25 @@ function askForFavoriteColor(controller, bot, message, userId) {
return;
}

convo.transitionTo("success", `_stored user preference_`);
convo.transitionTo("success", "_successfully stored user preference_");
});

},
},
{
default: true,
callback: function (response, convo) {
convo.say("Sorry, I don't know this color. Try another one...");
convo.repeat();
convo.next();
convo.gotoThread('bad_response');
}
}
], { key: "answer" });

// Bad response
convo.addMessage({
text: "Sorry, I don't know this color.<br/>_Tip: try blue, green, pink, red or yellow!_",
action: 'default',
}, 'bad_response');

// Success thread
convo.addMessage(
"Cool, I love '{{responses.answer}}' too",
Expand Down
37 changes: 0 additions & 37 deletions skills/timeout.js

This file was deleted.

0 comments on commit c9b8978

Please sign in to comment.