Wondering what actually happens when you connect to Twilio Client using your browser, and why you keep hearing that same welcome message? The key to this mystery is in this line:
This creates a security token that tells the browser which Twilio Application it will connect to. Applications are just references to TwiML URLs that are fetched when a connection is established from the browser. (If you are not familar with TwiML, we suggest you head over to the Twilio Markup Language Quickstart.)
So 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
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
copy-paste the following code into that file:
<?php header('Content-type: text/xml'); ?> <Response> <Dial> <Client>jenny</Client> </Dial> </Response>
Assuming your web server is at example.com, try loading up your new PHP
http://example.com/hello-client-monkey-twiml.php in your browser.
Now we’re ready to create the new application in your Account Dashboard, so let’s navigate to the 'Apps' tab. This is where you can see all your current Twilio Applications and create new ones. Select 'Create App' 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:
$capability->allowClientOutgoing('APXXXXXXXXXXXXXXXXXXXXXXXXX'); // YOUR APP SID!
Refresh the page. When you press the call button again, you should now be hearing your very own welcome message!