Why does Twilio not support SIP

Using Twilio for Telephony and SMS Functions in Python

This guide shows you how to perform common programming tasks with the Twilio API service on Azure. The scenarios deal with making a phone call and sending a short message (SMS). For more information about Twilio and how to use Telephony and SMS in your applications, see the Next Steps section.

What is Twilio?

Twilio is a powerful, future-oriented corporate communications tool that enables developers to embed telephony, VoIP, and messaging capabilities into applications. The entire infrastructure required in a cloud-based, global environment is virtualized and made available via the Twilio API communication platform. Applications can be easily created and scaled. You benefit from flexible pay-as-you-go prices and the reliability of the cloud.

Twilio Voice enables applications to make and receive phone calls. Twilio SMS allows your applications to send and receive SMS messages. Twilio client allows you to make VoIP calls from any phone, tablet or browser and supports WebRTC.

Twilio prices and specials

Azure customers get a special offer: $ 10 Twilio credit when they upgrade their Twilio account. This Twilio credit can be spent on any Twilio usage (a $ 10 credit is sufficient for sending 1,000 SMS messages or for up to 1,000 incoming phone minutes, depending on the location of the phone number and the message or call destination) . Redeem this Twilio credit and get started.

Twilio is a pay-as-you-go service, i.e. it is not subject to a contract. There are no setup fees and you can close your account at any time. For more information, see Twilio Pricing.


The Twilio API is a RESTful API that provides telephony and SMS functions for applications. Client libraries are available in several languages. For a list, see Twilio API Libraries.

Key aspects of the Twilio API are Twilio verbs and the Twilio Markup Language (TwiML).

Twilio verbs

The API uses Twilio verbs; for example, the verb <Say> Invite Twilio to beep a message in a call.

Below is a list of Twilio verbs. Other verbs and functions are explained in the Twilio Markup Language documentation.

  • <Dial> : Connects the caller to another phone.
  • <Gather> : Captures digits entered on the phone keypad.
  • <Hangup> : Ends a call.
  • <Pause> : Waits without sound for a specified number of seconds.
  • <Play> : Plays an audio file.
  • <Queue> : Adding to a queue of callers.
  • <Record> : Records the caller's voice and returns a URL of a file containing the recording.
  • <Redirect> : Transfers control of a call or SMS to the TwiML at a different URL.
  • <Reject> : Rejects an incoming call to your Twilio number at no cost to you.
  • <Say> : Converts text to speech for a call.
  • <Sms> : Sends an SMS message.


TwiML is a set of XML-based instructions based on the Twilio verbs that tell Twilio how to handle a call or SMS.

The TwiML in the following example converts the text Hello World in language.

When an application calls the Twilio API, one of the API parameters is the URL that the TwiML response will return. For development purposes, you can use the URLs provided by Twilio to provide the TwiML responses used by your applications. You can also host your own URLs to generate TwiML responses; another option is to use the object.

For more information on Twilio verbs, their attributes and TwiML, see TwiML. For more information on the Twilio API, see Twilio API.

Creating Twilio Accounts

To create a Twilio account, sign in to Try Twilio. You can start with a free account and upgrade later.

When you sign up for a Twilio account, you will be given an account SID and an authentication token. You will need both of these details to make Twilio API calls. Keep your authentication token safe to prevent unauthorized access to your account. You can enter your account SID and authentication token in the Twilio console in the fields ACCOUNT SID or. AUTH TOKEN see.

Creating a Python Application

A Python application that uses the Twilio service and runs on Azure is no different from any other Python application that uses the Twilio service. Twilio services are REST-based and can be called in Python in a number of ways. This article focuses on using Twilio services with the Twilio library for Python from GitHub. For more information on using the Twilio library for Python, see https://www.twilio.com/docs/libraries/python.

First, set up a new Azure Linux VM that will host your new Python web application. Once the VM is up and running, you need to make your application available on a public port as described below.

Add an inbound rule

  1. Go to the Network Security Group page.
  2. Select the network security group that corresponds to your virtual machine.
  3. Adding a Outgoing rule For Port 80. Make sure you allow incoming from any address.

Enter DNS name description

  1. Navigate to the The Public IP Addresses page.
  2. Select the public IP address that corresponds to your virtual machine.
  3. Put the DNS name label in the section configuration firmly. In this example it looks something like this your domain name.centralus.cloudapp.azure.com

Once you can connect to the VM via SSH, you can install the web framework of your choice (the two most popular ones in Python are Flask and Django). You can only install either of the two by running the command.

Note that we configured the VM to allow traffic on port 80 only. Make sure the application is configured to use this port.

Configure an Application to Use Twilio Libraries

You can configure the application for the Twilio library for Python in two different ways:

  • You can install the Twilio library for Python as a pip package. To do this, run the following commands:


  • Download the Twilio library for Python from GitHub (https://github.com/twilio/twilio-python) and install it as follows:

After you've installed the Twilio library for Python, you can then put it into your Python files:

See twilio_github_readme for more information.

Make outgoing calls

The following shows how to make an outgoing call. This code uses a website provided by Twilio to return the Twilio Markup Language (TwiML) response. Enter your values ​​for the phone numbers from_number and to_number one and make sure you get the from_numberVerified the phone number for your Twilio account before running the code.


Telephone numbers must be formatted with "+" and a country code. For example: +16175551212 (E.164 format). Twilio also accepts unformatted US numbers. Example: 415 or 555-1212.

As mentioned earlier, this code uses a website provided by Twilio to return the TwiML response. Instead, you can have the TwiML answer provided by your own website. For more information, see Providing TwiML Responses from Your Website.

Sending SMS messages

The following example shows how to send an SMS message using the class. The from_numberNumber is provided by Twilio for test accounts to send SMS messages. The to_numberNumber needs to be verified on your Twilio account before running the code.

Providing TwiML answers from your own website

When your application initiates a call to the Twilio API, Twilio sends your request to a URL that is expected to return a TwiML response. The above example uses the Twilio-provided URL https://twimlets.com/message. (TwiML was designed for use by Twilio, but it can be viewed in the browser. For example, click https://twimlets.com/message to see a blank element. Another example: Click https: // twimlets .com / message? Message% 5B0% 5D = Hello% 20World to display an element with an element.)

Instead of the URL provided by Twilio, you can create your own website for returning HTTP responses. You can build the website in any language that will return XML responses. This example assumes that you are building the TwiML response using Python.

The following examples output a TwiML response that was sent to the call Hello World says.

With Flask:

With Django:

As the example above shows, the TwiML response is simply an XML document. The Twilio Library for Python contains classes that TwiML generates for you. The following example generates the same response as above, but using the module in the Twilio library for Python:

You can find more information about TwiML at https://www.twilio.com/docs/api/twiml.

Once you've set up your Python application with the TwiML responses, you can pass the application's URL to the method. For example, if you have a web application named MyTwiML for an Azure hosted service, you can use the URL as a webhook, as shown in the following example:

Use additional Twilio services

In addition to the examples shown here, Twilio provides web-based APIs that you can use to use additional Twilio functionality in your Azure application. See the Twilio API documentation for details.

Next Steps

Now that you are familiar with the basics of the Twilio service, check out these links for more information: