Skip to content

Commit df7ece6

Browse files
reflected changes from Webex rebrand
1 parent 31c399a commit df7ece6

22 files changed

Lines changed: 399 additions & 1899 deletions

.env

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
# - note that ".env" is formatted like a shell file, so you may (depending on your platform) need to add double quotes if strings contains spaces
1212
#
1313

14-
# Uncomment if you wish to statically set a Cisco Spark access token
14+
# Uncomment if you wish to statically set a Webex Teams API access token
1515
# - if you do so, make sure not to version that file in a public repo
1616
# - if running the code from a private machine, setting secrets on the command line is recommended
17-
SPARK_TOKEN=
17+
ACCESS_TOKEN=
1818

1919
# Secret used to generate an HMAC-SHA1 for each payload submitted to your bot
2020
# Optional but highly recommended to use a Secret when going to production
@@ -27,19 +27,19 @@ SECRET="Not that secret !"
2727
#PUBLIC_URL=https://your-app.herokuapp.com
2828
#PUBLIC_URL=https://sharp-stove.glitch.me
2929

30-
# Name used to create the webhook to register your bot against Cisco Spark
30+
# Name used to create the webhook to register your bot against Webex
3131
# Defaults to 'built with BotKit (development)'
3232
#
3333
# WARNING: if you set or update this value,
34-
# - BotKit will automatically create a new Cisco Spark WebHook with the SPARK_TOKEN above
34+
# - BotKit will automatically create a new webHook with the ACCESS_TOKEN above
3535
# - BUT BotKit will not delete the previously created WebHook entry
3636
# - YOU will need to take this action manually
3737
# HERE'S HOW
38-
# - manually list your bot webhooks via Postman or the Spark API documentation
38+
# - manually list your bot webhooks via Postman or the Webex for Developers API documentation
3939
# /!\ make sure to use your bot's access token
40-
# https://developer.ciscospark.com/endpoint-webhooks-get.html
40+
# https://developer.webex.com/endpoint-webhooks-get.html
4141
# - identify the previously registered webhook identifier and delete it
42-
# https://developer.ciscospark.com/endpoint-webhooks-webhookId-delete.html
42+
# https://developer.webex.com/endpoint-webhooks-webhookId-delete.html
4343
#WEBHOOK_NAME="built with BotKit (development)"
4444

4545
# Local port where your bot will be started

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
node_modules
2+
*.lock

.vscode/launch.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"program": "${workspaceRoot}/bot.js",
99
"envFile": "${workspaceRoot}/.env",
1010
"env": {
11-
"SPARK_TOKEN": "PLACE_YOUR_BOT_TOKEN_HERE_FOR_DEBUG_PURPOSE",
11+
"ACCESS_TOKEN": "PLACE_YOUR_ACCESS_TOKEN_HERE",
1212
"PUBLIC_URL": "https://718670a3.ngrok.io",
1313
"REDIS_URL": "redis://127.0.0.1:6379"
1414
}

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Changes
2+
3+
### v0.7-redis (2018-05-17): reflecting Webex Teams rebrand
4+
- introducing ACCESS_TOKEN env variable
5+
- backward compatibility for SPARK_TOKEN env variable
6+
- documentation updates (removing spark mentions)
7+
- added popular skills from convos@sparkbot.io
8+
9+
### v0.6-redis (2017-11-17): legacy version for Cisco Spark
10+
- Redis support via the REDIS_URL variable
11+
12+
and all others features for the master branch
13+
- configuration through environment variables or hard-coded values in the .env file
14+
- skills: organize your bot behaviours by placing 'commands', 'conversations' and 'events' in the skills directory
15+
- user experience: the template comes with ready-to-use skills: a 'welcome' invite, as well as 'help' and 'fallback' commands.
16+
- healthcheck: easily check that everything goes well by hitting the ping endpoint automatically exposed.
17+
- metadata: expose extra info via command and on a public address so that Spark users can inquire on Bot Author / Legal mentions / Healthcheck endpoint...
18+
- mentions: the appendMention utility function helps Spark users remind to mention the bot in Group spaces.
19+
popular cloud providers: the bot self-configures when run on Glitch, and also Heroku (if dyno-metadata are installed for Heroku).

