0

I need to automatically make calls for customers and start a interaction with them through voice. Basically, when the customer pickup the phone, my "robot" will ask: "Hey, it seems you didn't finish your order. Would you like to finish by phone?" Customer will say YES, NO, or another phrase, and I will follow the flow.

My questions:

1) What is the best approach to solve this problem using Twilio?

2) It seems Twilio has this functionality (ASR) to understand only for inbound calls when I use functions. How can I do that with outbound calls?

3) Is Twilio ready to understand another languages except English? I need to use Portuguese, Brazil.

Thank you for your help.

Rafael Cronemberger
  • 231
  • 1
  • 4
  • 11

1 Answers1

0

Twilio developer evangelist here.

To automatically make calls you will need to use the Twilio Programmable Voice API. I note you're using C# according to the tags, so you can start with the Twilio C# library. Using the library you can make calls with the API like this:

using System;
using Twilio;
using Twilio.Rest.Api.V2010.Account;
using Twilio.Types;

class Example
{
    static void Main(string[] args)
    {
        // Find your Account Sid and Auth Token at twilio.com/console
        const string accountSid = "your_account_sid";
        const string authToken = "your_auth_token";
        TwilioClient.Init(accountSid, authToken);

        var to = new PhoneNumber("+14155551212");
        var from = new PhoneNumber("+15017122661");
        var call = CallResource.Create(to,
                                       from,
                                       url: new Uri("http://demo.twilio.com/docs/voice.xml"));

        Console.WriteLine(call.Sid);
    }
}

For a bit more detail on what all this means, check out the guide on making outbound phone calls with C#.

You will see in that example that we pass a URL to the method that makes the call. This URL can point anywhere, including at a Twilio Function (which is just a Node.js run in the Twilio infrastructure) or your own server. When the call connects to the user Twilio will make an HTTP request to that URL to find out what to do next. To tell Twilio what to do you will need to return TwiML.

To respond with the message that you want and then gather speech input from your user you will need to use the <Say> and <Gather> elements of TwiML. An example response might look like:

<Response>
  <Gather input="speech" hints="yes, no" action="/gatherResponse">
    <Say voice="alice">Hey, it seems you didn't finish your order. Would you like to finish by phone?</Say>
  </Gather>
</Response>

In this case we start with <Gather> so that we can capture anything the user says while the call is speaking to them. We set the input attribute to "speech" so that we can use speech to text to recognise what they say. Also included is the hints attribute which can give hints to the service for the text you expect to hear. Finally, there is an action attribute which is a URL that will be called with the result of this.

You can change the language that the <Gather> expects to hear using the language attribute. There are a number of languages available including Brazilian Portuguese, which you would set with "pt-BR".

Nested inside the <Gather> is a <Say> which you use to read out your message. You can use the voice attribute to change available voices.

The next thing you need to do is respond to the result of the <Gather>. At this stage it depends on what web application framework you are using. The important thing is that when it has a result, Twilio will make an HTTP request to the URL set as the action attribute. In that request will be two important parameters, SpeechResult and Confidence. The SpeechResult has the text that Twilio believes was said and the Confidence is a score between 0.0 and 1.0 for how sure Twilio is about it. Hopefully your result will have "Yes" or "No" (or the Brazilian Portuguese equivalent). At this point you need to return more TwiML to tell Twilio what to do next with the call depending on whether the answer was positive, negative or missing/incorrect. For more ideas on how to handle calls from here, check out the Twilio voice tutorials in C#.

Let me know if that helps at all.

philnash
  • 70,667
  • 10
  • 60
  • 88
  • Got success building my API following the sample, tks. Questions: Is it possible to avoid using the timeout parameter, and send information to the API every time the user stops speaking? Example: Hi, who are you? (And then, Twilio sends me the request). I tried to use timeout to call the API, but it seems they aren't respecting the value. I needed to wait for a while in the call. Any ideas? Some Brazilian Portuguese characters (for example, the word "não, same as "no") just broken my API when I try to get the Speech Result from the VoiceRequest object. Any ideas? – Rafael Cronemberger Jan 31 '18 at 02:28
  • You can try using the [`partialResultCallback`](https://www.twilio.com/docs/api/twiml/gather#attributes-partialResultCallback) which gets called asynchronously to the call, but means you could [modify the call](https://www.twilio.com/docs/api/voice/modify-live-calls) as soon as you get an expected result. As for the character issue, could you maybe ask a new question and give some more details? What do you mean by broken? – philnash Jan 31 '18 at 02:33
  • Just opened an a issue: https://github.com/twilio/twilio-aspnet/issues/12 – Rafael Cronemberger Jan 31 '18 at 02:51
  • Left you a comment over there, hope it helps! – philnash Jan 31 '18 at 03:15