This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function() { | |
"use strict"; | |
//rename file to config.js to implement project | |
exports.botToken = process.env.BOTTOKEN || "Your Spark access token"; | |
exports.watsonPassword = process.env.WASTSONPASSWORD || "Your IBM watson API password"; | |
exports.watsonUserName = process.env.WATSONUSERNAME || "Your IBM watson user code"; | |
exports.watsonWorkSpaceID = process.env.WATSONWORKSPACEID || "Work space ID created from conversation workspace"; | |
exports.cloud9URL = process.env.CLOUD9URL || "https://yourProject-username.c9users.io"; | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flint.hears(/\/broadcast( |.|$)/i, function(bot, trigger){ | |
var request = trigger.text.replace("/broadcast ",''); | |
if(trigger.personEmail.match(/youremail@example\.com|yourotheremail@example\.com/i)){ | |
_.forEach(flint.bots, function(bot) { bot.say(request); }); | |
}else{ | |
bot.say("Sorry but your are not authorised for this command. The authoritities have been notified."); | |
bot.dm('youremail@example.com','Unauthorised attempt by this person: '+trigger.personEmail); | |
} | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flint.hears('/roomid', function(bot, trigger) { | |
bot.say('This is your room ID', trigger.roomId); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flint.hears('/hello', function(bot, trigger) { | |
bot.say('Hello %s!', trigger.personDisplayName); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Welcome message when a new room or 1:1 is spawned with the bot | |
flint.on('spawn', function(bot) { | |
flint.debug('new bot spawned in room: %s', bot.room.id); | |
//presents different messages based on room or 1:1 | |
if(bot.isGroup){ | |
bot.say("Hi! To get started just type @examplebot hello."); | |
return | |
}else{ | |
bot.say("Hi! To get started just type hello."); | |
return |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//set bot to listen to incoming webhooks based on @mentions in group rooms | |
//or any text in a one on one room | |
flint.hears(/(^| )ExampleBot|.*( |.|$)/i, function(bot, trigger) { | |
var text = trigger.text; | |
//@ mention removed before further processing for group conversations. @symbol not passed in message | |
var request = text.replace("ExampleBot ",''); | |
//match method stops slash commands being passed to NLP | |
if(request.match(/(^| )\/hello|\/roomid|\/broadcast|\/find( |.|$)/i)){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
flint.hears('/roomid', function(bot, trigger){ | |
var roomId = trigger.roomId; | |
bot.say({markdown:'**Here are the current room settings: \n **'+ roomId,file:'http://filelocation.com/file.jpg'}); | |
}) | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//CISCOSPARK_ACCESS_TOKEN=<your token> DEBUG=* node server.js | |
var xmpp = require('simple-xmpp'), | |
http = require('http'), | |
ciscospark = require('ciscospark'), | |
assert = require('assert'), | |
fs = require('fs'), | |
path = require('path'), | |
logger = require('log4js'); | |
logger.configure({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var conversation = new ConversationV1({ | |
username: myconfig.watsonUserName, | |
password: myconfig.watsonPassword, | |
version_date: '2016-07-01' | |
}); | |
exports.watsonConversation = function(userContext, inputMessage, callback){ | |
//User context from either a new user or previsouly saved conversation | |
var params = { | |
context:userContext, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//mongojs implmentation | |
var mongodb = require('mongodb'); | |
var mongojs = require('mongojs'); | |
//Logging to file for troubleshooting | |
var fs = require('fs'); | |
var util = require('util'); | |
var log_file = fs.createWriteStream(__dirname + '/debug.log', {flags : 'w'}); | |
var log_stdout = process.stdout; | |
//debug logs to file for varying responses can be removed if not required | |
var mylog = function(d) { |
OlderNewer