如何通过调用sid获取Twilio Studio Flow执行

时间:2019-10-04 18:21:48

标签: twilio twilio-studio

我们正试图在用户界面中包括IVR步骤,但要获得这些步骤,我必须进行几次API调用。很好,除了我似乎可以获取相关信息的唯一方法是加载所有流程执行。

如果我可以通过flow.sid小部件传递HTTP Request,则可以以后获取所需的信息,而不必遍历之前的所有执行。我尝试将{{flow.data}}作为请求正文传递,认为它是JSON,但最终为空。

widget config RequestBin response

这是某人为我们写的尖峰,经过修改可以只使用一个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小部件中传递的Flow执行信息,要么需要从CallSid向后工作以获取执行步骤。

2 个答案:

答案 0 :(得分:1)

这里是Twilio开发人员的传播者。

可以在flow.sid下的流数据中访问执行Sid。

文档中没有此内容,但我只是在这里添加了它:https://www.twilio.com/docs/studio/user-guide#context-variables

请注意:{{flow.sid}}当前未出现在Studio的自动完成功能中,但是我保证在其中!

答案 1 :(得分:0)

我找到了一种从调用中获取执行的方法:

无论如何,如果您是从Studio调用函数,那么philnash答案会更好:)