Skip to content

Commit b5fe1c3

Browse files
renamed enrichCommand to appendMention, fixed storage skill
1 parent 3e921cc commit b5fe1c3

7 files changed

Lines changed: 23 additions & 15 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This template regroups a set of best practices:
1212

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

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

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

bot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ require("fs").readdirSync(normalizedPath).forEach(function (file) {
120120
//
121121

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

125125
// if the message is a raw message (from a post message callback such as bot.say())
126126
if (message.roomType && (message.roomType == "group")) {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"description": "Botkit template for Cisco Spark",
3-
"version": "0.5.5",
3+
"version": "0.6.0",
44
"main": "bot.js",
55
"scripts": {
66
"start": "node bot.js"

skills/help.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@ module.exports = function (controller) {
55

66
controller.hears([/^help$/], 'direct_message,direct_mention', function (bot, message) {
77
var text = "Here are my skills:";
8-
text += "\n- " + bot.enrichCommand(message, "color") + ": ask to pick a random color";
9-
text += "\n- " + bot.enrichCommand(message, "restricted") + ": let a user pick a color among a set of options";
10-
text += "\n- " + bot.enrichCommand(message, "threads") + ": branch to another thread";
11-
text += "\n- " + bot.enrichCommand(message, "variables") + ": enriched user-context among threads";
8+
text += "\n- " + bot.appendMention(message, "color") + ": ask to pick a random color";
9+
text += "\n- " + bot.appendMention(message, "restricted") + ": let a user pick a color among a set of options";
10+
text += "\n- " + bot.appendMention(message, "storage") + ": store picked color as a user preference";
11+
text += "\n- " + bot.appendMention(message, "threads") + ": branch to another thread";
12+
text += "\n- " + bot.appendMention(message, "variables") + ": enriched user-context among threads";
1213
text += "\n\nI also understand:";
13-
text += "\n- " + bot.enrichCommand(message, "about") + ": shows metadata about myself";
14-
text += "\n- " + bot.enrichCommand(message, "help") + ": spreads the word about my skills";
14+
text += "\n- " + bot.appendMention(message, "about") + ": shows metadata about myself";
15+
text += "\n- " + bot.appendMention(message, "help") + ": spreads the word about my skills";
16+
text += "\n- " + bot.appendMention(message, "show [skill]") + ": display the code of the specified skill";
1517
bot.reply(message, text);
1618
});
1719
}

skills/storage.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = function (controller) {
66
controller.hears([/^storage$/], 'direct_message,direct_mention', function (bot, message) {
77

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

3434
convo.sayFirst(`Hey, I know you <@personId:${userId}>!<br/> '${color}' is your favorite color.`);
35-
36-
convo.ask("Should I remove your preference?", [
35+
36+
// Remove user preferences if supported
37+
if (!controller.storage.users.remove) {
38+
convo.say("_To erase your preference, simply restart the bot as you're using in-memory transient storage._");
39+
convo.next();
40+
return;
41+
}
42+
43+
convo.ask("Should I erase your preference? yes/(no)", [
3744
{
3845
pattern: "^yes|ya|da|si|oui$",
3946
callback: function (response, convo) {
4047

41-
// Remove user preferences
4248
controller.storage.users.remove(userId, function (err) {
4349
if (err) {
4450
convo.say(message, 'sorry, could not access storage, err: ' + err.message);

skills/welcome.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ module.exports = function (controller) {
2525

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

3131
bot.say({

skills/z-fallback.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module.exports = function (controller) {
55

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

1010
bot.reply(message, mardown);
1111
});

0 commit comments

Comments
 (0)