Twilio: Receive Call On Your Own Server And Process The Call

Article shows how to receive incoming call on your own server and process the call further using Twilio. We can use Twilio for greet the user, dial new number, forward, redirect, record the call, hang up, reject, and play recorded message and many more things can do with that incoming call.

Step 1: Get Twilio Number

First log in to Twilio and get a number. You can purchase new number or you can start with trial account. For trial account Twilio provide one trial number. You can use it with some restrictions. In some cases, for getting Twilio number you need to provide one actual working number for verification process. As soon as you fill the details, Twilio system will call your actual number with some verification code, you need to put that code in text box given on Twilio website while verification. Then Twilio will provide you one Twilio number.

Step 2: Check your number’s default URLs

Click on “Configure Your Phone number” from same page or “Phone numbers” > “Manage” from top menu bar. You will find below screen:


Now test it, call on same number, default Twilio message will play. If you want to check default Twilio message, copy Voice URL and paste it in your browser, hit enter and check the XML code written for your number.

Note: For trial account you need to verify other numbers which you will use for testing. Twilio call it caller IDs. To verify number go to “Phone Numbers” > “Verified Caller IDs” > “Verify a Number” at top right corner.

Twilio provides two URLs for each number i.e. Voice URL which handles incoming/outgoing call and Messaging URL which handles text messages.

Step 3: Create Project to handle the incoming call using Visual Studio MVC

Visual Studio > File > New Project > Web > ASP.NET MVC Web Application

Add Home controller and one action as “ReceiveCall”.

Step 4: Add reference files

Go to the Solution Explorer > Right click on “References” > Manage NuGet Packages > Search Twilio > Install Twilio.Api, Twilio.Mvc and Twilio.Twiml

Add namespaces on top of the page of “HomeController.cs” file.

E.g. using Twilio; using Twilio.TwiML; using Twilio.TwiML.Mvc;

Step 5: Add the new action “ReceiveCall”


Step 6: Deploy the code

Publish code and deploy the code on your own server and hit the URL This is the demo URL so please check with your hosted URL. If you get familiar XML code then you are ready for next step.

Step 7: Replace Voice URL

Go to Twilio website and click on “Phone numbers” at top menu bar. Click on your number. You will find below screen:


Step 8: For testing, call on the Twilio number. It will say “Demo application” then will play given mp3, then dial the given number. You can customize the code as per your requirement.

Leave a comment