Skip to content

Instantly share code, notes, and snippets.

@Joffcom
Last active June 12, 2019 18:45
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
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