Image of the glider from the Game of Life by John Conway
Skip to content

IRC Notifications Over SMS

Recently, I pinged my boss about a networking question, and got the following response:

I am away but your message is being sent to my phone.

Well, there are a few things he could be doing here:

  1. Logged in 24/7 with a local IRC client on his phone. Easiest, but will drain his battery quickly.
  2. Using an IRC script to send away messages to email. Pull notifications could be slow.
  3. Using an IRC script to send away messages to SMS. Snappy push notifications.

I've done both #1 and #2, but have never attempted #3, so I thought I'd give it a go. That way, the alert would be the most responsive, and I could login to IRC with a local client on my phone to address the issue, if it's important enough.

Now, to be clear, I'm not using Irssi. This may come as a shock to many of you, but last April, I discovered ZNC and WeeChat, and I haven't looked back. I REALLY like this setup. So, that means no more Irssi posts for this blog. It's time for WeeChat posts. Hopefully, I can do as good of a job. Further, this post addresses a script that must be running in WeeChat, not ZNC.

First, install in WeeChat. If running Debian/Ubuntu, this will mean installing the "built-essential", "ruby1.8" and "ruby1.8-dev" packages, then running "gem install zmq" to get the 0mq Ruby modules installed. Then restart WeeChat (yes, this is necessary- trust me) and load the script, and you should be good to go. If not, troubleshoot.

Now, the script sends YAML through the 0mq socket. Unfortunately, the YAML is not syntactically correct, and it's delivering base64-encoded binary. Meh. We can handle that. So, we need to connect to the 0mq socket that the script sets up, parse the YAML, then send the message as an email to an email-to-sms gateway. If you have a mobile phone, then the major phone providers have likely already set this up for you: See for a fairly comprehensive list.

So, what does the script look like?

UPDATE: I created a Github project:


import base64
import email.utils
import re
import smtplib
import yaml
import zmq
from email.mime.text import MIMEText

context = zmq.Context()
socket = context.socket(zmq.SUB)
socket.setsockopt(zmq.SUBSCRIBE, '')

while True:
    f = open('/var/log/0mq.log','a')
    msg = socket.recv()
    msg = re.sub('\n:', '\n', msg)
    msg = re.sub('^---| !binary \|-\n','',msg)
    y = yaml.load(msg)


    # Ignore client events that aren't PUBLIC
    if not y['tags']:

    server = base64.b64decode(y['server'])
    channel = base64.b64decode(y['channel'])
    nick = base64.b64decode(y['tags'][3])
    nick = re.sub('^nick_','',nick)
    message = base64.b64decode(y['message'])

    # If sending messages to the channel while away, it shows up as
    # "prefix_nick_white". This can change it to your nick.
    if nick == 'prefix_nick_white':
        nick = 'eightyeight'

    # Change your email-to-sms address as provided by your mobile provider
    fromaddr = ''
    toaddr = ''
    msg = MIMEText("{0}/{1}: <{2}> {3}".format(server, channel, nick, message))
    msg['To'] = email.utils.formataddr(('eightyeight', toaddr))
    msg['From'] = email.utils.formataddr(('WeeChat', fromaddr))

    s = smtplib.SMTP('localhost')
    s.sendmail(fromaddr, [toaddr], msg.as_string())

Place the code in your /etc/rc.local, or create a valid init script for it, and you're ready to go. Next time you set your status to away on IRC, you'll get an SMS alert every time someone highlights you in an IRC channel, or your receive a private message. If you're running WeeChat behind a terminal multiplexor, like GNU Screen or tmux, then you could also install an away script that sets your status away automatically when you detach from your session. Of course, if WeeChat disconnects from your bouncer, then this won't do much good for you.

Here is an example of an SMS alert from a private message from a bot: said:
Subject: IRC Notification
21:59:34 freenode/ibot: <ibot> for heaven's sake, eightyeight, don't do that!

There are some outstanding bugs, and I'm working them out. In the meantime, if this interests you, then it should get you started with basic functionality. Happy IRC over SMS!

{ 8 } Comments

  1. Jason using WebKit 534.46 on Mac OS | August 29, 2012 at 10:28 am | Permalink

    SMS seems silly to use here. I use a script for irssi that send me notifications of highlights and privmsgs via Prowl.

    My point is simply that "C2D" ("cloud-to-device") messaging solutions exist that should be a ton easier to work with than SMS and the ridiculous fees associated with them.

  2. Jason using WebKit 534.46 on Mac OS | August 29, 2012 at 10:30 am | Permalink

    I guess the fees argument stands, not that SMS via e-mail is particularily difficult.

  3. Serge using Firefox 15.0 on Ubuntu 64 bits | August 29, 2012 at 2:52 pm | Permalink

    In the past I've sent PMs to my google chats, which I received on my phone (or my desktop, of course). I had scripts to do this from znc, ii, and sic. Finally (after about a year?) got back to not wanting interruptions :) Prefer to make use of 'lastlog' in irssi. Still it's fun to play with isn't it :)

  4. Nils-Anders N√łttsete using Google Chrome 18.0.1025.168 on GNU/Linux 64 bits | August 30, 2012 at 1:21 am | Permalink

    I've recently discovered which is an android-centric C2D like what Jason talks about. No more SMS, just notifications with nice icons, severity levels etc.

  5. Aaron Toponce using Google Chrome 21.0.1180.75 on GNU/Linux 64 bits | August 31, 2012 at 10:46 am | Permalink

    Jason- I can understand the arguments against SMS and their ridculous fees. However, the major advantage here, is that you don't need an application running on your phone, on a data connection, draining your battery. Further, it's entirely operating system agnostic. And, if you have a plan like mine with unlimited text, then it's a non-issue.

    Serge- Yeah, I can understand that. I'm certainly playing with it, so we'll see how things go. I may end up disabling it, or installing filters client-side to prevent certain pushes.

    Nils-Anders N√łttsete- I have nice icons with my SMS app. Not sure which one you're using. :)

  6. Aaron Toponce using Google Chrome 21.0.1180.75 on GNU/Linux 64 bits | September 1, 2012 at 5:45 am | Permalink

    (Of course, it's also worth mentioning this script is free.)

  7. chovy using Google Chrome 38.0.2125.111 on Mac OS | November 6, 2014 at 2:03 pm | Permalink

    Can you provide instructions on how to install the script?

    I'm new to weechat.

  8. Aaron Toponce using Debian IceWeasel 31.3.0 on GNU/Linux 64 bits | December 9, 2014 at 10:48 am | Permalink

    The post describes it fairly clearly, and even links to a Github project that also describes how to get this working in detail. What are you stuck on?

Post a Comment

Your email is never published nor shared.