Twilio click to call and gather digit

335 views Asked by At

I've developed a web that connect two persons into a call following this tutorial: https://www.twilio.com/docs/tutorials/click-to-call-node-express and everything is working fine.

Now I need to gather 1 digit of the callee in order to execute a command.

Reading the Twilio documentation it seems I can't use Gather until the Dial verb is over, but this way the call is closed and the callee can't digit anything.

I tried this without success, the dial works fine but the digits callback is never executed:

twimlResponse.say(
    'Please wait for the other person to join the call'
  );

  twimlResponse.dial({
    timeLimit: 30
  })
  twimlResponse.dial(to_number)

  const gather = twimlResponse.gather({
    input: 'dtmf',
    timeout: 30,
    numDigits: 1,
    action: url // the url is the callback that should handle the digit entered
  });

Is it a limitation of Twilio? any workaround or alternative call strategy?

1

There are 1 answers

2
user94559 On

I believe you need to send an url with the number you dial and have that URL respond with the TwiML you want to drive the interaction with the callee. From https://www.twilio.com/docs/api/twiml/number:

The 'url' attribute allows you to specify a url for a TwiML document that will run on the called party's end, after she answers, but before the parties are connected. You can use this TwiML to privately play or say information to the called party, or provide a chance to decline the phone call using <Gather> and <Hangup>.

So something like this:

const dial = twimlResponse.dial({
  timeLimit: 30
});
dial.number({
  url: urlToGather // respond to this URL with your <Gather> TwiML
}, to_number);