1

I am setting up an IVR flow in Twilio Studio. I have a function that validates the user's phone number and then fetches some data. Once the data is fetched, I need to ask the user to input their zip code. I have used the "Gather Input On Call" widget. But the call gets disconnected as soon as the flow reaches this widget (event hangup is triggered).

Any idea what I could be missing? Is it possible to gather multiple digits as User Input in IVR flow?

Jilna
  • 190
  • 1
  • 13
  • Can you share your Studio flow? It is definitely possible to gather multiple digits as user input. Is the data being fetched successfully? Perhaps it's not making it to the Gather widget because the one before fails? – philnash Feb 13 '22 at 22:32
  • @philnash - You are right. The before widget was breaking the "Gather Input Widget" flow. I have a Set Variables widget, which passes on to the "Run Function" widget. In this widget I only have three lines of code, at a later point, will be adding a service call to this function but for now its just these three lines `let twiml = new Twilio.twiml.VoiceResponse(); twiml.say("Hello Welcome back"); return callback(null, twiml);` If I disconnect this function call and point Set variables directly to Gather User input. it works fine. – Jilna Feb 14 '22 at 09:20
  • When you say you only have 3 lines of code, do you mean apart from the code that exports the handler function. That is, it should start with `exports.handler = function (context, event, callback) {` and end with a `};` making 5 lines total. – philnash Feb 14 '22 at 11:48
  • @philnash yeah, I meant apart from the function definition. :) – Jilna Feb 14 '22 at 15:55

1 Answers1

1

If you use a Run Function Widget and want to return TwiML, you should use a TwiML redirect widget to call the Function instead, then use the suggested syntax below to return to the Studio flow.

TwiML Redirect Widget https://www.twilio.com/docs/studio/widget-library/twiml-redirect

Returning Control to Studio

To handle returning control to Studio, you need to specify a to the Studio Webhook URL and append ?FlowEvent=return. Any additional parameters specified in the return URL will be injected into the Studio context and addressable via Liquid template variables.

Alan
  • 10,465
  • 2
  • 8
  • 9
  • I tried the approach you suggested. I pass data to the Twilio function, but when I use the TwilML redirect widget, I am unable to pass the data. The document says I can pass data by appending it to the URL `?Digits={{widgets.MY_WIDGET_NAME.Digits}}` but the function call fails with `InvalidUrl` . From what I see in the docs the Twilio functions do not support path parameters. Any idea what am I missing. – Jilna Feb 15 '22 at 07:05
  • Do you have an example what you are using for the URL query parameters vs what the documentation is using (maybe you need to URL encode your data)? It works and Twilio Functions can access those passed parameters the same way it accesses POST parameters. – Alan Feb 15 '22 at 12:14
  • URL: `https://ivr-services-xxxx.twil.io/post-info?userData={{widgets.Set_Variables.body}}`. `widgets.Set_Variables.body` is a JSON response that I need to be passed to the function. – Jilna Feb 15 '22 at 13:59
  • 1
    Not sure how much JSON you are passing, maybe try: `https://x.x.twil.io/myFunction?widget={{trigger.call.AddOns | to_json | url_encode}}` – Alan Feb 15 '22 at 21:42
  • 1
    That worked. `url_encode` was missing. Thank you so much. – Jilna Feb 16 '22 at 13:45