Instantly share code, notes, and snippets.

@Joffcom /huebot.js
Last active Feb 22, 2017

Embed
What would you like to do?
Set Hue light to red for 2 seconds when certain words are mentioned in Slack
var Botkit = require('botkit');
var unirest = require('unirest');
var botToken = 'SLACK_BOT_TOKEN';
var hueBridge = 'IP_OF_HUE_BRIDGE';
var hueUser = 'HUE_USER_ID_FROM_BRIDGE';
var controller = Botkit.slackbot({
debug: false
});
controller.spawn({
token: botToken
}).startRTM(function(err) {
if (err) {
throw new Error(err);
}
});
controller.hears(['Jon', 'Jonathan', 'John'], ['ambient'], function(bot, message) {
// Sets light to Red
unirest.put('http://' + hueBridge + '/api/' + hueUser + '/lights/1/state').send('{"hue":65280}').end();
setTimeout(backToGreen, 2000);
});
function backToGreen(){
// Sets light to Green
unirest.put('http://' + hueBridge + '/api/' + hueUser + '/lights/1/state').send('{"hue":25500}').end();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment