Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (39 sloc) 1.57 KB
// Include required modules.
var Botkit = require('Botkit');
var accela = require('accela-construct');
var config = require('./config');
// Set up an Accela iobject.
accela.setup(config);
// Fire up your bot.
var debug = process.env.debug || false
var controller = Botkit.slackbot({ debug: debug });
var bot = controller.spawn({ token:process.env.token }).startRTM();
// An empty variable to hold the repsonse to the user.
var reply;
// Identify the bot.
controller.hears(['hello','hi', 'sup'],'direct_message,direct_mention,mention',function(bot,message) {
bot.reply(message, ":robot_face: I am a bot named <@" + bot.identity.name + ">. I am here to serve.");
});
// Send help.
controller.hears(['help'],'direct_message,direct_mention,mention',function(bot,message) {
bot.reply(message, "Find out the status of a record by sending: ```status [record id]``` I will provide the current status if the record has one");
});
// Look up record status.
controller.hears(['status (.*)'],'direct_mention,mention',function (bot, message) {
var matches = message.text.match(/status (.*)/i);
var record_id = matches[1];
accela.records.getRecords({id: record_id}, function (error, response) {
if(!error) {
if(response.result[0].status) {
reply = "Current status of record " + record_id + ": " + response.result[0].status.text + ". :hammer_and_wrench:";
}
else {
reply = "I could not find a status for record " + record_id + ". :cry:";
}
bot.reply(message, reply);
}
else {
bot.reply(message, "Sorry, I could not look up the status for that record. :thumbsdown:" );
}
});
});