Cisco Spark Websocket Events
Provides a simple way to get events through Cisco Spark's native websocket.
This module is useful when deploying a Cisco Spark bot behind a firewall with no way to get the traditional inbound webhooks back to the bot.
Installation
npm install ciscospark-websocket-events
Usage
This module can be used in two different ways. The first is by setting an event callback to handle the events directly in your code. The second is to define URL to the location you would like to post event data to.
The current events supported are:
- Message Created
- Membership Created
- Room Updated
Here is an example event:
Example 1: using the event handler callback
Run the sample from a terminal:
> cd ciscospark-websocket-events> npm install> cd tests> SPARK_TOKEN=XXXXXXXXXXXXXXXXX node event-callback.js...
Check the code:
var SparkWebSocket = ; var accessToken = processenvSPARK_TOKEN; sparkwebsocket = accessToken; sparkwebsocket:
Example 2: forwarding the event using the webhook_url
var SparkWebSocket = ; var accessToken = processenvSPARK_TOKEN; var webHookUrl = processenvWEBHOOK_URL; // http://localhost:8080/mybot/incoming_event sparkwebsocket = accessToken; sparkwebsocket;
BotKit Example
Run the sample from a terminal:
> cd examples> cd botkit> npm install> SPARK_TOKEN=XXXXXXXXXXXXXXXXX node bot.js...
Check the BotKit code sample:
/// Setup the Cisco Spark Websocket var SparkWebSocket = var accessToken = processenvSPARK_TOKENvar PORT = processenvPORT || 3000 var webHookUrl = "http://localhost:"+PORT+"/ciscospark/receive" sparkwebsocket = accessTokensparkwebsocket //////// Bot Kit ////// var Botkit = ; var controller = Botkit; var bot = controller; controller; controller; controller; controller;
Flint Example
Run the sample from a terminal:
> cd examples> cd flint> npm install> SPARK_TOKEN=XXXXXXXXXXXXXXXXX node bot.js...
Check the flint code sample:
// Spark Websocket Intializationvar SparkWebSocket = var accessToken = processenvSPARK_TOKENvar PORT = processenvPORT || 8080 var webHookUrl = "http://localhost:"+PORT+"/flint" sparkwebsocket = accessTokensparkwebsocket // Flint Bot Initialization var Flint = ;var webhook = ;var express = ;var bodyParser = ;var app = ;app; // flint optionsvar config = token: accessToken port: PORT removeWebhooksOnStart: true maxConcurrent: 5 minTime: 50; // init flintvar flint = config;flintstart; // say helloflint; // add flint event listenersflint; flint; // define express path for incoming webhooksapp; // start express servervar server = app; // gracefully shutdown (ctrl-c)process;
Proxy Support
Cisco Spark Websockets now support web proxies!
To enable web proxy support set the following enviroment variables:
- HTTP_PROXY=(to your web proxy URL)
- NO_PROXY=localhost