Join Slack4Developers
Install
npm install --save botkit
npm install --save botkitGet your Bot Online
The quickest and easiest way to get started talking with your bot.
var Botkit = require('botkit');
var controller = Botkit.slackbot();
var bot = controller.spawn({
token: my_slack_bot_token
})
bot.startRTM(function(err,bot,payload) {
if (err) {
throw new Error('Could not connect to Slack');
}
});
var Botkit = require('botkit');
var controller = Botkit.slackbot();
var bot = controller.spawn({
token: my_slack_bot_token
})
bot.startRTM(function(err,bot,payload) {
if (err) {
throw new Error('Could not connect to Slack');
}
});Basic Bot Commands
Try out basic commands, bot.hears() will allow your bot to listen for a key word and reply.
controller.hears(["keyword","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
// do something to respond to message
// all of the fields available in a normal Slack message object are available
// https://api.slack.com/events/message
bot.reply(message,'You used a keyword!');
});
controller.hears(["keyword","^pattern$"],["direct_message","direct_mention","mention","ambient"],function(bot,message) {
// do something to respond to message
// all of the fields available in a normal Slack message object are available
// https://api.slack.com/events/message
bot.reply(message,'You used a keyword!');
});