/ guest posts

Building a Phone Robot

A phone robot? Who needs a phone robot? What even is a phone robot, and what on earth could Young Mensa North be doing with one? And how could such a thing be built?

Encouragement

If you've spent any time around Mensa circles, or ever read a Mensa-organised schedule of events, no doubt you'll have found a curious phrase repeated over and over in meeting descriptions. At the end of any advertisement for a chat in the pub, there's almost always a phone number and an offer to "text or call for directions or encouragement". This captures the imagination - what sort of words of encouragement are to be given? Are there hordes of introverts just waiting to go to these events, and the only thing barring them is a lack of encouraging words - which they could obtain by, paradoxically, overcoming their introversion through the process of calling a stranger to ask for encouragement?

Well, empirical evidence has shown that actually, a great number of individuals find a nice solid phone number to interact with to be a good anchor, and basis for their attendance at an event. Far be it from me to question group psychology; I just pander to what is placed in front of me. So here's where PHONEBOT2000 comes in.

The Problem

The problem specification: At the end of every event post on this blog, every email, on every facebook event and so on, it would be really nice to drop a phone number - one that can receive text messages or deal with phonecalls, a way to direct Mensans who, despite their galaxy-sized brains, are having difficulty with basic directions or cannot manage to operate Google Maps to find their way to the pub venue of the evening. Or, even more challengingly, who require a few positive words of "encouragement" to bring them along. And we want to offer these words of encouragement, we want to cater to these quirks - and after all, who hasn't every now and again gone to the wrong "Black Bull" on a Saturday night when there are three in town? Thus, so far so good.

But here's the issue... if one of the organisers were to post their personal and private mobile number in these very public fora, it can be problematic. This number would be archived forever in the history of the internet, in inboxes and so on, and receive calls years after the organiser is no longer involved - or even in country. Worse, some tenacious corner-case "young at heart" members may choose to pass through the invisible cordon of societal nicety and use the number in great impropriety to hit on the nubile young organiser. And all of this is quite aside from the very fundamental problem of automated robot spam to any number that's visible on google - PPI insurance texts up the wazoo. So how do we solve this?

The Solution

It's simple. We want to have a phone number that is shared for the group, that can deal with both texts and phonecalls, but in a non-exclusive manner. Something that can answer the phone when all organisers are asleep or passed out drunk. Something that can broadcast a text to all organisers and yet not solicit multiple replies because nobody knows the others have already replied. In short, we needed... AN ARTIFICIALLY INTELLIGENT ROBOT.

Birth of a Bot

Young Mensa North's instant messaging system of choice is Telegram. It's beyond the scope of this article to justify why, but suffice to say, if you're still using Facebook Messenger - or even worse, Facebook's subsidiary Whatsapp - then you either really don't care about the future of the internet and your own privacy, or you just haven't done your research on how terrible those things really are. So, let's skip over that - Telegram is our basis, and Telegram supports an excellent bot ecosystem. The logical first step was to connect an SMS gateway to a Telegram group. Read on.

Sending to Telegram

First I built a general purpose Telegram bot - a bot is a lot like a virtual human in group chats, but by default cannot see messages (privacy privacy privacy!). We interface with Telegram by registering a web hook with them to which it delivers pending requests. We send generic messages - it could be anything - from our Linux-based server hosted in a German data centre, to an invite-only Telegram group dedicated to receiving these messages. The core organisers of Young Mensa North events at any given time are present in this group, and receive an instant notification - on their computers or their mobile phones - whenever anything is posted here. Next, we need something to send.

What's in a Number

We decided to go with Twilio, a web API providing various telephony services at a not entirely unreasonable price. We bought a phone number. We wanted it to be memorable, but anything that spelt "MENSA" in DTMF codes was of course taken. We settled on:

0144 360 6367

360 degrees in a circle, and 6367 is what you get when you type MENS on a phone keypad. Write that down in your copybooks now.

For those of you who prefer to store their UK phone numbers in an international format, of course that would be +441443606367.

It's all well and good having a number, but what can you do with it?

SMS to Telegram

First and easiest is passing on SMS messages. I wrote a Twilio compatible service as a webhook that would accept connections from Twilio whenever someone sent a text message to the number. It would then take the following steps:

  1. Look up the sender's ID in our caller ID database of all Mensans in the North, and if there, get their first name. We're on first name terms, you see.
  2. Immediately send a telegram message to the private telegram group, containing:
  • The full text of the sender's message
  • Their phone number (so one of the organisers can reply)
  • And their first name (so we'll be aware if it's someone we know - and offer the personal touch)

