Make Your Own Music Hotline in PHP or Python
Time to read: 3 minutes
Hot off the heels of the Callin’ Oates soulful emergency music hotline, developers started creating their own music
One of our Developer Evangelists, Rob Spectre, ported Callin’ Oates over to Python, though along the way Hall and Oates got a little more punk rock at 676-606-2607. See Rob’s code, environment setup documentation and code comments on his GitHub project.
Below the developers of Callin’ Oates, Michael Selvidge and Reid Butler, share their ‘how to’ and sample code to build your own music hotline in PHP.
Full version originally posted on Reid’s new (Twilio-unaffiliated) blog Exploring Twilio.
Callin’ Oates: How We Did It
The first is the file used to greet the caller and present the audio options. After a little trial and error, here is the properly formatted file that we created (based on TwiML):
As seen in that file, Twilio’s basic language makes it simple to create the voice menu for the users. The key to that file is telling the app what to do with the response once the user presses a key on their phone. We need to tell the app where to send the user-entered data and what to do with it, so we created handle-user-input.php.
Next Step, use <Play>
Next, we turn our focus to the handle-user-input.php. This php script would be the core of our app and respond to the digit pressed by the user and execute accordingly. Replace the bits below to reference the full URL of your own personal audio files that you want to have played based on the user’s selection. We did this with Hall and Oates songs–and they turned out to be really cool about it. No guarantees if you want to make a Metallica phone line (*cough* Napster).
<
Once executed, the code above will create a properly formatted response for the Twilio server to process. With these two files, you can easily create an interactive voice system to do any of the following:
- Play a song/file based on user selection (as seen above)
- Change the <Play> verb to <Say> and read a message to the user.
- Add Twilio credentials to the script and change the <Play> verb to <sms> and send a text message.
- Add Twilio credentials to the script and change the <Play> verb to <dial> and call another number.
Reid Butler works in San Francisco at a digital media company as a Sr. Product Development Manager. Leveraging some long forgotten scripting experience from previous gigs, he helped create Callin’ Oates over a weekend with pal Michael Selvidge. Follow him on Twitter at @rbutlersf. Michael Selvidge is the Sr. Corporate Communication Manager at Twilio. Follow him on Twitter at @selviano
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.