0

How do I return to a Studio Flow after playing a custom voice message to a person?

Here's the code:

  
  if(calledNumber == "+11234567890")
  {
   twiml.say("Biden is closed.");
  }
  return callback(null, twiml)

With this code above, it hangs up the call after telling me that Biden is closed instead of returning to my flow.

If I try it with a redirect like Twilio says is required:

  
  if(calledNumber == "+11234567890")
  {
   twiml.say("Biden is closed.");
   twiml.redirect({method: 'POST},'https://webhooks.twilio.com/v1/Accounts/<accountSID>/Flows/<flowSID>')
  }
  return callback(null, twiml)

... the Twilio logs show that the URL for the Studio Flow is called twice, the first call returning the valid TwiML but no redirect URL, and the second call has all the proper paramters (Called, CallSid, etc.), but a completely empty body.

The calls just... quit. How can I get back to my flow?

Using a TwiML Redirect isn't an option because the TwiML needs to be customized, not static. Thank you!

1 Answer 1

0

It seems like the behavior you're experiencing is the intended one. The function widget cannot return control back to the original Studio Flow execution once it has been invoked. It can only trigger a second flow execution.

However, using the TwiML Redirect widget would be a suitable solution as it can handle dynamic responses effectively.

This way, the redirect will call the URL and allow you to dynamically return to your Studio Flow, adhering to the custom logic you need.

4
  • I guess what I don't understand is how do I give Twilio dynamic content to play inside of the TwiML? If I want the Flow to call a Redirect TwiML that plays a different message based on the phone number that was dialed before returning to the original Flow, how can I do that without calling my own private URLs? I can't put if...then statements into TwiML, and the whole point of this thing being serverless is to not have a server, so what is Twilio's solution to this problem?
    – Highdel
    Commented Jun 30 at 20:51
  • You can use a serverless Function to handle this logic and return dynamic TwiML without the need to manage a server. Twilio Functions can handle this for you.
    – IObert
    Commented Jul 2 at 7:14
  • Sure. I love the serverless Functions, but I need to be able to come back to the Flow after the function finishes executing, and you're saying that's not possible. I need the dynamics of a Twilio Fucntion combined with the return-to-Flow capability of a Redirect TwiML. Is that not an option? (I got the Redirect TwiML working, I just really don't want to use my own server to do it)
    – Highdel
    Commented Jul 3 at 15:25
  • I haven't tried it myself but the way I read this docs, it works. You just need to select the right widget I linked above "The TwiML Redirect Widget allows you to redirect a call or message to TwiML hosted somewhere other than your Studio Flow and, optionally, return control of the call back to Studio after the TwiML you redirect to is complete."
    – IObert
    Commented Jul 3 at 20:30

Not the answer you're looking for? Browse other questions tagged or ask your own question.