Journey

Journey

Translate

Monday, June 27, 2016

Cisco Spark Bot Integration

Creating a Cisco Spark integration can be interesting. Here is the sample code and i've added a few things to it. With this code you can add a person to the Cisco Spark room by email, remove a person by email and anytime someone says hello, the bot will say hello back by name.


Code as follows:

var Flint = require('node-flint');

// define flint setup
var config = {
  // url to access this app's webservice
  baseUrl: 'http://sparkbot-lperera3.c9users.io',
  // port that local server listens on
  localPort: process.env.PORT,
  // spark account email
  sparkEmail: 'lperera@la-networks.com',
  // spark api token
  sparkToken: 'MDA2ZDk1YTQtOWUzNy00ODA3LTk3MDYtMWE2MjJhZDg5ZjQ3NDRlN2RhNzAtNmVh'
};

// init flint framework
var flint = new Flint(config);


// echo test
flint.hears('/echo', function(bot, trigger) {
  bot.say(trigger.args.join(' '));
});

// add a person or people to room by email
flint.hears('/add', function(bot, trigger) {
  var email = trigger.args;
  if(email) bot.add(email);
});

// remove a person or people from room by email
flint.hears('/remove', function(bot, trigger) {
  var email = trigger.args;
  if(email) bot.remove(email);
});

// anytime someone says hello
flint.hears(/(^| )hello( |.|$)/i, function(bot, trigger) {
  bot.say('Hello, %s!', trigger.person.displayName);
});

No comments:

Post a Comment