<img alt="" src="https://secure.leadforensics.com/150446.png " style="display:none;">
Go to top icon

Integrating Twilio in Azure Web App for Phone and SMS

Vikram Pendse Jan 12, 2017

Microsoft Azure Twilio

In line of business apps or large enterprise apps you must have seen some automation for sharing feedback over email and connecting over Live Chat. Phone and SMS are another effective way to connect. Twilio as a product allows you to achieve automation of SMS and voice calling. It can be used for different applications, especially for technical support with clients.Twilio allows developers to programmatically make or receive phone calls and text messages using rich set of APIs

This article will help you to understand how to deploy a Twilio integrated web-app on Azure to make phone calls and SMS. 

How Twilio free trial works?

When you use Twilio as services then you have to sign up, this includes a free balance for you to experiment with. When your balance is getting low, Twilio will send you an email with information to upgrade your account. See the last section of this article for pricing.

Here are some tips to for using free Twilio account -

Phone numbers:

  • Twilio only allows one Twilio number per trial account. To get a different phone number, you need to release the current number you have on the numbers page first.

    twillo-1.png

  • If you upgrade your account, your trial number will be carried over and charged monthly according to current voice or SMS rates.

  • If your phone number is unused in your trial account for more than 30 days, Twilio will remove it from your trial account, becausethey do not have an unlimited supply of phone numbers for trial accounts. However, if you decide to return to your trial account, you can always buy a new phone number at any time and start using your new number, or if you are particularly attached to a phone number, you can always upgrade your account simply by adding your credit card.

SMS:

  • Be sure to verify non-twilio phone number before sending or receiving any SMS messages to/from it.

    twillo-2.png

  • You will be able to send SMS from your Twilio SMS enabled number, but not from your verified personal number. This rule will also apply after the trial.

  • When you send an SMS from your free trial phone number, it will begin with “Sent from a Twilio Trial account”. This message will be removed once your account has been upgraded.

  • You may be eligible to use global SMS on your trial account its depending on your country, you may be able to try Twilio’s global SMS service without upgrading your Twilio account. With a Twilio trial account, you may only send SMS messages to SMS-enabled phone numbers which you have verified.

Voice:

  • Before attempting to call be to verify non-twilio phone number by having Twilio place a verification call to it. This is an extra security measure that we remove once you’re calling from an upgraded account.
  • There are a limited number of countries your Twilio account can make calls to. Upgraded accounts have the ability to enable permissions to call almost any countryfrom your Twilio app.
  • Trial Accounts can only use either your account’s Twilio number, or a Verified User Id, as the Caller-ID/From number when making outgoing calls.

Note: To start using your Twilio phone number without these restrictions, just upgrade your account. 

How to get a Twilio number?
To get a twilio number you need to follow below steps -

Step 1
Go to www.twilio.com , click on sign up and put your valid information and click on get started.

Step 2
Verify your phone number.twillo-3.png
Step 3
After your phone verification, you can see your dashboard where account SID, authentication token etc. are visible.

twillo-4.png

Step 4
Go to All Products and Services > Phone Numbers > Get Started > Get Your First Twilio Number.

twillo-5.png

In this screen there is a by default number which provided by Twilio. If you want another number then click on search for a different number. When you click on search for a different number then it shows below screen.
twillo-6.png

In this you choose your capabilities accordingly your service. Once you have chosen your number, you’re good to go!

You can see your Twilio number in Manage Numbers > Active Numbers tab.

twillo-7.png

Make calls and SMS using .net + Twilio and host it on Azure.

Here we are using ASP.NET MVC application for demo purpose. However, you can call API from any type and project format like a simple console application. Here are steps to make phone call or SMS from your application using Twilio. This application will be then hosted to Azure as Azure Web App. For demo purpose, phone numbers are declared as hard coded string however in real scenarios, it can be fetched from database.

Step 1 -
Open your solution in Visual Studio and Search for Twilio NuGet package and install it.

Step 2 -
After installing NuGet Packge then create an action for a view. In this view there are 2 buttons “call” and “Send Text”. On hit of “call” call should go with pre-defined recorded message and on “Send Text” SMS should go.

twillo-8.png

Step 3 -
Add your Twilio SID and AUTH TOKEN into your web.config file.

twillo-9.png

Step 4 -
After change into your webconfig file then move to post method of your action where we add code for make calls and send SMS.

Code for making call:

twillo-10.png

In options.From put your twilio number.

As mentioned in this method there is aURL which comes from Twilio-Provided site to return the TwiML response.You could instead use your own site to provide the TwiML response. In the TwiML response, following xml file is included where there is a message:

twillo-11.png

Code for send message:

twillo-12.png

Note:
While doing SMS or call the non-twilio phone number must be verified.

Publishing your Twilio integrated Web App on Microsoft Azure:

When all done with coding then next step is to deploy your web-app on Azure. For that follow these steps-

  • Right click on your project and select publish

    twillo-13.png

  • After click on publish it shows like this, select Microsoft Azure Web Apps.

    twillo-14.png
  • Click on New for create a new web-app on Azure and give required information to create web-app

    twillo-15.png

    twillo-16.png

    twillo-17.png

  • When all set then click on Publish to host your app on website. After publishing it shows below message

    twillo-18.png

Running Twilio integrated in Azure Web App:

  • Go to your browser and type your new URL and press enter.

    twillo-19.png
  • Type your phone number and click on send SMS button

    twillo-20.png
  • Now you can see actual output on your mobile device.

    twillo-21.png

  • And when you click on make call button then it shows following output

    twillo-22.png


For pricing details check following link:
https://www.twilio.com/voice/pricing

Summary:

Twilio is the smartest and fastest way to make phone calls and SMS from your application whether it is on premise or hosted on cloud platforms like Microsoft Azure. APIs are well documented and overall integration is very easy and smooth. Give a try to Twilio for your app today.

e-Zest is a leading digital innovation partner for enterprises and technology companies that utilizes emerging technologies for creating engaging customers experiences. Being a customer-focused and technology-driven company, it always helps clients in crafting holistic business value for their software development efforts. It offers software development and consulting services for cloud computing, enterprise mobility, big data and analytics, user experience and digital commerce.