Building a Happy New Years Voice Broadcasting App
Time to read: 3 minutes
Over lunch today we were talking about how we wanted to make a Twilio Voice app to ring in the New Year, and I wanted to make it something really social where people would feel more connected to the entire world after using it. Ambitious? Yeah. Impossible? Nope. So I built a Twilio app. Here’s how it works…
TO TRY IT OUT*
*you will get a phone call around 11:30pm PST
Step 1 – Call In and Leave Your Message for the World
The first step is to set up the file to handle incoming calls to my Twilio number.
Creating incoming.php
-
<?xml version=“1.0” encoding=“UTF-8”?>
-
<Response>
-
<Say>Happy New Years from Twil ee oh! Record your News Years Eve wishes for the world after the beep, and press star when you are done.</Say>
-
<Record action=”new-recording.php” method=”POST” maxLength=”180″ finishOnKey=”*” />
-
</Response>
Step 2 – Gather the Recording URLs and Phone Numbers from Inbound Calls
The Twilio REST API makes it very simple to get a list of recordings by account SID using the Recordings Resource, so the next step is to gather up the recordings from incoming callers so we can put them all into a single TwiML file for the outbound call that will take place later tonight.
When you use the two URL examples below, an authentication window will pop up and you will need to use either your Twilio username and password or account SID and token.
Getting a List of Recordings
https://api.twilio.com/2008-08-01/Accounts/{Account SID}/Recordings?DateCreated=2009-12-31
Getting a Single Recording from the List
https://api.twilio.com/2008-08-01/Accounts/{Account SID}/Recordings/{Recording SID}
Creating new-recording.php
-
<?php
-
echo “<?xml version=“1.0“ encoding=“UTF-8“?>n“;
-
?>
-
<Response>
-
<Say>Thank you, your recording has been saved. You will receive a call at midnight tonight, where you will hear the New
-
Years wishes of the world. Have a wonderful two thousand ten, from everyone at twil ee oh.</Say>
-
</Response>
-
<?php
-
$phonenumbers = ‘phonenumbers.txt’;
-
$recordings = ‘allrecordings.txt’;
-
$caller_number = $_REQUEST[‘Caller’];
-
$recording_URL = $_REQUEST[‘RecordingUrl’];
-
/* Append the caller’s phone number to the list to call later */
-
/* Append the recording URL to the list of recordings to play during the call */
-
?>
Step 3 – Initiate a Massive Outbound Call with the REST API
Since
the phone lines are pretty jammed at midnight each New Years Eve, I’m
going to initiate the call at 11:30pm Pacific Time instead, mostly to
make sure people with cell phones will actually get it. The idea is
that every person who contributed to the massive New Years Eve message
will get to hear the entire thing.
I’ve got to get home before the traffic gets crazy, so I’m going to go ahead and post this and write the rest of the code when I get home. The last piece to add will enable me to initiate calls to all the people who have called in with the REST API.
In the meantime, you can learn about initiating calls with the Twilio REST API, or watch this video.
More Functionality… If I Have Time
I was thinking about how to add a truly “viral” feature to this, where each person who used it would be able to include more people in the experience.
What if the caller had the option to input a friend’s phone number, so that they would receive a call asking them to contribute their New Years wishes for 2010? How hard would that be?
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.