Do you ever listen to Soulja Boy's song "Kiss Me Thru the Phone" and wonder, "How can I kiss someone through the phone?"
Whether you have or not, you're probably looking for new creative ways to express your feelings to your loved ones this Valentine's Day.
With the help of Twilio and your command line, you can deliver a romantic Valentine's Day poem over the phone to your gal pals, best buddies, a special someone, or to yourself! With a project as fun as this, it's hard to restrict yourself from using it on only one day out of the year.
In this article, you'll be using TwiML and the Twilio CLI to call a phone number and deliver a poem.
Tutorial requirements
- A free or paid Twilio account. If you are new to Twilio get your free account now! (If you sign up through this link, Twilio will give you $10 credit when you upgrade.)
- The Twilio CLI.
Set up the Twilio CLI environment
If this is your first time installing the Twilio CLI, check out the Twilio CLI quickstart page for instructions on how to install it on your machine.
For developers using a Mac, it's very convenient and easy to install the CLI using Homebrew, so make sure you check out how to install Homebrew on your machine if you don’t have it already. Then, you can run the command brew tap twilio/brew && brew install twilio
to install the Twilio CLI.
For Windows developers, make sure you install npm first, as you will need it to install the CLI with the command npm install twilio-cli -g
.
Once you have the Twilio CLI installed, type twilio login
to log in to your account. You’ll need your Account SID and Auth Token from the Twilio Console to login.
Create a Twilio Bin
TwiML Bins work well with Twilio Functions because they help you explore Twilio's capabilities to the fullest. By using Twilio's Markup Language (TwiML), you save yourself the hassle of having to write complex code or connect your own web server in order to execute a simple call.
If you haven't done so already, search for and purchase a Twilio phone number from the console. Make sure that the phone number you choose is set to the same country or region of your personal number to avoid international fees when you pick up calls from the number.
On the Twilio Console, click on the (...) icon and scroll down to the Runtime section. Select TwiML Bins. Click on the red (+) sign to create a new TwiML Bin.
Give the TwiML Bin a friendly name such as "valentinesdaygram". In the next step, you’ll populate the TwiML text box with the script for the voice recording that you will hear when you call the number.
Before you move on further, take some time to meet Alice. Alice is a talented friend of Twilio, known as a text-to-speech (TTS) engine that converts text into a human-sounding voice. Thus, Alice is the perfect way to deliver the Valentine’s Day poem. Alice is capable of speaking in 26 total dialects and offers the voice of a man
or a woman
.
For now, we'll have Alice speak in their default voice and recite some verses from Eavan Boland's poem, "Code", attributed to Grace Murray Hopper. However, feel free to change the XML to whatever you please. Copy and paste the following XML into the text box, replacing anything already inside, and click the Create button at the bottom of the page:
You should be able to see the properties of your TwiML bin at the top of the page. Leave this page open as you'll need to use the TwiML URL in the next section.
Send yourself a romantic poem with Twilio
Take a moment to test out the TwiML bin by making a call to your personal phone number. To do this, run the following command from your command line, taking care to replace the placeholder values with your own. Take the URL from the TwiML Bin page and set that as the value for the url
line.
Replace the from
value with your Twilio phone number in E.164 format such as "+19140201400". For the time being, use your personal phone number in E.164 format for the to
value so that the call is directed to your device.
Wow, what a beautiful and powerful poem!
Is Alice's voice not swoon worthy enough for you? No worries, as I mentioned earlier, Alice is capable of speaking 26 different dialects and can change to a man
or a woman
.
Let's experiment with the TwiML voices in the next section.
Change Alice's TwiML Voice
Go back to the valentinesdaygram TwiML Bin on the Twilio Console. Look at the documentation for TwiML Voices to see all of the dialects you can choose from.
Let's make Alice sound more like a woman by specifying her voice to woman
. Replace the TwiML Bin with the following XML:
Wait a minute… then check your phone!
Who said knowing how to use computers can't be romantic?
What's next for sending romantic poems over the phone with Twilio?
Congratulations on using Twilio to send a poem over phone and text! As you can see, not only is coding fun, but it can be used to impress your loved ones with a surprise they surely weren't expecting. Just make sure they don't ignore the call ;)
There's so much you can accomplish with the Twilio CLI to help you build fast and test out the power of Twilio. Check out the examples on the docs to learn more about quick commands you can use on the Twilio CLI.
Now that you know the basics of making a call with Twilio CLI, you can try to expand on the project by sending a poem to a list of contacts. Here are some other cool projects you can explore:
- Send a Valentine's Day Gram with Twilio Functions
- Build a Galentine's Day Compliment Generator with Python, Flask, and Twilio
- Last minute Valentine’s Day Gifts delivered via Twilio Studio
Let me know how you're sharing the love in February this year by reaching out over email!
Diane Phan is a Developer for technical content on the Twilio Voices team. She loves to help beginner programmers get started on creative projects that involve fun pop culture references. She can be reached at dphan [at] twilio.com or LinkedIn.