README.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Template to bootstrap a Botkit project for Cisco Spark
1+
# Template to bootstrap a Botkit project for Webex Teams
22

33
This template regroups a set of best practices:
44

@@ -10,18 +10,18 @@ This template regroups a set of best practices:
1010

1111
- healthcheck: easilly check that everything goes well by hitting the `ping` endpoint automatically exposed.
1212

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

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

17-
- popular cloud providers: the bot self-configures when run on Glitch and Heroku (if )
17+
- popular cloud providers: the bot self-configures when run on Glitch and Heroku (if the dyno_metadata feature is activated)
1818

1919

2020
## Quick start on Glitch
2121

2222
Click [![Remix on Glitch](https://cdn.glitch.com/2703baf2-b643-4da7-ab91-7ee2a2d00b5b%2Fremix-button.svg)](https://glitch.com/edit/#!/import/github/CiscoDevNet/botkit-template)
2323

24-
Then open the `.env` file and paste your bot's token into the SPARK_TOKEN variable.
24+
Then open the `.env` file and paste your bot's token into the ACCESS_TOKEN variable.
2525

2626
You bot is all set, responding in 1-1 and 'group' spaces, and sending a welcome message when added to a space,
2727
Its healthcheck is accessible at your application public url, suffixed with "/ping"
@@ -33,7 +33,7 @@ _Note that thanks to Glitch 'PROJECT_DOMAIN' env variable, you did not need to a
3333

3434
Create a new project pointing to this repo.
3535

36-
Reach to your app settings, reveal your config variables, and add a SPARK_TOKEN variable with your bot token as value.
36+
Reach to your app settings, reveal your config variables, and add a ACCESS_TOKEN variable with your bot token as value.
3737

3838
Unless your app is using [Dyno Metadata](https://devcenter.heroku.com/articles/dyno-metadata), you also need to add a PUBLIC_URL variable pointing to your app domain.
3939

@@ -48,7 +48,7 @@ Its healthcheck is accessible at your application public url, suffixed with "/pi
4848
Assuming you plan to expose your bot via [ngrok](https://ngrok.com),
4949
you can run this template in a snatch.
5050

51-
1. Create a Bot Account from the ['Spark for developers' bot creation page](https://developer.ciscospark.com/add-bot.html), and copy your bot's access token.
51+
1. Create a Bot Account from the ['Webex for developers' bot creation page](https://developer.webex.com/add-bot.html), and copy your bot's access token.
5252

5353
2. Launch ngrok to expose port 3000 of your local machine to the internet:
5454

@@ -62,7 +62,7 @@ you can run this template in a snatch.
6262

6363
_Note that you can also specify any of these settings via env variables. In practice, the values on the command line or in your machine env will prevail over .env file settings_
6464

65-
To successfully run your bot, you'll need to specify a PUBLIC_URL for your bot, and a Cisco Spark API token (either in the .env settings or via env variables). In the example below, we do not modify any value in settings and specify all configuration values on the command line.
65+
To successfully run your bot, you'll need to specify a PUBLIC_URL for your bot, and a Webex Teaùs API ACCESS_TOKEN (either in the .env settings or via env variables). In the example below, we do not modify any value in settings and specify all configuration values on the command line.
6666
6767
4. You're ready to run your bot
6868

@@ -72,7 +72,7 @@ you can run this template in a snatch.
7272
git clone https://github.com/CiscoDevNet/botkit-template
7373
cd botkit-template
7474
npm install
75-
SPARK_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
75+
ACCESS_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
7676
```
7777

7878
From a windows shell:
@@ -81,13 +81,13 @@ you can run this template in a snatch.
8181
> git clone https://github.com/CiscoDevNet/botkit-template
8282
> cd botkit-template
8383
> npm install
84-
> set SPARK_TOKEN=0123456789abcdef
84+
> set ACCESS_TOKEN=0123456789abcdef
8585
> set PUBLIC_URL=https://abcdef.ngrok.io
8686
> node bot.js
8787
```
8888

8989
where:
9090

91-
- SPARK_TOKEN is the API access token of your Cisco Spark bot
92-
- PUBLIC_URL is the root URL at which Cisco Spark can reach your bot
91+
- ACCESS_TOKEN is the API access token of your bot
92+
- PUBLIC_URL is the root URL at which the Webex cloud platform can reach your bot
9393
- [ngrok](http://ngrok.com) helps you expose the bot running on your laptop to the internet, type: `ngrok http 3000` to launch

bot.js

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,19 @@
1010
// Load environment variables from project .env file
1111
require('node-env-file')(__dirname + '/.env');
1212

13-
if (!process.env.SPARK_TOKEN) {
14-
console.log("Could not start as bots require a Cisco Spark API access token.");
15-
console.log("Please add env variable SPARK_TOKEN on the command line or to the .env file");
13+
14+
// Fetch token from environement
15+
// [COMPAT] supports SPARK_TOKEN for backward compatibility
16+
var accessToken = process.env.ACCESS_TOKEN || process.env.SPARK_TOKEN
17+
if (!accessToken) {
18+
console.log("Could not start as this bot requires a Webex Teams API access token.");
19+
console.log("Please invoke with an ACCESS_TOKEN environment variable");
1620
console.log("Example: ");
17-
console.log("> SPARK_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
21+
console.log("> ACCESS_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
1822
process.exit(1);
1923
}
2024

21-
// Get public URL where Cisco Spark will post spaces notifications (webhook registration)
25+
// Get public URL where Web will post notifications (webhook registration)
2226
var public_url = process.env.PUBLIC_URL;
2327
// Infer the app domain for popular Cloud PaaS
2428
if (!public_url) {
@@ -37,7 +41,7 @@ if (!public_url) {
3741
console.log("Could not start as this bot must expose a public endpoint.");
3842
console.log("Please add env variable PUBLIC_URL on the command line or to the .env file");
3943
console.log("Example: ");
40-
console.log("> SPARK_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
44+
console.log("> ACCESS_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
4145
process.exit(1);
4246
}
4347

@@ -53,9 +57,8 @@ var env = process.env.NODE_ENV || "development";
5357
var configuration = {
5458
log: true,
5559
public_address: public_url,
56-
ciscospark_access_token: process.env.SPARK_TOKEN,
57-
secret: process.env.SECRET, // this is a RECOMMENDED security setting that checks of incoming payloads originate from Cisco Spark
58-
webhook_name: process.env.WEBHOOK_NAME || ('built with BotKit (' + env + ')')
60+
ciscospark_access_token: accessToken,
61+
secret: process.env.SECRET, // this is a RECOMMENDED security setting that checks if incoming payloads originate from Webex webhook_name: process.env.WEBHOOK_NAME || ('built with BotKit (' + env + ')')
5962
}
6063

6164
if (process.env.REDIS_URL) {
@@ -73,7 +76,7 @@ if (process.env.REDIS_URL) {
7376
//, namespace: 'cisco:devnet'
7477
};
7578

76-
// Create Redis storage for BotKit
79+
// Create Redis storage for Botkit
7780
try {
7881
var redisStorage = require('botkit-storage-redis')(redisConfig);
7982

@@ -102,7 +105,7 @@ var bot = controller.spawn({
102105
var port = process.env.PORT || 3000;
103106
controller.setupWebserver(port, function (err, webserver) {
104107
controller.createWebhookEndpoints(webserver, bot, function () {
105-
console.log("Cisco Spark: Webhooks set up!");
108+
console.log("webhooks setup successfully");
106109
});
107110

108111
// installing Healthcheck
@@ -115,7 +118,7 @@ controller.setupWebserver(port, function (err, webserver) {
115118
};
116119
webserver.get(process.env.HEALTHCHECK_ROUTE, function (req, res) {
117120

118-
// As the identity is load asynchronously from Cisco Spark token, we need to check until it's fetched
121+
// As the identity is load asynchronously from the access token, we need to check until it's fetched
119122
if (healthcheck.bot == "unknown") {
120123
var identity = bot.botkit.identity;
121124
if (bot.botkit.identity) {
@@ -125,7 +128,7 @@ controller.setupWebserver(port, function (err, webserver) {
125128

126129
res.json(healthcheck);
127130
});
128-
console.log("Cisco Spark: healthcheck available at: " + process.env.HEALTHCHECK_ROUTE);
131+
console.log("healthcheck available at: " + process.env.HEALTHCHECK_ROUTE);
129132
});
130133

131134

@@ -137,20 +140,20 @@ var normalizedPath = require("path").join(__dirname, "skills");
137140
require("fs").readdirSync(normalizedPath).forEach(function (file) {
138141
try {
139142
require("./skills/" + file)(controller, bot);
140-
console.log("Cisco Spark: loaded skill: " + file);
143+
console.log("loaded skill: " + file);
141144
}
142145
catch (err) {
143146
if (err.code == "MODULE_NOT_FOUND") {
144147
if (file != "utils") {
145-
console.log("Cisco Spark: could not load skill: " + file);
148+
console.log("could not load skill: " + file);
146149
}
147150
}
148151
}
149152
});
150153

151154

152155
//
153-
// Cisco Spark Utilities
156+
// Webex Teams Utilities
154157
//
155158

156159
// Utility to add mentions if Bot is in a 'Group' space

docs/heroku_config-variables.png

-13.8 KB
Loading

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
2-
"description": "Botkit template for Cisco Spark",
3-
"version": "0.6.0-redis3",
2+
"description": "Botkit template for Webex Teams with Redis support",
3+
"version": "0.7.0-redis1",
44
"main": "bot.js",
55
"scripts": {
66
"start": "node bot.js"
77
},
88
"keywords": [
9-
"ciscospark",
9+
"webex",
10+
"webex-teams",
1011
"botkit",
1112
"devnet"
1213
],
1314
"author": "Stève Sfartz (Cisco DevNet) <stsfartz@cisco.com>",
1415
"license": "MIT",
1516
"dependencies": {
16-
"botkit": "0.6.0",
17+
"botkit": "0.6.14",
1718
"botkit-storage-redis": "1.1.0",
1819
"node-env-file": "0.1.8"
1920
},

skills/README.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
# Placeholder for your bot's skills
22

3+
This directory and subdirectories are automatically imported.
34
Add scripts to enrich your bot skills.
45

56
_Note that the skills are imported in alphabetical order of their file name. As such, the fallback skill is prefixed with a 'z-' to ensure it is loaded last, ie, if no pattern match, the fallback skill will apply to any message sent to the bot_
6-
7-
8-
This directory and subdirectories are automatically imported by the Cisco Spark starter kit.
9-
10-
_Note that you can place common code in the 'utils' directory, as it is not loaded automatically by design._
11-

skills/about.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ module.exports = function (controller, bot) {
2121
"support-contact": "Stève Sfartz <mailto:stsfartz@cisco.com>",
2222

2323
// Messaging platform
24-
"plaform": bot.type,
24+
// [WORKAROUND] overriding Botkit's integrated support temporarly as 'ciscospark' is still returned
25+
//"plaform": bot.type,
26+
"plaform": "webex",
2527

26-
// the precise bot identity is loaded asynchronously, as /people/me request - issued by "BotKit CiscoSparkBot.js" - returns
28+
// the precise bot identity is loaded asynchronously, from a GET /people/me request
2729
"identity": "unknown",
2830

2931
// Endpoint where to check the bot is alive
@@ -37,13 +39,13 @@ module.exports = function (controller, bot) {
3739
// Adding a metadata endpoint
3840
//
3941
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
42+
// As the identity is load asynchronously from the access token, we need to check until it's fetched
4143
if ((botcommons.identity == "unknown") && (bot.botkit.identity)) {
4244
botcommons.identity = bot.botkit.identity.emails[0];
4345
}
4446
res.json(botcommons);
4547
});
46-
console.log("CiscoSpark: Bot metadata available at: " + process.env.BOTCOMMONS_ROUTE);
48+
console.log("bot metadata available at: " + process.env.BOTCOMMONS_ROUTE);
4749

4850
//
4951
// .botcommons skill
@@ -62,4 +64,4 @@ module.exports = function (controller, bot) {
6264
bot.reply(message, '```json\n' + metadata + '\n```');
6365
});
6466

65-
}
67+
}

0 commit comments

Comments
 (0)