我们试图在我们的 UI 中包含 IVR 步骤,但要获得这些步骤,我必须进行几次 API 调用。没关系,除了我似乎可以获得相关信息的唯一方法是加载所有流执行。
如果我可以通过flow.sid
小HTTP Request
部件传递,那么我可以稍后获取我需要的信息,而不必遍历所有先前的执行。我尝试{{flow.data}}
作为请求正文传递,认为它是 JSON,但它最终是空的。
这是有人为我们写的一个尖峰,修改为只使用一个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 - 我需要在小部件中传递的流执行信息,HTTP Request
或者我需要从 a 向后工作CallSid
以获取执行步骤。