TwiML Quickstart: Hello Monkey
Let's walk through creating your first application, Hello Monkey. We'll use PHP to construct this example, but almost any web development language could be used.
Prerequisites
- You'll need a Twilio inbound phone number for customers to dial. You can use a free Twilio trial account or signup and get your own dedicated phone number.
- You will also need a web host that lets you host PHP applications. There are lots web hosting services that with host your PHP application for a few dollars a month.
Code
You can download the (minimal) code used in this example if you want:
Hello Monkey, v1.0
- Let's say your web server answers HTTP requests at mytwilioapp.com. Create a file called hello-monkey.php in the document root. The URL http://mytwilioapp.com/hello-monkey.php will be the initial URL for your phone number.
- If you are using a trial Twilio account, browse to your account page on the Twilio website. Scroll down to the "Your Trial Sandbox" and paste the URL of your hello-monkey file (e.g. http://mytwilioapp.com/hello-monkey.php) in the "Uses URL" box. Hit save and your sandbox account will now point to your new hello monkey code.
- If you are using a paid Twilio account, browse over to the phone number configuration page in your account on the Twilio website. Click on the phone number you wish to use for the demo. If you don't have a phone number you can purchase your own phone number using the "Find a Number" button on the right hand side of the page. Paste the URL of your hello-monkey file (e.g. http://mytwilioapp.com/hello-monkey.php) in the "URL" box. Hit save and this phone number will now point to your new hello monkey code.
- Now, open up the hello-monkey.php file on your web server. Let's start with this basic php example code:
quickstart/twiml/1.0/hello-monkey.php<?php
header("content-type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
?>
<Response>
<Say>Hello Monkey</Say>
</Response>
Now, call your application's phone number... Twilio will fetch your URL, http://mytwilioapp.com/hello-monkey.php in our case, and execute the XML above. First, it will Say 'hello monkey' and then it will hang up because there are no more instructions.
Next: Hello Monkey 1.1