Skip to content

Commit def44c8

Browse files
reflected changes from Webex rebrand
1 parent a2aaf2e commit def44c8

28 files changed

Lines changed: 3378 additions & 1923 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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Changes
2+
3+
### v0.7-plugin (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-plugin (2017-11-17): legacy version for Cisco Spark
10+
- modular architecture
11+
12+
and all others features for the master branch
13+
14+
- configuration through environment variables or hard-coded values in the .env file
15+
- skills: organize your bot behaviours by placing 'commands', 'conversations' and 'events' in the skills directory
16+
- user experience: the template comes with ready-to-use skills: a 'welcome' invite, as well as 'help' and 'fallback' commands.
17+
- healthcheck: easily check that everything goes well by hitting the ping endpoint automatically exposed.
18+
- metadata: expose extra info via command and on a public address so that Spark users can inquire on Bot Author / Legal mentions / Healthcheck endpoint...
19+
- mentions: the appendMention utility function helps Spark users remind to mention the bot in Group spaces.
20+
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: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1-
# Template to bootstrap a Botkit project for Cisco Spark
1+
# Modular Template to bootstrap a Botkit project for Webex Teams
22

3-
This template regroups a set of best practices:
3+
This template adds a modular architecture to the Botkit master template.
44

5-
- plugable architecture: as Botkit launches, several directories are loaded to customize your bot, in the order below:
5+
Pplugable architecture features: as Botkit launches, several directories are loaded to customize your bot, in the order below:
66
1. configurations: add complex configuration settings that get activated from env variables
77
2. extensions: add extra utility function to the bot object
88
3. plugins: add extra routes/middlewares to your bot
99
4. skills: organize your bot behaviours by placing 'commands', 'conversations' and 'events' in the [skills directory](skills/README.md).
1010

11+
All other features from the Botkit template's master branch apply (see below), BUT the capabity to run on glitch.
12+
13+
-------
14+
15+
1116
- configuration: pass settings either through environment variables on the command line, or hard-coded values in the `.env` file. Note that command line variables are priorized over the `.env` file if present in both places.
1217

1318
- user experience: the template comes ready-to-use skills: a 'welcome' invite, as well as 'help' and 'fallback' commands.
1419

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

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...
22+
- 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...
1823

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

2126
- popular cloud providers: the bot self-configures when run on Glitch and Heroku (if dyno metadata have been enabled via the Heroku CLI)
2227

@@ -25,7 +30,7 @@ This template regroups a set of best practices:
2530

2631
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)
2732

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

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

3843
Create a new project pointing to this repo.
3944

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

4247
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.
4348

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

55-
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.
60+
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.
5661

5762
2. Launch ngrok to expose port 3000 of your local machine to the internet:
5863

@@ -66,32 +71,32 @@ you can run this template in a snatch.
6671

6772
_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_
6873

69-
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.
74+
To successfully run your bot, you'll need to specify a PUBLIC_URL for your bot, and a Webex Teams 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.
7075
7176
4. You're ready to run your bot
7277

7378
From a bash shell:
7479

7580
```shell
76-
git clone https://github.com/CiscoDevNet/botkit-template
81+
git clone -b plugin https://github.com/CiscoDevNet/botkit-template
7782
cd botkit-template
7883
npm install
79-
SPARK_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
84+
ACCESS_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
8085
```
8186

8287
From a windows shell:
8388

8489
```shell
85-
> git clone https://github.com/CiscoDevNet/botkit-template
90+
> git clone -b plugin https://github.com/CiscoDevNet/botkit-template
8691
> cd botkit-template
8792
> npm install
88-
> set SPARK_TOKEN=0123456789abcdef
93+
> set ACCESS_TOKEN=0123456789abcdef
8994
> set PUBLIC_URL=https://abcdef.ngrok.io
9095
> node bot.js
9196
```
9297

9398
where:
9499

