2

I am trying to migrate some parts of my studio flow to Twilio Functions, but not the whole, but it seems like that when I try to redirect back to the studio flow, Twilio dies with error 400 or hangs up the call.

I am experimenting with the following piece of code:

exports.handler = function(context, event, callback) {
    let twiml = new Twilio.twiml.VoiceResponse();
    //twiml.doWhatINeed();
    twiml.redirect('https://webhooks.twilio.com/v1/Accounts/AC.../Flows/FW...?FlowEvent=success');
    callback(null, twiml);
};

I expect it to continue the studio flow on the success branch, but the call gets hung up. I also experimented with ommitting FlowEvent, but it was no better.

When I enter an invalid FlowEvent (like helicopter), then I get error 400.

Do you guys have any idea what am I missing?

lezsakdomi
  • 115
  • 10

3 Answers3

1

Adding another answer here because the other two don't appear to be correct (anymore?).

In order to return to an active Flow after calling a function, you must use the TwiML Redirect widget instead of the Run Function widget, and you must append ?FlowEvent=return to your flow webhook URL when you redirect back to Studio after you finish your external logic. See the linked docs page for more info.

You can have as many rounds of TwiML as you need before redirecting, since the Studio flow hangs on to the call (and that call's place in the flow) until the call ends, even if it isn't directly controlling it anymore.

All you need to do to use the TwiML Redirect widget instead of Run Function is to get your function URL manually and configure it yourself, instead of letting the Run Function widget generate it for you. You can pass parameters to your function by using liquid variables to encode them in the URL string as URI parameters, and then using the GET method instead of POST.

NReilingh
  • 1,730
  • 17
  • 32
0

Take a look at the page at https://support.twilio.com/hc/en-us/articles/360019580493-Using-Twilio-Functions-to-Enhance-Studio-Voice-Calls-with-Custom-TwiML.

It looks quirky, but that page has you using a dummy "play/say" widget attached to the success transition of the "run function" widget, and use "FlowEvent=audioComplete" to continue on your flow.

mike
  • 86
  • 5
  • Is this still a thing? I can't see any mention of `FlowEvent` in the entire documentation, except for returning from the TwiML Redirect widget. – NReilingh Jan 13 '21 at 03:53
-1

What mike said worked for me, just be sure to connect a "play/say" after the function call on Twilio Studio and configure it to "Say a Message" and leave blank the "Text to Say".

In the function side just use:

twiml.redirect('https://webhooks.twilio.com/v1/Accounts/AC.../Flows/FW...?FlowEvent=audioComplete');

I still didn't got variables working as URL parameters method.