Twilio +.Net — Incoming and Outgoing Calls

Twilio provides telecommunication functionalities like SMS, Calling, WhatsApp integration, and many more. The goal of this post is to describe Twilio integration with .net and take advantage of Twilio’s amazing features.

Buy New Number
Login to Twilio > Go to Console. Note down Account SID, and Auth Token. Both will be required in future while integrating with .net.

The next step is to buy a new number. Go To Console > Phone Number > Active Numbers > Buy Number. Twilio gives one number free along with a free account and has limited features.

Settings for Incoming call

Go to Console > Active Numbers > Select the number > Set API as webhook
Set .Net API URL as “A Call Comes In” webhook (as shown in the below image). We used ngrok for incoming call testing for localhost. ngrok is a proxy URL associated with .Net API localhost. Any calls coming to ngrok will be redirected to .Net API URL.

Example:
.Net API URL: http://localhost:23548/api/home/incomingcall
ngrok URL: [http/https]://subdomain.ngrok.io/api/home/incomingcall

Generate Token for Incoming call

Go to Account Menu > Auth Tokens & API Keys

Create New API Key: Give meaningful name and note down API Key and API Secret. This will be used later while integrating incoming call in code.

Setting for Outgoing Calls

For outgoing calls, we need to create TwiML app. There are 2 ways to create TwiML App (Both are the same, it’s just different menu options).
1. Go to Console > Voice > Manage > TwiML Apps
2. Go to Console > Phone Numbers > Manage > TwiML Apps

Let’s set Outgoing Call API URL as Request URL (same like incoming, we are using ngrok for localhost) — http://localhost:23548/api/home/outgoingcall

Note down TwiML SID for Outgoing call which will be used later in code.

Let’s create a project in .net

To showcase Twilio integration, we are using the .Net 6.0 (you can use the same code for .Net core and .Net framework as well)
Package Name :
Twilio: Version 5.45.0
Twilio.AspNet. Common: Version 5.33.1
Twilio.AspNet.Mvc: Version 5.33.1

To perform Outgoing and incoming calls, we are going to create 2 different methods

  • GenerateTwilioToken
  • Javascript code to initialize token for incoming and outgoing call

You can download the sample code from here.

intforce software is a software development firm. With a fresh perspective and dedicated attention to each client, we provide a complete IT solution globally. By defining, designing, and developing solutions tailored to meet our clients’ business objectives, we ensure that our clients get the maximum return on their investment and support them in tackling evolving business and technological issues. Our mission is to provide the best customer service and expertise using the most practical and robust web technologies/software technologies to satisfy our clients’ IT objectives and to provide them with the business and competitive advantage they needed to succeed.

To learn more about intforce’s portfolio, visit: https://www.intforcesoftware.com/portfolio/ or drop us a mail at sales@intforcesoftware.com .

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store