Skip to content

Commit 5676566

Browse files
botcommons identity and platform are now dynamic
1 parent 23e8570 commit 5676566

3 files changed

Lines changed: 10 additions & 6 deletions

File tree

bot.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ controller.setupWebserver(port, function (err, webserver) {
102102
var normalizedPath = require("path").join(__dirname, "skills");
103103
require("fs").readdirSync(normalizedPath).forEach(function (file) {
104104
try {
105-
require("./skills/" + file)(controller);
105+
require("./skills/" + file)(controller, bot);
106106
console.log("Cisco Spark: loaded skill: " + file);
107107
}
108108
catch (err) {

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.3",
3+
"version": "0.5.4",
44
"main": "bot.js",
55
"scripts": {
66
"start": "node bot.js"

skills/command-botcommons.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// Adds meta information about the bot, and exposes them at a public endpoint
33
//
4-
module.exports = function (controller) {
4+
module.exports = function (controller, bot) {
55

66
//
77
// OVERRIDE WITH YOUR BOT INFORMATION
@@ -21,10 +21,10 @@ module.exports = function (controller) {
2121
"support-contact": "Stève Sfartz <mailto:stsfartz@cisco.com>",
2222

2323
// Messaging platform
24-
"plaform": "ciscospark",
24+
"plaform": bot.type,
2525

2626
// the precise bot identity is loaded asynchronously, as /people/me request - issued by "BotKit CiscoSparkBot.js" - returns
27-
"identity": "convos@sparkbot.io",
27+
"identity": "unknown",
2828

2929
// Endpoint where to check the bot is alive
3030
"healthcheck": "https://" + controller.config.public_address + process.env.HEALTHCHECK_ROUTE,
@@ -37,14 +37,18 @@ module.exports = function (controller) {
3737
// Adding a metadata endpoint
3838
//
3939
controller.webserver.get(process.env.BOTCOMMONS_ROUTE, function (req, res) {
40+
// As the identity is load asynchronously from Cisco Spark token, we need to check until it's fetched
41+
if ((botcommons.identity == "unknown") && (bot.botkit.identity)) {
42+
botcommons.identity = bot.botkit.identity.emails[0];
43+
}
4044
res.json(botcommons);
4145
});
4246
console.log("CiscoSpark: Bot metadata available at: " + process.env.BOTCOMMONS_ROUTE);
4347

4448
//
4549
// .botcommons skill
4650
//
47-
controller.hears([/^\.about$/, /^\.commons$/, /^\.bot$/, /^\.ping$/], 'direct_message,direct_mention', function (bot, message) {
51+
controller.hears([/^\about$/, /^\botcommons$/, /^\.commons$/, /^\.bot$/], 'direct_message,direct_mention', function (bot, message) {
4852

4953
// Return metadata
5054
var metadata = '{\n'

0 commit comments

Comments
 (0)