Created
January 16, 2018 16:02
-
-
Save nybblr/ed70198112ce46689e2737749c78158e to your computer and use it in GitHub Desktop.
Should you wear slacks, or should you wear shorts? This Slackbot will help you decide.
This file contains hidden or 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
const SlackBot = require('slackbots'); | |
const BOT_NAME = 'Slacks or Shorts'; | |
const BOT_TOKEN = '<YOUR-TOKEN-HERE>'; | |
const BOT_HANDLE = 'slacks-or-shorts'; | |
let bot = new SlackBot({ | |
token: BOT_TOKEN, | |
name: BOT_NAME | |
}); | |
bot.on('start', () => { | |
console.log("I'm in!"); | |
bot.on('message', data => { | |
console.log(data); | |
let say = (channel, text) => { | |
bot.postMessage(channel, text, { icon_emoji: ':jeans:' }); | |
} | |
if (data.type === 'group_joined') { | |
let channel = data.channel.id; | |
say(channel, "Hello! I'm here to answer all your fashion questions."); | |
} | |
if (data.type === 'message' && | |
data.text != null && | |
data.username !== BOT_NAME) { | |
switch (data.text) { | |
case 'What should I wear?': | |
say(data.channel, "Today's forecast calls for a slight chance of business casual, I recommend a nice pair of jeans."); | |
return; | |
break; | |
case 'What should I wear tomorrow?': | |
say(data.channel, "Just make sure they're clothes."); | |
return; | |
break; | |
} | |
if (/wear/i.test(data.text)) { | |
say(data.channel, "Need some fashion advice? Just ask me!"); | |
} | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment