0

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"));
James Z
  • 12,209
  • 10
  • 24
  • 44

1 Answers1

0

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.

jassent
  • 529
  • 3
  • 10
  • Thank you for the response, when I use your code - I am getting below errors :- System.UriFormatException HResult=0x80131537 Message=Invalid URI: The format of the URI could not be determined. Source=System – samshank102 Jul 05 '23 at 23:24
  • @samshank102, the process_gather.php was just an example. You will need to provide your own webserver with a controller or api endpoint. I use ngrok to create a tunnel from my local machine to the internet. Another alternative is to use Twilio Studio which will allow you to build serverless applications hosted by Twilio. – jassent Jul 05 '23 at 23:46
  • Thanks again for your response, Basically I am building C# console application , so there is no end point in that , I am directly writing code under Main() method. – samshank102 Jul 06 '23 at 00:13
  • in this scenario, could you please give me some Idea on how to make the call and also how to extract the text message whatever call recipient has spoken – samshank102 Jul 06 '23 at 00:14
  • @samshank102, this page will walk you through building an IVR: https://www.twilio.com/docs/studio/tutorials/how-to-build-an-ivr – jassent Jul 06 '23 at 09:41