Skip to content

Instantly share code, notes, and snippets.

@Joffcom
Last active June 12, 2019 18:45
Show Gist options
  • Save Joffcom/ade0698c5b80d03aaa09d8f3f5cec514 to your computer and use it in GitHub Desktop.
Save Joffcom/ade0698c5b80d03aaa09d8f3f5cec514 to your computer and use it in GitHub Desktop.
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