| var chatskills = require('chatskills'); | |
| var SlackBot = require('slackbots'); | |
| var bot = new SlackBot({ token: 'your-slack-token', name: 'awesome' }); | |
| // Set bot name. | |
| chatskills.name('awesome'); | |
| // Create a new skill. | |
| var hello = chatskills.add('hello'); | |
| // Create a new intent. | |
| hello.intent('helloWorld', { | |
| 'slots': {}, | |
| 'utterances': [ '{to |}{say|speak|tell me} {hi|hello|howdy|hi there|hiya|hi ya|hey|hay|heya}' ] | |
| }, | |
| function(req, res) { | |
| res.say('Hello, World!'); | |
| } | |
| ); | |
| // Listen to slack messages. | |
| bot.on('message', function(message) { | |
| // Reply to humans. | |
| if (message.type == 'message' && message.text && message.subtype != 'bot_message') { | |
| var author = getUserById(message.user); | |
| var channel = getChannelById(message.channel); | |
| // Respond to input, use author.name as the session id. | |
| chatskills.respond(message.text, author.name, function(response) { | |
| if (channel) { | |
| // Public channel message. | |
| bot.postMessageToChannel(channel.name, response); | |
| } | |
| else { | |
| // Private message. | |
| bot.postMessageToUser(author.name, response); | |
| } | |
| }); | |
| } | |
| }); | |
| function getUserById(id) { | |
| return bot.users.filter(function (user) { | |
| return user.id == id; | |
| })[0]; | |
| } | |
| function getChannelById(id) { | |
| return bot.channels.filter(function (channel) { | |
| return channel.id == id; | |
| })[0]; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
