As part of my Slack evangelism I’ve been hellbent on trying to integrate as many products I/we use into the aforementioned tool, to test out where the limit is on what this awesome product can do. Next on my list of things is IRC – that old warhorse. Opsview has a large number of users on IRC, yet I continually forget to start my IRC client after reboots, etc meaning i miss out on all the useful questions, comments and other items that our community have to offer.

Therefore, it sounds like a perfect technology to stream into Slack; 24/7 coverage of ANY IRC room – pretty cool, huh?

Background

To find the right integration, I scoured the internet and tested a few different solutions. Some where just OVERLY complex, some just didnt work, and some were just right (Codename Goldilocks). The one that I found worked perfectly for me was ‘slack-irc-plugin‘, by Jimmy Hillis. To install any of the IRC bots, it turns out you need ‘node’ installed on your server. But lets back-up – how does this actually works?

Basically, you need something that is always-0n, which the irc-bot can run on. This bot connects to the IRC channel(s) and monitors what is going on, s that when something changes like someone posting a new message, the bot notices this and sends the information to Slack using the given parameters.  Essentially, you need the following setup:

 

The IRC Bot runs on your server/PC, and updates Slack whenever anything happens. So, how do we install it?

Installation 

This bot, and the others I tested, all run on node which is interesting, as i’ve never had the pleasure of using node before. After some testing, it turns out that the version of node that some OS’s have in their repositories (like Ubuntu) doesnt work, so in my installation instructions I will give you the correct repo to use.

Firstly, lets add that repo:

sudo apt-get install -y python-software-properties
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs

Next,  clone the slack-irc-plugin from git:

cd /the/directory/you/want/this/to/run/in
git clone https://github.com/jimmyhillis/slack-irc-plugin

Of course, change the directory above – DONT blindly copy and paste. Next, go into that new directory and lets build the tool:

cd ~/slack-irc-plugin/
npm install

This npm command is inherited from node. There will be some output now, as node downloads the actual components of the bot (listed in the node_modules dir) and installs them. After this completes, lets copy the config file and then edit it:

cp config-example.js config.js
nano config.js

In here, we will need to edit the following:

var slackbot = require('./lib/bot');

var config = {
server: 'chat.freenode.net',
nick: 'irclistener007',
username: 'mirclistener731',
token: 'slack-token-here',
channels: {
'#opsview': '#irc'
},
users: {
'~myIRCusername': 'myslack.username'
},
// optionals
silent: true
};

var slackbot = new slackbot.Bot(config);
slackbot.listen();

Let me explain the above:

Server = This is the IRC server you are going to connect to, i.e. Freenode is chat.freenode.net.

Nick = This is the name you want the bot to show as in the channels it joins.

Username = The bots actual username.

Token = You will need to create a new INCOMING WEBHOOK via https://yourorganisation.slack.com/services/new – which will give you a token as a result, i.e.:

Next, we have Channels: This is where you bind which channels you want to watch in IRC, and where that chat is dumped to, so i’m monitoring the #opsview room in IRC, and I want to mirror it into an #irc channel in Slack.

Users: This tripped me up for a WHILE, but this is where you bind IRC users to their slack usernames. This is very finicky, but you need to include the tilde, i.e. ~ircuser, and you need to ensure that it is the same username as what is shown when you do an ‘/whois ircuser’. Your slack username is shown on your account, if you dont know it:

Finally, you really want to set ‘silent’ to true, otherwise the bot randomly starts blabbering into the channel which is pretty embarrassing, as i found out.

NOTE: This is all you need to get it working, as per the instructions, but i found that when i was running this (3rd Sept 2014) my bot was constantly joining/leaving the channel. I found out it was being kicked due to ‘Flooding’, even though it was posting no messages. After digging around in the API of the actual bot module, (link here if your bored), I had to edit the following file and line:

nano slack-irc-plugin/node_modules/irc/irc.js
...  
floodProtection: true,
...

Doing this solved all my problems (well, IRC ones at least…). Finally, lets start her up:

[email protected]:~/slack-irc-plugin# node config.js
(node) warning: possible EventEmitter memory leak detected. 11 listeners added. Use emitter.setMaxListeners() to increase limit.
Trace
at Client.addListener (events.js:160:15)
at Client.whois (/root/slack-irc-plugin/node_modules/irc/lib/irc.js:854:14)
at /root/slack-irc-plugin/lib/bot.js:56:25
at Array.forEach (native)
at Client.<anonymous> (/root/slack-irc-plugin/lib/bot.js:55:28)
at Client.emit (events.js:98:17)
at Client.<anonymous> (/root/slack-irc-plugin/node_modules/irc/lib/irc.js:320:26)
at Client.emit (events.js:95:17)
at /root/slack-irc-plugin/node_modules/irc/lib/irc.js:669:22
at Array.forEach (native)

 

I have no idea what any of that means, but i’ve fed it back to the developer as they might have more of an insight! But thats it, your bot is now configured and is sending data back to your Slack room when items are entered into IRC:

Pretty fancy eh? Now, go forth and Slack!