Skip to content

Commit

Permalink
renamed enrichCommand to appendMention, fixed storage skill
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectIsAdvantag committed Sep 19, 2017
1 parent 3e921cc commit b5fe1c3
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ This template regroups a set of best practices:

- metadata: expose extra info via command and on a public address so that Spark users can inquire on Bot Author / Legal mentions / Healthcheck endpoint...

- mentions: the enrichCommand utility helps you add mentions in Group spaces.
- mentions: the appendMention utility function helps Spark users remind to mention the bot in Group spaces.

- popular cloud providers: the bot self-configures when run on Glitch and Heroku (if )

Expand Down
2 changes: 1 addition & 1 deletion bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ require("fs").readdirSync(normalizedPath).forEach(function (file) {
//

// Utility to add mentions if Bot is in a 'Group' space
bot.enrichCommand = function (message, command) {
bot.appendMention = function (message, command) {

// if the message is a raw message (from a post message callback such as bot.say())
if (message.roomType && (message.roomType == "group")) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"description": "Botkit template for Cisco Spark",
"version": "0.5.5",
"version": "0.6.0",
"main": "bot.js",
"scripts": {
"start": "node bot.js"
Expand Down
14 changes: 8 additions & 6 deletions skills/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ module.exports = function (controller) {

controller.hears([/^help$/], 'direct_message,direct_mention', function (bot, message) {
var text = "Here are my skills:";
text += "\n- " + bot.enrichCommand(message, "color") + ": ask to pick a random color";
text += "\n- " + bot.enrichCommand(message, "restricted") + ": let a user pick a color among a set of options";
text += "\n- " + bot.enrichCommand(message, "threads") + ": branch to another thread";
text += "\n- " + bot.enrichCommand(message, "variables") + ": enriched user-context among threads";
text += "\n- " + bot.appendMention(message, "color") + ": ask to pick a random color";
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.appendMention(message, "threads") + ": branch to another thread";
text += "\n- " + bot.appendMention(message, "variables") + ": enriched user-context among threads";
text += "\n\nI also understand:";
text += "\n- " + bot.enrichCommand(message, "about") + ": shows metadata about myself";
text += "\n- " + bot.enrichCommand(message, "help") + ": spreads the word about my skills";
text += "\n- " + bot.appendMention(message, "about") + ": shows metadata about myself";
text += "\n- " + bot.appendMention(message, "help") + ": spreads the word about my skills";
text += "\n- " + bot.appendMention(message, "show [skill]") + ": display the code of the specified skill";
bot.reply(message, text);
});
}
14 changes: 10 additions & 4 deletions skills/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (controller) {
controller.hears([/^storage$/], 'direct_message,direct_mention', function (bot, message) {

// Check if a User preference already exists
var userId = message.original_message.personId;
var userId = message.raw_message.actorId;
controller.storage.users.get(userId, function (err, data) {
if (err) {
bot.reply(message, 'could not access storage, err: ' + err.message, function (err, message) {
Expand All @@ -32,13 +32,19 @@ function showUserPreference(controller, bot, message, userId, color) {
bot.startConversation(message, function (err, convo) {

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

convo.ask("Should I remove your preference?", [

// 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)", [
{
pattern: "^yes|ya|da|si|oui$",
callback: function (response, convo) {

// Remove user preferences
controller.storage.users.remove(userId, function (err) {
if (err) {
convo.say(message, 'sorry, could not access storage, err: ' + err.message);
Expand Down
2 changes: 1 addition & 1 deletion skills/welcome.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ module.exports = function (controller) {

if (rawMessage.roomType == "group") {
help = "Note that this is a 'Group' Space. I will answer only if mentionned.<br/>";
help += "To learn about my skills, type " + bot.enrichCommand(rawMessage, "help");
help += "To learn about my skills, type " + bot.appendMention(rawMessage, "help");
}

bot.say({
Expand Down
2 changes: 1 addition & 1 deletion skills/z-fallback.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function (controller) {

controller.hears([".*"], 'direct_message,direct_mention', function (bot, message) {
var mardown = "Sorry, I did not understand.<br/>Try "
+ bot.enrichCommand(message, "help");
+ bot.appendMention(message, "help");

bot.reply(message, mardown);
});
Expand Down

0 comments on commit b5fe1c3

Please sign in to comment.