Friday, June 29, 2018

SMS over IRC

A couple years ago, I moved from Google Voice to custom infrastructure.  That system used XMPP to send SMS.  Now that I've moved from XMPP to IRC, I needed a new set up for sending SMS.  This post is about a small proxy I wrote to translate between SMS and IRC protocols.

When I'm connected to our family IRC server, I can send a message to any nick that's a valid phone number.  The server converts that message into an HTTP request to Twilio to send an SMS to that number.  I map our IRC nicks to our phone numbers to correctly set outgoing caller ID.

Some of my extended family (mom, dad, siblings, etc.) aren't connected to our IRC server.  I contact them frequently enough that I didn't want to use their phone numbers in IRC, so I've given them aliases.  The server pretends that they're on IRC under those aliases.  For instance, when I send a privmsg to the IRC nick "mom", it converts that into a Twilio API call that sends an SMS to my mom's phone number.  As far as my IRC clients are concerned, my mom is on IRC.

When sending SMS, Twilio provides helpful status updates via HTTP.  I've translated some of those into IRC messages too.  In an IRC client, it looks like this:

[12:01:02] michael: Any big plans for your birthday?
[12:01:03] mom: ⌛
[12:01:07] mom: ✓
[12:05:22] mom: I'm going to Cirque du Soleil with some friends


The first two emoji are synthetic messages generated by the IRC server.  ⌛ means, "Twilio has successfully delivered the message to the recipient's phone company" and ✓ means, "the phone company delivered the message to the recipient's phone".

Incoming SMS work as you'd expect.  The phone number to which the SMS was sent, determines which IRC user receives the corresponding privmsg.  If the phone number has an alias, that alias is used as the IRC nick; otherwise, the phone number is used as the nick.

It all works really well in practice.  I can pretty much pretend that everyone I care about is on IRC all the time.

Twilio doesn't support group SMS, which is too bad.  I'd love to translate those into ad-hoc IRC channels.  Twilio supports MMS, but I receive them so rarely that I haven't added IRC support yet.

The code is available, in case you're interested.  It's a couple hundred lines of Go.

Thursday, June 28, 2018

Dadurday

As my five kids have gotten older, I've noticed the world and its activities encroaching more and more on our family time.  While we were traveling in Europe, we changed cities every two weeks and had no outside obligations, so our family spent lots of time together.  It was great.  Our friendships strengthened and we grew closer.

As we prepared to return home, my wife and I decided that we would establish the first and third Saturdays of each month as "Dadurday".  A day when the kids and I would block everything else out and just spend time together: no chores, no outside obligations.  So far we've watched a movie, played board games, read stories, watched the World Cup, collected coal to try to start a fire, had sword fights, and gone on walking adventures.  The kids seem excited about the whole thing and are constantly suggesting activities for the next Dadurday.

The outside has tried to occupy these days, as we suspected it would.  I suppose it's a corollary to Parkinson's Law that non-family activities expand to fill all available time.  Fortunately, Dadurday was on the calendar first.  When other activities try to crowd in, we politely decline and say that we have a previous obligation.  Just knowing that these unstructured, playful days with my kids are waiting for me every couple weeks makes me smile.

Of course, my kids have friends and other interests.  Most of the time they can be scheduled away from Dadurday, but sometimes there's a conflict.  As a family, we decided that each kid gets 3 exemptions per year that let them skip Dadurday if they want to do something else that day.  So far three kids have spent four exemptions total, all to attend birthday parties.

Between Dadurday and our family night on Mondays, I suppose that some people would think it's too much time together, but it's a great balance for us.

Tuesday, June 12, 2018

Goodbye XMPP. Hello IRC

Up until 2 years ago, my wife and kids and I stayed in touch with Google Hangouts.  I disliked being dependent on a third party, being unable to program the system to match our needs, and not having access to it on all the devices we care about, so we switched to XMPP.  It was an improvement and has served us well for the last couple years.

A couple months ago, we started seeing large delays in message delivery times.  We were also getting extended, repeated disconnects from the XMPP server.  Our messaging stack is selfhosted and open source, so I prepared for a debugging session.  As I got ready to dive in, I had a nagging feeling that there was way too much code at play here.  We ran Prosody, which is a great XMPP server, but it's 35k lines of code.  My SMS to XMPP gateway adds another 1k.  All we wanted to do was send small pieces of text between 7 people and set up some chat rooms.  That much code felt like overkill.

After a few hours work and 500 lines of Go, I had a custom IRC server with a built in BNC.  With another 200 lines, I had a working SMS to IRC gateway, so I can send and receive SMS from my IRC clients.  Obviously, setting up chat rooms was painless.

We had some minor glitches during initial deployment, but because the whole system is so small, it was a cinch to debug and repair.  It's been really solid since then.  The minimalism is refreshing.

The code is available in case you're interested. It won't compile by itself since it's part of a larger family server (git, movies, personal assistant, Asterisk dialplan, etc).