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
- To begin, you'll need a Twilio inbound phone number. You can use a free Twilio trial account or upgrade your account and get your own dedicated phone number.
- You will also need a web host that lets you host PHP applications. There are lots of 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 companyfoo.com. Create a file called hello-monkey.php in the document root. The URL should be http://companyfoo.com/hello-monkey.php and will be the initial URL for your phone number.
- If you are using a trial Twilio account, browse to your Dashboard page on the Twilio website. Scroll down to the "Your Trial Sandbox" and paste the URL of your hello-monkey file (e.g. http://companyfoo.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 to the Phone Numbers page in your account on the Twilio website. If you don't already have a Twilio phone number, you can purchase your own phone number using the "Buy a Number" button on the right hand side of the page. Paste the URL of your hello-monkey file (e.g. http://companyfoo.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:
Now, pick up your mobile or landline phone and dial the number of application. Twilio will now fetch your URL, http://companyfoo.com/hello-monkey.php in our case, and execute the XML instructions above. First, it will Say 'hello monkey' and then it will hang up because there are no more instructions.
Next: Hello Monkey 1.1