Because the data comes to a group chat, the organisers can immediately discuss the incoming message - whether it's a request for the location of an ongoing event, a request for "encouragement", or a general message of congratulations for being the most awesome Mensa chapter in the world. We can then decide quickly who fields it, and someone will say "I got this" - preventing multiple replies to a single recipient, while letting our texter deal with a real human on a one-to-one basis from that point on, rather than continuing a conversation with a faceless robot.

Texting is great, but what if someone wants to do the old-fashioned thing and call?

Phonecalls to Telegram

You're running late to an event, the bus broke down, your phone contract's got no internet bandwidth left, and you forgot to look up how to get to the pub before you went out of the door. You don't want to faff about on Google Maps, you don't want to ask strangers for directions. You just want to press a button dial a number, and ask how the hell you get to this place where everyone else is already drinking.

Traditionally you'd call the organiser, but in the 21st century of digital everything and fewer personal connections, you've got the Young Mensa North Robot Hotline instead. What happens now?

No worries! The robot greets you in friendly tone, it recognises you if you've called before, it can tell you about the organisation, it can talk to you about the next queued event, it can take messages to pass to the organisers - instantly - and it can even offer automated robot encouragement! How is this possible? Read on!

Ghost to Telephone

We self-host this blog on our own hardware, using the open source Ghost platform. On this blog, we use tags to organise different types of posts; all of our events posts are thusly tagged.

When you dial and press the selection button (2 at the time of writing) to ask the phone robot about the latest event, at that moment it performs a query directly against the sqlite3 database of the ghost server, filtering blog posts for those tagged with the "events" tag, and sorting them by publication date; it reads out the title of the latest one for the caller, using automated voice synthesis.

If the caller then requests the full text of the blog post, we pull the html out of the database for that post, and run it through the html2text utility to obtain a plain text parse of the data. We finally pass it through a regex to filter out any special characters that may remain, such as asterisks around titles. We do this while being careful to keep that punctuation which would aid the text-to-speech system, by offering clues to the correct pronunciation of sentences.

This lets people call the number and get a verbal description of the event, as well as our own directions to it - a handy service, and one that allows hands-free and eyes-on-the-road navigation for drivers.

Automated Encouragement

The robot is also equipped with a database of cheesy inspirational quotations; when a caller presses the button to ask for encouragement, it selects three quotes at random from this database and reads them out to the caller, using voice synthesis, hopefully either giving them the carpe-diem style boost they need to get their indecisive backside on the way to the latest event - or making them laugh with the sheer tackiness of it all. A menu option at the encouragement stage allows them to quickly request further encouragement as they see fit.

Leaving voice messages

The robot, at the time of writing, listens very attentively (if somewhat patronisingly) if you wish to leave a voice message, but does not currently carry it on to anyone else.

Future work in this area will be to accept voice messages which the system will then record, and pass through a speech recognition system - possibly Sphynx developed at the University of Edinburgh, or some derivative system, or perhaps some online speech recognition processing API - subject to testing what works out best. This will then allow us to post the text of the message to Telegram immediately after it is left, as well as offering an mp3 file of the audio recording to the organisers for further listening in case the system fails to understand someone's pecularly Scottish accent.

Realtime Telegram Monitoring

Throughout the whole process, the Telegram bot reports the current status of each ongoing call in its private channel; Upon answering, it tells us who is calling and how many times they've called before - if it recognises the number against our regional member database, it reports their first name as well as their phone number. It also reports and logs every menu option the caller selects, as they select them, so we can keep track of which services are in demand and discover any problems - as well as gauge interest in specific data the system has to offer.

Telegram to SMS and Voice

One future development I would like to explore would be adding a feature to the telegram bot to send an SMS message reply directly back to someone who has sent us a message, straight from Telegram. We could accomplish this again using our Twilio system (although this is more costly than most mobile phone contracts, which is why we are currently preferring to have the organisers reply manually).

Another similar feature could be an automated call-back bot; it could return a voice call to the caller, using the text to speech synthesis system, to deliver by voice a message that has been typed by one of the organisers in Telegram as a reply - making it possible for organisers to reply quickly to a caller without having to interrupt their real-life conversation in the pub, or upsetting passengers in the quiet carriage of a train.

Try it out

The possibilities are indeed numerous - and we need your feedback!

So give the system a try - add 0144 360 6367 to your contacts and give it a call (standard UK landline rates, free on most mobile contracts) - and let us know what you think!

Text us your comments and any encouragement of your own. We'd love to hear from you, and we can't wait to see the system put through its paces.

Eugene Hopkinson

Eugene Hopkinson

Director of the VoxelStorm indie gamedev studio, C++ programmer, photographer, alumnus of philosophy at University of Edinburgh, regular at Young Mensa North pub events.

Read More
Building a Phone Robot
Share this