Set Hue light to red for 2 seconds when certain words are mentioned in Slack
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 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