beerbot
v0.4.0
Published
BeerBot is an extensible and real time bot for Slack.com
Downloads
14
Readme
beerbot
Slack Beer Bot for Build Failures
A Slack bot which will listen to channels and will automatically reply with a custom message and a gif generated from giphy when message matches the given pattern.
Why?
Because the one which breaks the build have to bring beers for ALL the team!
So this is just to remind him with a message and a random beer gif:
The Beerbot was originally created for fun, to pollute Slack channels with funky gifs. But now, it can also be used to create integrations with Slack without having to consume official Slack integration limits.
Default Features
- Listen to CI build failures on a channel and send a random beer gif to a channel
- Create Hublin video conference: '@bot !hublin' will create a conference on Hubl.in with the current channel name.
Install
$ npm install --save beerbot
Usage
From configuration
var BeerBot = require('beerbot');
var token = 'xoxs-YOUR-TOKEN'; // check the slack API doc
// let's have beers when the build is broken, and let's celebrate when it is back!
var options = {
token: token,
silent: false,
logger: {
level: 'info'
},
plugins: [
{
name: 'beerbot-giphy',
listen_on: ['#jenkins'],
reply_on: '#general',
response: 'Build failure, let\'s have beer!',
match: /Failure after/,
term: 'beer'
}, {
name: 'beerbot-giphy',
listen_on: ['#jenkins'],
reply_on: '#general',
response: 'Yeah, build is back!',
match: /Back to normal after/,
term: 'celebrate'
}
]
};
var bot = new BeerBot(options);
bot.on('connected', function() {
console.log('Bot is started');
});
bot.on('error', function(err) {
console.error('Error while starting bot', err);
});
bot.start();
You can directly adapt and use ./bin/beerbot.js:
$ SLACK_TOKEN=xoxs-YOUR-TOKEN node bin/beerbot.js
From the BeerBot API
'use strict';
var BeerBot = require('beerbot');
var options = {
token: 'xoxp-YOUR-TOKEN', // check https://api.slack.com/web
silent: false,
logger: {
level: 'debug'
}
};
var yoloOptions = {
listen_on: ['#general'],
reply_on: '#general',
response: 'You said: '
};
var bot = new BeerBot(options);
bot.listen(/YOLO/, yoloOptions, function() {
return bot.q.resolve('YOLO');
});
bot.on('connected', function() {
console.log('Yolo Bot is started');
});
bot.on('error', function(err) {
console.error('Error while starting bot', err);
});
bot.start();
API
Beerbot
var bot = new BeerBot(options);
bot.request('http://www.google.com', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the Google homepage.
}
});
Default Listener
Options
- listen_on: Array of channels to listen on. Note that this will not subscribe to channels if the beerbot is not already in the defined channels. It is just a filter to process message on defined channels when received.
- reply_on: The channel to send back response to. If not defined, the response is sent to the channel on which the message is received.
- response: The prefix to add to the response generated by your message handler.
- match: The regular expression applied on the message or a function like function(message, bot) which must return a boolean. If the message matches the regex or if the function returns true, the message handler is called.
License
MIT © Christophe Hamerling