twiliotwilio-apitwilio-twimltwilio-programmable-voice

Twilio Gather followed by call forward (Dial) after user input without using another webhook


I'm using the Twilio C# SDK to initiate an outbound call from Twilio, during which user's DTMF input needs to be gathered (Press 1 to be transferred to sales, 2 for support...), and the subsequent action is to forward the call to a designated E164 number that matches the key.

So the VoiceResponse.Gather() method takes this action parameter that is a webhook Uri to which the user input will be posted and we can surely forward the call from there.

var twiml = new VoiceResponse();
twiml.Say("...");
twiml.Gather(numDigits: 1, action: webhookUri);

But is there a way to achieve this simple forward instruction within the current twiml object without involving an external webhook? Basically something that gathers the user input digit, correlates to a E164 number(using a predefined dictionary), then Dial directly.


Solution

  • Twilio developer evangelist here.

    No, there is not a way to achieve the instruction after the <Gather> without another webhook. You must pass a URL as the action parameter and respond to the webhook with the next set of TwiML to direct the call onward.

    If you do not want to host the application that responds to this webhook yourself, you could achieve this flow using Twilio Studio, which is a drag and drop editor for communications flows, or using Twilio Functions, which is a serverless environment where you can respond to incoming HTTP requests with JavaScript functions.