iOS Quickstart: Connecting to a TwiML Application

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 the Python server we deployed earlier. Let's take a look at that code:

# some code ommitted here

def token():
  account_sid = os.environ.get("ACCOUNT_SID", ACCOUNT_SID)
  auth_token = os.environ.get("AUTH_TOKEN", AUTH_TOKEN)
  app_sid = os.environ.get("APP_SID", APP_SID)

  capability = TwilioCapability(account_sid, auth_token)

  # This allows outgoing connections to TwiML application
  if request.values.get('allowOutgoing') != 'false':

  # This allows incoming connections to client (if specified)
  client = request.values.get('client')
  if client != None:

  # This returns a token to use with Twilio based on the account and capabilities defined above
  return capability.generate()

This portion of the code is responsible for creating a capability token that tells your Twilio Device what actions it is allowed to perform.

The two lines below tell your device to make outgoing connections to the App Sid APa4983020a0b29fb5db1b1dc68e322fbe.

APP_SID = 'APa4983020a0b29fb5db1b1dc68e322fbe'

# ... some code omitted here ...


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 Twilio Markup Language Quickstart.

The string starting with 'AP' is an Application SID. You entered this Application Sid when you deployed the server in the steps above. That Application's Voice URL points to your server's / endpoint, which returns the TwiML to say "Welcome to Twilio".

<?xml version="1.0" encoding="UTF-8"?>
    <Say>Welcome to Twilio</Say>

We change the user's telephony experience by generating different TwiML. Let's continue with an example that let's us dial any phone number.

Next: Passing Parameters to your Application »