Sales: contact@tretainfotech.com | +91-917-317-5751
HR: hr@tretainfotech.com | +91-962-477-169

Twilio Studio integration to generate inquiry through IVR using Asp.Net Core web API

Twilio
Sep 24, 2018 CSharp,Asp.Net Core 0 2630

Twilio Studio integration to generate inquiry through IVR using Asp.Net Core web API


In this era of artificial intelligence and the internet of things, it is quite common that everybody is focusing on automation and diminishing human intervention in various processes. Though IVR is one very common solution for the decreasing man power in supporting system or helpline from the decade, it is quite difficult and lengthy process to integrate it with web solution to do automated processing based on user voice or key input on the call. Twilio comes up with the Twilio Studio which is a very effective solution with drag and drop option to create various flows and initiate HTTP requests to trigger actions based on user input.

Here, I am going to demonstrate how to build the solution to generate sales enquiry based on user input on call.

Let’s start with the real-time requirement and proceed with how to build the solution using Twilio Studio. I have a scenario in which I am the owner of the used vehicle selling website and I am also selling these vehicles using other advertising platforms. I want to provide one helpline number when I put advertise on third-party platforms So that when any customer want to inquire regarding it, they can call on the helpline number and get details of the owner in the SMS. I don’t want to reveal owner information directly because I want to generate inquiry in my system when any customer asks about the vehicle from any third party platform.

Now I am explaining the steps, how we can achieve this type of solution using Twilio Studio.

Login to https://twilio.com, you will be able to see Studio option in the left bar like shown in below image.

Click on Studio and add new flow as shown in below image.

As we have a custom requirement which is not directly fit to any of the ready samples click on Start from Scratch.

Click on the next, Studio Flow is created and you are able to see this screen.

Here Trigger widget is already there and you are having three options to initiate your process. In our case, we are going to use an incoming call option as we want to take customer input through a call.

As we want to take advertise reference number as the input on call from customer keypad, I am adding gather input widget and adding text to say when calling on the IVR number.

You can also configure other options on gather_input like stop gathering on a particular key press, stop gathering after some digits etc.

Now we want to proceed further based on key pressed by user, so adding split based on keys widget and adding gather_1 keys to the input.

You can also set various conditions on it in the transitions, I have added a regex to check only digits input as shown below.

If my input match to this condition, I will send an HTTP request to the rest web API like shown below:

Here, you need to set your request URL, content type, request method, request body or parameters. I have added my parameters as shown below:

Rest API endpoint code in Asp.net core is given below:

public class TwilioWebhookController : ControllerBase
    {

        private readonly IConfiguration _configuration;
        private string key;
        private string twillioWebhookKey;
        public TwilioWebhookController(IConfiguration configuration) 
        {
            _configuration = configuration;
            twillioWebhookKey = _configuration.GetSection("TwillioWebhookKey").Value;
            key = _configuration.GetSection("EncryptionKey").Value;
        }

        [HttpPost]
        public async Task<IActionResult> SendSMS(SMSModel model)
        {
            var str = Encryption.Encrypt(Convert.ToString(twillioWebhookKey), key);
            string Key = Encryption.Decrypt(model.Key.Replace(" ", "+"), key);
            if(Key==twillioWebhookKey)
            {
                var result = await SendEnquirySMSAndAddEnquiry(model.PhoneNumber, model.AdvertId);
                if (result != String.Empty)
                {
                    var response = new
                    {
                        AdvertId=model.AdvertId
                    };
                    return Ok(response);
                }
                else
                {
                    return NotFound();
                }            
            }
            else
            {
                return Unauthorized();
            }           
        }		
	 public class SMSModel
        {
            public string Key { get; set; }
            public string PhoneNumber { get; set; }
            public string AdvertId { get; set; }
        }		
 }

Here I am sending AdvertId in response which I can use while playing a message like shown in below screen.

Now Final flow image is as shown in below screen.

You can also add other request handling part for the failed cases, which I haven’t mentioned here.

Now you just need to publish the flow and set incoming calls to start studio flow in Twilio like shown in below screen.

Now, Twilio Studio IVR with API triggering and send SMS using it is working. You can now try other widgets and make it feature rich by yourself and develop various functionality using Twilio Studio.

Blog Author

Comments

Leave a Comment