Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ jspm_packages
.node_repl_history

#config
config.json
#config.json
# Removing config-template.json for simplicity

#DS Store
.DS_Store
4 changes: 4 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"tabWidth": 2,
"useTabs": false
}
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Webex-Bot-Starter

-----

**Note:** To skip the details and get up and running ASAP, see here: **[quickstart.md](./quickstart.md)**

------

### Starter kit and template for a simple Webex Teams bot

*For a more detailed walkthorugh, see the companion blog post here: https://developer.webex.com/blog/from-zero-to-webex-teams-chatbot-in-15-minutes*
Expand Down Expand Up @@ -27,12 +33,20 @@ git

2. Sign up for nGrok, then connect and start it on your machine (save the port number and public web address): https://ngrok.com/download

3. Add the nGrok address, port number and bot access token to the `config-template.json` file
3. Add the nGrok address, port number and bot access token to the **[config.json](config.json)** file

4. Re-name the `config-template.json` file as `config.json`
4.

5. Turn on your bot server with ```npm start```

6. Create a space in Webex Teams

7. Add the bot (by its username) to the space in Webex Teams
7. Add the bot (by its username) to the space in Webex Teams


nGrok
>start from config file
>bind tls
>region
"region":"us",
"bind_tls":true
8 changes: 6 additions & 2 deletions config-template.json → config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
{
"webhookUrl": "http://_REPLACE_THIS_WITH_NGROK_URL_.ngrok.io",
"token": "REPLACE_THIS_WITH_YOUR_BOT_API_KEY",
"port": 7001
}
"port": 7001,
"webhookRoute": "/",
"ngrok_config": {
"region": "us"
}
}
Binary file added docs/assets/inspector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/quickstart_boot.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/quickstart_create.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/quickstart_space.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/quickstart_token.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/assets/quickstart_tunnel.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions docs/ngrok.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
### nGrok

**THIS IS IMPORTANT:** nGrok is a tool that will expose a port on your machine to a fixed URL controlled by nGrok's systems. This is done as a convenience feature to make local development of your webhook fast/easy.

nGrok details their available password-protected & enterprise/pro plans here: **https://ngrok.com/pricing**

See below for similiar **[tools and alternatives](#Tunneling-Tools)**

Long story short, using nGrok for local development means you...

1) Trust nGrok & the team building services for it

2) Trust the author of the **[nGrok npm package(^3.2.7)](https://www.npmjs.com/package/ngrok)** (which is not controlled by nGrok) which downloads an nGrok binary, its source code is available here: https://github.com/bubenshchykov/ngrok



## Background
nGrok was developed by **[Alan Shreeve](https://twitter.com/inconshreveable)** as a way to learn Go. nGrok will open a "secure" tunnel to nGrok's system so external services (like a webhook system) can access exposed resources on your local machine as if they were deployed on the public internet. This can make developing fulfillment webhooks insanely convenient & fast-- nGrok also comes with a network inspector available on localhost:4040

## Config

If you are having any trouble, you can change the "ngrok" configuration fields in the main **[config.json file](config.json)**

```json
"ngrok": {
"region":"us",
"bind_tls":true
}
```
<details><summary>(Expand for details on nGrok configuration options)</summary>
<p>

There are lots of options you can use to configure nGrok, see here for details: **https://ngrok.com/docs**

Enterprise/Pro features available here: https://ngrok.com/pricing

| **Item** | Description |
| --- | --- |
| **proto** | tunnel protocol name, one of http, tcp, tls |
| **addr** | forward traffic to this local port number or network address |
| **inspect** | enable http request inspection |
| **auth** | HTTP basic authentication credentials to enforce on tunneled requests |
| **host_header** | Rewrite the HTTP Host header to this value, or preserve to leave it unchanged |
| **bind_tls** | bind an HTTPS or HTTP endpoint or both true, false, or both |
| **subdomain** | subdomain name to request. If unspecified, uses the tunnel name |
| **hostname** | hostname to request (requires reserved name and DNS CNAME) |
| **crt** | PEM TLS certificate at this path to terminate TLS traffic before forwarding locally |
| **key** | PEM TLS private key at this path to terminate TLS traffic before forwarding locally |
| **client_cas** | PEM TLS certificate authority at this path will verify incoming TLS client connection certificates. |
| **remote_addr** | bind the remote TCP port on the given address |
| **metadata** | arbitrary user-defined metadata that will appear in the ngrok service API when listing tunnels |

| Region | Code |
| --- | --- |
| **ap** | Asia/Pacific |
| **au** | Australia |
| **eu** | Europe |
| **in** | India |
| **jp** | Japan |
| **sa** | South America |
| **us** | United States (default) |
</p>
</details>


## Tunneling Tools

These are provided as suggestions for further inspection only-- make sure you and/or security team to audit any tunneling tools before using on a network

- https://ngrok.com/

- https://localtunnel.github.io/www/

- http://localhost.run/

- https://telebit.cloud/

13 changes: 13 additions & 0 deletions docs/resources.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## Resources

Links & documentation

## Guides & posts

https://developer.webex.com/docs/bots

https://developer.webex.com/blog/from-zero-to-webex-teams-chatbot-in-15-minutes

## Learning Labs

https://developer.cisco.com/learning/lab/collab-spark-botkit/step/1
18 changes: 12 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json());
app.use(express.static('images'));
const config = require("./config.json");
const config = require('./config.json');

// init framework
var framework = new framework(config);
framework.start();
console.log("Starting framework, please wait...");

framework.on("initialized", function () {
console.log("framework is all fired up! [Press CTRL-C to quit]");
console.log(`framework is all fired up on port ${config.port}! [Press CTRL-C to quit]`);
});

// A spawn event is generated when the framework finds a space with your bot in it
Expand Down Expand Up @@ -215,7 +215,7 @@ framework.hears(/.*/, function (bot, trigger) {
});

function sendHelp(bot) {
bot.say("markdown", 'These are the commands I can respond to:', '\n\n ' +
bot.say("markdown", 'These are some of the commands I can respond to:', '\n\n ' +
'1. **framework** (learn more about the Webex Bot Framework) \n' +
'2. **info** (get your personal details) \n' +
'3. **space** (get details about this space) \n' +
Expand All @@ -229,13 +229,19 @@ function sendHelp(bot) {
//Server config & housekeeping
// Health Check
app.get('/', function (req, res) {
res.send(`I'm alive.`);
res.send(`Backend is up and running ${String(new Date())}`);
});

app.post('/', webhook(framework));
app.post(config.webhookRoute, webhook(framework));
/**
* ex
* app.post('/mywebhookroute', webhook(framework))
*
**/

var server = app.listen(config.port, function () {
framework.debug('framework listening on port %s', config.port);
framework.debug(`framework listening on port ${config.port}`);
framework.debug(`Webhook URL set to ${config.webhookUrl}`)
});

// gracefully shutdown (ctrl-c)
Expand Down
6 changes: 6 additions & 0 deletions nodemon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"watch": ["*"],
"ext": "js json",
"ignore": ["node_modules"],
"exec": "npm run start:noinstall"
}
Loading