diff --git a/skills/about.js b/skills/about.js index 2dbdb78f..5b0e8066 100644 --- a/skills/about.js +++ b/skills/about.js @@ -21,7 +21,9 @@ module.exports = function (controller, bot) { "support-contact": "Stève Sfartz ", // 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", diff --git a/skills/help.js b/skills/help.js index dc48dc06..7bae475c 100644 --- a/skills/help.js +++ b/skills/help.js @@ -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:"; diff --git a/skills/restricted.js b/skills/restricted.js index 9dc895ab..591255d7 100644 --- a/skills/restricted.js +++ b/skills/restricted.js @@ -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.
_Tip: try blue, green, pink, red or yellow!_", + action: 'default', + }, 'bad_response'); }); }); }; diff --git a/skills/storage.js b/skills/storage.js index 62881295..229636df 100644 --- a/skills/storage.js +++ b/skills/storage.js @@ -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); }); }); } @@ -33,19 +33,14 @@ function showUserPreference(controller, bot, message, userId, color) { convo.sayFirst(`Hey, I know you <@personId:${userId}>!
'${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(); @@ -61,7 +56,7 @@ 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(); } } @@ -69,7 +64,7 @@ function showUserPreference(controller, bot, message, userId, color) { }); } -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?", [ @@ -87,7 +82,7 @@ function askForFavoriteColor(controller, bot, message, userId) { return; } - convo.transitionTo("success", `_stored user preference_`); + convo.transitionTo("success", "_successfully stored user preference_"); }); }, @@ -95,13 +90,17 @@ function askForFavoriteColor(controller, bot, message, userId) { { 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.
_Tip: try blue, green, pink, red or yellow!_", + action: 'default', + }, 'bad_response'); + // Success thread convo.addMessage( "Cool, I love '{{responses.answer}}' too", diff --git a/skills/timeout.js b/skills/timeout.js deleted file mode 100644 index 15c2b1ba..00000000 --- a/skills/timeout.js +++ /dev/null @@ -1,37 +0,0 @@ -// -// Show Botkit timeouts behave in a conversation -// https://github.com/howdyai/botkit/blob/master/docs/readme.md#handling-conversation-timeouts -// -module.exports = function (controller) { - - controller.hears([/^timeout$/], 'direct_message,direct_mention', function (bot, message) { - - bot.startConversation(message, function (err, convo) { - convo.sayFirst("Then you're this kind of people that do not answer? let's check that..."); - - convo.ask("What's your favorite color ?", function(response, convo) { - convo.say('Cool, I like ' + response.text + ' too!'); - convo.next(); - }); - - // If no answer after a minute, we want to give a few chances, then cancel the flow - convo.setVar('chances', 1); - convo.setTimeout(5000); // in milliseconds - convo.onTimeout(function (convo) { - var chances = convo.vars["chances"]; - if (chances < 3) { - chances++; - convo.setVar('chances', chances); - - convo.say('Did not hear from you :-(, giving you another chance '); - convo.repeat(); - convo.next(); - } - else { - convo.say("Looks like you're gone, cancelling..."); - convo.next(); - } - }); - }); - }); -};