samshank102
samshank102

Reputation: 3

Using twilio how to make a call and extract the call response in Text format with C# code

Using twilio API how to make a call and extract the call response in Text format.

below is my code - I am able to make the call to specified number, but after making the call and after answering the call it says the configured message and then It just disconnects - It doesn't allow call recipient to speak.

And also how to extract the call response in text format (I mean whatever phone call recipient has responded)?

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OfficeOpenXml;
using System.Data;
using ExcelDataReader;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.TwiML;
using System.Net.Http;

namespace CustomerCallerV1._0
{
    internal class Program
    {
        static void Main(string[] args)
        {
         TwilioClient.Init("1603567658742638756874", "378659876587634785");

 var call = CallResource.Create(
 twiml: new Twilio.Types.Twiml($"<Response><Say>Hi, How are you Doing?Is that a good time to talk now ?</Say></Response>"),
 to: new Twilio.Types.PhoneNumber($"+12396467367"),
 from: new Twilio.Types.PhoneNumber("+12396467368"));

         }

     }
}

var call = CallResource.Create(
 twiml: new Twilio.Types.Twiml($"<Response><Say>{column2}</Say></Response>"),
 to: new Twilio.Types.PhoneNumber($"+12396467367"),
 from: new Twilio.Types.PhoneNumber("+12396467368"));

Upvotes: 0

Views: 306

Answers (1)

jassent
jassent

Reputation: 1116

The Twiml you provided instructs Twilio to say something to the caller. To get the caller to return a response, you will need to use the Gather verb and receive the response back to your controller/api endpoint:

var response = new VoiceResponse();
var gather = new Gather(action: new Uri("/process_gather.php"),
            method: Twilio.Http.HttpMethod.Get);
gather.Say("Please enter your account number,\nfollowed by the pound sign");
response.Append(gather);
response.Say("We didn't receive any input. Goodbye!");
Console.WriteLine(response.ToString());

In the example above, process_gather.php will receive the account number after the caller presses the pound key on their phone.

Upvotes: 0

Related Questions