Wednesday, 23 April 2008

RickRolling the Phone Network at Web 2.0 Expo

I built a little demo for Web 2.0 that rick rolls the phone network. If you haven't come across rickrolling, the basic concept came about when people started getting sent links to the below Rick Astley video


Most annoying. Some of the implementations refused to let you close the browser window as well.

Well, I thought that for the Web 2.0 Expo I'd do that to the phone network, and try and get folk to rickroll each other. So in a midnight-through 3am coding session, I came up with a cool app.

If I haven't taken it down yet (that'll happen on Friday 25th April) you can try it.

Just send an SMS with the word "rick" to +447800000320

If it's still working you'll get called back - press a key, and then you'll get the dulcet tones of Rick Astley crooning at you across the phone network.

So, how did I build this?

Using, of course, the fabulous Web21C services from BT, and CallFlow in particular.

I used a YouTube downloader to pull the Video down, and extract an mp3 file from the flv file. Then used Sony Acid Pro 6 to edit it and convert it to a suitable format (open source products such as Audacity may be used!).

I uploaded to the CallFlow platform the resulting wav file, rick.wav, and another one, press.wav. They need to be there so that they can be played back to the poor victim over the phone line.

Then I got hold of an Inbound SMS (Mobile Originated) number from my colleagues; if you want to use this service you have to register, and order a number through the web site. But once you've got it, implementing the rest of the code is dead easy, and will run off your laptop!

Wanna see some of the code? Here's some of the highlights. Written in C#, as a console app; BT has SDKs for Python, PHP, and Java too.

1. Retrieve messages and clear them down from the BT servers

Collection<Message> messages = smsIn.GetReceivedMessages();
Collection<string> mIds = new Collection<string>();

foreach (Message m in messages)
{
RickRoll(m.MessageText, m.SenderUri);
mIds.Add(m.MessageId);
}
if (mIds.Count > 0) smsIn.ClearReceivedMessages(mIds);

2. The highlights of the RickRoll function, creating some XML for placing the call.


//create the callflow XML
StringBuilder sb = new StringBuilder();
sb.Append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
sb.Append("<callflow xmlns=\"http://sdk.bt.com/callflow/2007/04\">");
sb.Append(String.Format("<call id=\"start\" target=\"{0}\" next=\"check\" />", roll.Target));
sb.Append("<prompt id=\"check\" audio=\"press.wav\" barge=\"true\" firstDigitTimeout=\"30\">");
sb.Append("<input pattern=\"0\" next=\"prank\"/>");
sb.Append("<input pattern=\"1\" next=\"prank\"/>");
sb.Append("<input pattern=\"2\" next=\"prank\"/>");
sb.Append("<input pattern=\"3\" next=\"prank\"/>");
sb.Append("<input pattern=\"4\" next=\"prank\"/>");
sb.Append("<input pattern=\"5\" next=\"prank\"/>");
sb.Append("<input pattern=\"6\" next=\"prank\"/>");
sb.Append("<input pattern=\"7\" next=\"prank\"/>");
sb.Append("<input pattern=\"8\" next=\"prank\"/>");
sb.Append("<input pattern=\"0\" next=\"prank\"/>");
sb.Append("<input pattern=\"#\" next=\"prank\"/>");
sb.Append("<default next=\"unprank\"/>");
sb.Append("</prompt>");
sb.Append(String.Format("<announcement id=\"prank\" audio=\"{0}.wav\" />",roll.Prank));
sb.Append("<hangup id=\"unprank\" />");
sb.Append("</callflow>");


//Call BT's Callflow Service and place the call
roll.CallFlowId= callFlow.StartCallFlow(sb.ToString());

There really isn't very much more to the code - a bit that monitors each callflow to check that the phone was answered - the script does a "Press 1 if you're not an answerphone" check


The entire code is downloadable here - you won't be able to run it straight of the bat, because of it's reliance on an inbound SMS number tied to my account, and certs referenced in a config file - get your own from BT - but it may be interesting to read.

No comments:

Tim Stevens

Tim Stevens
Work
Consume
Obey
Be Silent
Die