0
votes

How can I run a flow from another flow in Twilio Studio Flow?

Help with defining the To and From HTTP parameters:

Help with defining the To and From HTTP parameters

I am a beginner in programming so I am failing to understand the brief notes given in support docs, namely specifying HTTP additional parameters for "To" and "From".

Additional details from comment:

I am trying to run REST API triggered Flow B from primary Flow A by using an http request widget in Flow A in the format below: (as suggested in a similar problem posted on this portal) Widget: HTTP Request [ACCOUNT_SID:[email protected]/v1/Flows/THE_OTHER_STUDIO_FLOW_SID/Executions][2] Content Type: Form URL Encoded KEY:VALUES To:+1234567890 From:+2773123456 I am getting error 401. I tried to swap the To number with the From number without success

3

3 Answers

1
votes

There are 2 ways you can trigger one twilio studio flow from another

Method 1:

Use the TwiML Redirect Widget. Place the widget where you need it and specify the target studio flow URL there. Studio URLs have the following format https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid}

Method 2:

Do the same as above programmatically. You can send twilio a twiML response such as the one below

      let twiml = new Twilio.twiml.VoiceResponse();
      
      if (something) {
        twiml.redirect({
            method: 'POST'
        }, 'https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid1}');
      } else {
        twiml.redirect({
            method: 'POST'
        }, 'https://webhooks.twilio.com/v1/Accounts/{AccountSid}/Flows/{FlowSid2}');
      }
     

For more info, check out https://www.twilio.com/docs/voice/twiml/redirect

0
votes

Assuming you are not trying to bridge the call between the two flows, this should be possible. To simplify:

  • You have a call come in on Flow A ("Incoming Call" trigger on Flow A).
  • Flow A executes its logic.
  • That logic triggers Flow B by calling its REST API endpoint so that it makes a new outbound call ("REST API" trigger on Flow B).

This last thing is the hard part. Make sure you are looking at the docs for the REST API Execution resource. To trigger a new flow, you need to make a POST request which supplies the To and From parameters.

If you are a beginner at programming, it might be helpful for you to start with a separate HTTP client like Postman to start to get familiar with the structure of an HTTP request, and learn the full extent of what is required to successfully make this API request before you start trying to cram it into Studio and automate it.

That said, this request should be possible to do within the Studio Make HTTP Request widget. If you make your content type Application/JSON, you can pass the To/From parameters directly in a JSON-formatted request body, like this:

{
  "To": "+19995551234",
  "From": "+12345556789"
}

To be perfectly honest, I don't know what the widget means by "Http Parameters". This could be HTTP Headers, URI parameters, or something else. I think the JSON form is clearer.

0
votes

I came across the same situation. The solution for authentication is to change the url to include AccountSid and AuthToken

https://[AccountSid]:[AuthToken]@studio.twilio.com/v2/Flows/[SID]/Executions

Instead of Application / Json, use Form Parameters. Then add individual parameters below, for To, From, and Parameters​ (JSON string) for other variables.