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.
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.
A BeerBot CLI is available on chamerling/beerbot-cli so you can install and directly use it.
$ npm install --save beerbot
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 of the beerbot plugin as npm module
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();
'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(response) {
return response.sendText('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();
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.
}
});
- 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 prepend to the response sent 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.
MIT © Christophe Hamerling