Search code examples
twiliotwilio-functionstwilio-studio

How to pass procesing a call from Twilio functions back to Twilio Studio flow?


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?


Solution

  • 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.