Skip to content

Commit

Permalink
reflected changes from Webex rebrand
Browse files Browse the repository at this point in the history
  • Loading branch information
ObjectIsAdvantag committed May 17, 2018
1 parent a2aaf2e commit def44c8
Show file tree
Hide file tree
Showing 28 changed files with 3,378 additions and 1,923 deletions.
14 changes: 7 additions & 7 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# - 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
#

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

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

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

# Local port where your bot will be started
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
*.lock
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"program": "${workspaceRoot}/bot.js",
"envFile": "${workspaceRoot}/.env",
"env": {
"SPARK_TOKEN": "PLACE_YOUR_BOT_TOKEN_HERE_FOR_DEBUG_PURPOSE",
"ACCESS_TOKEN": "PLACE_YOUR_ACCESS_TOKEN_HERE",
"PUBLIC_URL": "https://718670a3.ngrok.io",
"REDIS_URL": "redis://127.0.0.1:6379"
}
Expand Down
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Changes

### v0.7-plugin (2018-05-17): reflecting Webex Teams rebrand
- introducing ACCESS_TOKEN env variable
- backward compatibility for SPARK_TOKEN env variable
- documentation updates (removing spark mentions)
- added popular skills from [email protected]

### v0.6-plugin (2017-11-17): legacy version for Cisco Spark
- modular architecture

and all others features for the master branch

- configuration through environment variables or hard-coded values in the .env file
- skills: organize your bot behaviours by placing 'commands', 'conversations' and 'events' in the skills directory
- user experience: the template comes with ready-to-use skills: a 'welcome' invite, as well as 'help' and 'fallback' commands.
- healthcheck: easily check that everything goes well by hitting the ping endpoint automatically exposed.
- 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 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 also Heroku (if dyno-metadata are installed for Heroku).
35 changes: 20 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Template to bootstrap a Botkit project for Cisco Spark
# Modular Template to bootstrap a Botkit project for Webex Teams

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

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

All other features from the Botkit template's master branch apply (see below), BUT the capabity to run on glitch.

-------


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

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

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

- metadata: expose extra info via command and on a public address so that Spark users can inquire on Bot Author / Legal mentions / Healthcheck endpoint...
- 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...

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

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

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

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)

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

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

Create a new project pointing to this repo.

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

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.

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

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

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

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

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

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.
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.
4. You're ready to run your bot

From a bash shell:

```shell
git clone https://github.com/CiscoDevNet/botkit-template
git clone -b plugin https://github.com/CiscoDevNet/botkit-template
cd botkit-template
npm install
SPARK_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
ACCESS_TOKEN=0123456789abcdef PUBLIC_URL=https://abcdef.ngrok.io node bot.js
```

From a windows shell:

```shell
> git clone https://github.com/CiscoDevNet/botkit-template
> git clone -b plugin https://github.com/CiscoDevNet/botkit-template
> cd botkit-template
> npm install
> set SPARK_TOKEN=0123456789abcdef
> set ACCESS_TOKEN=0123456789abcdef
> set PUBLIC_URL=https://abcdef.ngrok.io
> node bot.js
```

where:

- SPARK_TOKEN is the API access token of your Cisco Spark bot
- PUBLIC_URL is the root URL at which Cisco Spark can reach your bot
- ACCESS_TOKEN is the API access token of your bot
- PUBLIC_URL is the root URL at which the Webex cloud platform can reach your bot
- [ngrok](http://ngrok.com) helps you expose the bot running on your laptop to the internet, type: `ngrok http 3000` to launch
34 changes: 18 additions & 16 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ var debug = require('debug')('starterkit');


//
// BotKit configuration
// Botkit configuration
//

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

// Fail fast
if (!process.env.SPARK_TOKEN) {
console.log("Could not start as bots require a Cisco Spark API access token.");
console.log("Please add env variable SPARK_TOKEN on the command line or to the .env file");

// Fetch token from environement
// [COMPAT] supports SPARK_TOKEN for backward compatibility
var accessToken = process.env.ACCESS_TOKEN || process.env.SPARK_TOKEN
if (!accessToken) {
console.log("Could not start as this bot requires a Webex Teams API access token.");
console.log("Please invoke with an ACCESS_TOKEN environment variable");
console.log("Example: ");
console.log("> SPARK_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
console.log("> ACCESS_TOKEN=XXXXXXXXXXXX PUBLIC_URL=YYYYYYYYYYYYY node bot.js");
process.exit(1);
}

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

Expand All @@ -51,14 +54,12 @@ if (!public_url) {
// Create bot
//

var Botkit = require('botkit');

var env = process.env.NODE_ENV || "development";

var configuration = {
public_address: process.env.PUBLIC_URL,
ciscospark_access_token: process.env.SPARK_TOKEN,
secret: process.env.SECRET, // this is a RECOMMENDED security setting that checks if incoming payloads originate from Cisco Spark
ciscospark_access_token: accessToken,
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 + ')')
}

Expand Down Expand Up @@ -87,9 +88,10 @@ catch (err) {
}
}

var controller = require('botkit').sparkbot(configuration);
var Botkit = require('botkit');
var controller = Botkit.sparkbot(configuration);

var sparkbot = controller.spawn({}, function (bot) {
var webexbot = controller.spawn({}, function (bot) {

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

controller.createWebhookEndpoints(webserver, sparkbot, function (err, success) {
controller.createWebhookEndpoints(webserver, webexbot, function (err, success) {
debug("Webhook successfully setup");
});

Expand All @@ -139,7 +141,7 @@ controller.setupWebserver(process.env.PORT || 3000, function (err, webserver) {
require("fs").readdirSync(pluginsPath).forEach(function (file) {
try {
if (file.endsWith(".js")) {
require("./plugins/" + file)(controller, sparkbot);
require("./plugins/" + file)(controller, webexbot);
debug("plugin loaded: " + file);
}
}
Expand Down
4 changes: 2 additions & 2 deletions configurations/redis-storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

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

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

Expand Down
Binary file modified docs/heroku_config-variables.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 3 additions & 4 deletions extensions/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
Place in this directory the extensions to be loaded into the bot spawned from BotKit controller.
Place in this directory the extensions to be loaded into the bot spawned from Botkit controller.

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

Examples:
Example:
- appendMention utility: append the bot name to a command if the current room is a 'Group' space
4 changes: 2 additions & 2 deletions extensions/append_mention.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
//

/*
* Utility to add mentions if Bot is in a 'Group' space
* Utility to add mentions if the bot is in a 'Group' space
*
*/
module.exports = function (bot) {

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

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

0 comments on commit def44c8

Please sign in to comment.