0

I am trying to create a voice call from twilio to a number using programmable voice. I also intend to gather recipient's speech transcribed. However, the documentation contains examples and tutorials only for inbound voice calls.

This is what I have tried-

Initiating voice call:

  client.calls
  .create({
    twiml: `<Response><Gather input="speech" action="https://ngrok-url-for-my-local-server/voice" method="POST" speechTimeout="5"><Say>Hey there, How are you?</Say><Pause length="4" /></Gather></Response>`,
    to: toPhoneNumber,
    from: myPhoneNumber,
  })
  .then((call) => {
    console.log(call.sid)
    console.log(call)
  })
  .catch((e) => {
    console.log(e)
  })

Code in handler for gathering speech-

const VoiceResponse = twiml.VoiceResponse

const res = new VoiceResponse()
res.gather()
console.log(res.toString())

However I am not getting anything useful in the console. Can anybody point me to a useful tutorial or example or tell me what I should do ?

1 Answers1

0

You need to first make the call and then modify the call to gather.

When you make the call using the new VoiceResponse() call you will be returned a SID for the call. Next, use that SID to modify a call that is in progress by redirecting to the Twiml to gather the digits.

You will have three legs:

  1. Make the outbound call (you provided this code in your questions).
  2. Modify the active outbound call by using the call's SID to redirect to a Gather twiml.
  3. After the gather has finished tell the call what do to using the action parameter of the gather. Here is an example.

If you are trying to go for a conference bridge type feature where you press * to move into an admin type menu, you will need a more complex solution involving a conference call.

jassent
  • 529
  • 3
  • 10
  • Hey jassent, I am making the call with `client.calls.create` (refer to question), do I need to give any twilm there? And where should I provide with the webhook url where I will update the code with gather twiml ? – ashutosh sHisodia Oct 18 '22 at 06:26
  • Your twiml is on the right track. You need the "action" to process the digits. Refer to the [Gather node.js example](https://www.twilio.com/docs/voice/twiml/gather). In the example, you will need to write the method/controller for "process_gather.php". So after the twiml gathers the digits it will call the process_gather.php where you will then handle the digits. process_gather.php can then [update the call in progress](https://www.twilio.com/docs/voice/api/call-resource?code-sample=code-update-a-call-in-progress-with-twiml&code-language=Node.js&code-sdk-version=3.x) using the Twilio REST Api. – jassent Oct 18 '22 at 10:09