Curing the Post MAGFest Blues with Twilio, Ruby, Sinatra and SEGA music
Time to read: 3 minutes
MAGFest is a video game music festival with just about everything fun that you can imagine: a giant arcade, amazing video game cover bands, tons of nerdy merchandise and a fantastic community. Going back to normal life can be a bit of a bummer after partying with some best friends you only see a few times a year.
Based on a suggestion from my pals at theshizz, I built a phone-based jukebox that plays happy SEGA music to relive the feeling of MAGFest whenever you want.
If you want to hear the pure positively charged ecstasy of classic SEGA music, call this phone number:
(855) 635-7342
Let’s walk through how to build your own IVR based jukebox.
Building a phone based SEGA Jukebox in Ruby
Here is all of the code you need to build a SEGA jukebox:
Copy and paste that code into a new file called app.rb
. Before being able to run this code, you’ll need to install some dependencies. Open your terminal and run the following commands:
Played over the hotline is a list of music from SEGA games that represented the pure nostalgic happiness and energy of MAGFest to my group of friends:
- The Space Harrier theme
- Emerald Hill Zone from Sonic 2
- Splash Wave from OutRun
- Like the Wind from Power Drift
- Pleasure from Phantasy Star 2
- Stage 1 from Quartet
If you want to build your own jukebox, replace the URLs to music of your choice, and update their name in the voice menu. You’ll need a publicly accessible URL to access each of those.
I’ll assume you might not have SEGA soundtracks lying around in the cloud, so if you need a URL to use for testing purposes, replace the first song URL in app.rb
with the following:
Calling your jukebox
Now that we have the code taken care of, let’s try actually calling a phone number to hear some jams. You’ll need a Twilio account for this, but don’t worry you can sign up for free.
When someone calls your Twilio number, Twilio makes an HTTP request to your app. Twilio expects an HTTP response from your web app in the form of TwiML, which is a set of simple XML tags used to tell Twilio what to do next.
Our app needs a publicly accessible URL so that Twilio can make that request. To avoid having to deploy every time we make a change, we’ll use a nifty tool called ngrok to open a tunnel to our local machine.
Ngrok generates a custom forwarding URL that we will use to tell Twilio where to find our application. Download ngrok and run it in your terminal on port 4567:
Next we need to grab a phone number or use the number that comes with your trial account and configure it to send POST
requests to your app whenever you receive a phone call.
Open the phone number configuration screen in your Twilio console. Scroll down to the “a call comes in” field. Before entering your URL you should see:
Punch in the URL for our call route that was generated by ngrok. It should look like http://your-ngrok-url.ngrok.io/call
.
Click save, and run you application by entering the following command in your terminal:
Call your number and press 1 to hear some awesome music!
Now it can be MAGFest forever
Now you have your own phone number to dial whenever you want to hear music of your choice. It may not be quite as glorious as running down a hallway blasting Space Harrier on a boombox, but hopefully this will come close enough to hold me over until the next MAGFest.
I can already smell the Elevation Burger.
Feel free to drop me a line if you have any suggestions for music from games made by SEGA I should add to the hotline, or just want to show off what you built:
- Email: sagnew@twilio.com
- Twitter: @Sagnewshreds
- Github: Sagnew
- Twitch (streaming live code): Sagnewshreds
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.