- API & Docs
Wondering what actually happens when you connect using your app, and why you keep hearing that same welcome message? The key to this mystery is in this line in your PHP file:
$capability->allowClientOutgoing($appSid, array(), $clientName);
This creates a security token that tells your device which Twilio Application it will connect to. Applications are just references to TwiML URLs that are fetched when a connection is established from a device, a browser, or a phone. If you are not familiar with TwiML, we suggest you head over to the Twilio Markup Language Quickstart.
The string starting with 'AP' is an ApplicationSid. The default one above is a demo app created by Twilio that serves up a very simple TwiML document that uses <Say> to read a greeting.
Let's build a simple application in PHP to serve TwiML from your web host. Create a new file called
hello-client-monkey-twiml.php on your server and paste the following code into that file:
<?php header('Content-type: text/xml'); ?> <Response> <Say>Welcome to Twilio Client!</Say> </Response>
Assuming your web server is at
companyfoo.com, try loading up your new PHP script:
http://companyfoo.com/hello-client-monkey-twiml.php in your browser. All set?
Now we're ready to create the new application in the Apps Tab of the Account Dashboard. This is where you can see all your current Twilio Applications and create new ones. Select 'Add Application' and complete the form with the following information:
Click SAVE to create your app. Now, copy the newly created ApplicationSid and paste it into the token generation code at the top of the client script we created before:
$token->allowClientOutgoing('APXXXXXXXXXXXXXXXXXXXXXXXXX'); // Your application sid
If you press the Dial button again, you should now be hearing your very own welcome message!
Sweet. Now, what if you want to pass variables from your iOS app to the script running on the server?