95-
- SPARK_TOKEN is the API access token of your Cisco Spark bot
96-
- PUBLIC_URL is the root URL at which Cisco Spark can reach your bot
100+
- ACCESS_TOKEN is the API access token of your bot
101+
- PUBLIC_URL is the root URL at which the Webex cloud platform can reach your bot
97102
- [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: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,25 @@ var debug = require('debug')('starterkit');
88

99

1010
//
11-
// BotKit configuration
11+
// Botkit configuration
1212
//
1313

1414
// Load environment variables from project .env file
1515
require('node-env-file')(__dirname + '/.env');
1616

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

26-
// Get public URL where Cisco Spark will post spaces notifications (webhook registration)
29+
// Get public URL where the Webex cloud platform will post notifications (webhook registration)
2730
var public_url = process.env.PUBLIC_URL;
2831
// Infer the app domain for popular Cloud PaaS
2932
if (!public_url) {
@@ -42,7 +45,7 @@ if (!public_url) {
4245
console.log("Could not start as this bot must expose a public endpoint.");
4346
console.log("Please add env variable PUBLIC_URL on the command line or to the .env file");
4447
console.log("Example: ");
45-
console.log("> SPARK_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
48+
console.log("> ACCESS_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
4649
process.exit(1);
4750
}
4851

@@ -51,14 +54,12 @@ if (!public_url) {
5154
// Create bot
5255
//
5356

54-
var Botkit = require('botkit');
55-
5657
var env = process.env.NODE_ENV || "development";
5758

5859
var configuration = {
5960
public_address: process.env.PUBLIC_URL,
60-
ciscospark_access_token: process.env.SPARK_TOKEN,
61-
secret: process.env.SECRET, // this is a RECOMMENDED security setting that checks if incoming payloads originate from Cisco Spark
61+
ciscospark_access_token: accessToken,
62+
secret: process.env.SECRET, // this is a RECOMMENDED security setting that checks if incoming payloads originate from Webex
6263
webhook_name: process.env.WEBHOOK_NAME || ('built with BotKit (' + env + ')')
6364
}
6465

@@ -87,9 +88,10 @@ catch (err) {
8788
}
8889
}
8990

90-
var controller = require('botkit').sparkbot(configuration);
91+
var Botkit = require('botkit');
92+
var controller = Botkit.sparkbot(configuration);
9193

92-
var sparkbot = controller.spawn({}, function (bot) {
94+
var webexbot = controller.spawn({}, function (bot) {
9395

9496
// Load bot extensions: append_mention, botcommons metadata
9597
try {
@@ -129,7 +131,7 @@ controller.setupWebserver(process.env.PORT || 3000, function (err, webserver) {
129131
throw err;
130132
}
131133

132-
controller.createWebhookEndpoints(webserver, sparkbot, function (err, success) {
134+
controller.createWebhookEndpoints(webserver, webexbot, function (err, success) {
133135
debug("Webhook successfully setup");
134136
});
135137

@@ -139,7 +141,7 @@ controller.setupWebserver(process.env.PORT || 3000, function (err, webserver) {
139141
require("fs").readdirSync(pluginsPath).forEach(function (file) {
140142
try {
141143
if (file.endsWith(".js")) {
142-
require("./plugins/" + file)(controller, sparkbot);
144+
require("./plugins/" + file)(controller, webexbot);
143145
debug("plugin loaded: " + file);
144146
}
145147
}

configurations/redis-storage.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
/**
7-
* Adds a persistent storage to Redis to BotKit configuration
7+
* Adds a persistent storage to Redis to Botkit configuration
88
*
99
* Setup instructions:
1010
* - add a REDIS_URL env variable pointing to the redis instance
@@ -28,7 +28,7 @@ module.exports = function (configuration) {
2828
//, namespace: 'cisco:devnet'
2929
};
3030

31-
// Create Redis storage for BotKit
31+
// Create Redis storage for Botkit
3232
try {
3333
var redisStorage = require('botkit-storage-redis')(redisConfig);
3434

docs/heroku_config-variables.png

-13.8 KB
Loading

extensions/README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
Place in this directory the extensions to be loaded into the bot spawned from BotKit controller.
1+
Place in this directory the extensions to be loaded into the bot spawned from Botkit controller.
22

3-
This is your opportunity to enrich the interactions with Cisco Spark.
4-
by adding extra properties and functions to the `bot` object passed to your skills.
3+
This is your opportunity to enrich the interactions with Webex by adding extra properties and functions to the `bot` object passed to your skills.
54

6-
Examples:
5+
Example:
76
- appendMention utility: append the bot name to a command if the current room is a 'Group' space

extensions/append_mention.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
//
55

66
/*
7-
* Utility to add mentions if Bot is in a 'Group' space
7+
* Utility to add mentions if the bot is in a 'Group' space
88
*
99
*/
1010
module.exports = function (bot) {
1111

12-
// Utility to add mentions if Bot is in a 'Group' space
12+
// Add support for the append mention
1313
bot.appendMention = function (message, command) {
1414

1515
// if the message is a raw message (from a post message callback such as bot.say())

0 commit comments

Comments
 (0)