0

We're trying to include the IVR steps in our UI, but to get the steps I have to make several API calls. That's fine, except the only way I can seem to get the relevant info is to load all flow executions.

If I could pass the flow.sid via the HTTP Request widget then I could go fetch the info I need later instead of having to iterate through all the previous executions. I tried passing {{flow.data}} as the request body, thinking it was JSON, but it ends up being empty.

widget config RequestBin response

Here's a spike that someone wrote for us, modified to just work with a single execution.

require "httparty"

STUDIO_FLOW_SID = "FW***"
AUTH = {username: ENV["TWILIO_ACCOUNT_SID"], password: ENV["TWILIO_AUTH_TOKEN"]}
DATE_CREATED_FROM = "2019-09-01T000000Z"
DATE_CREATED_TO = "2019-10-01T000000Z"

# Retrieves all executions in the given date range
executions_url = "https://studio.twilio.com/v1/Flows/#{STUDIO_FLOW_SID}/Executions?DateCreatedFrom=#{DATE_CREATED_FROM}&DateCreatedTo=#{DATE_CREATED_TO}"
response = HTTParty.get(executions_url, basic_auth: AUTH)

# If I can get the individual execution from the IVR {{flow.data}}
# that would be ideal
execution = response.parsed_response["executions"].first

execution_context_url = execution["links"]["execution_context"]
execution_context = HTTParty.get(execution_context_url, basic_auth: AUTH)

# Or, if I could work backwards and get the execution context ID from
# the call somehow, that would work too.
call_sid = execution_context.parsed_response["context"]["trigger"]["call"]["CallSid"]

steps = HTTParty
  .get(execution["links"]["steps"], basic_auth: AUTH)
  .parsed_response["steps"]
  .sort_by { |step| step["date_created"] }
  .map { |step| step["transitioned_to"] }
  .select { |step| step.include?("option") || step.include?("menu") }

puts [call_sid, steps].inspect

tl;dr - I either need the Flow execution info passed in an HTTP Request widget or I need to work backwards from a CallSid to get the execution steps.

jc00ke
  • 2,435
  • 1
  • 21
  • 14

2 Answers2

1

Twilio developer evangelist here.

The execution Sid can be accessed in the flow's data, under flow.sid.

This was missing in the documentation, but I've just added it here: https://www.twilio.com/docs/studio/user-guide#context-variables

Note: {{flow.sid}} doesn't currently appear in Studio's autocomplete, but it's there, I promise!

philnash
  • 70,667
  • 10
  • 60
  • 88
0

I found a way to get the execution from the call:

Anyway, if you are calling the function from Studio, philnash answer is better :)

Dharman
  • 30,962
  • 25
  • 85
  • 135
ricardo
  • 26
  • 5