【问题标题】:How to get Twilio Studio Flow execution via call sid如何通过调用 sid 执行 Twilio Studio Flow
【发布时间】:2020-02-03 02:11:55
【问题描述】:

我们正在尝试在我们的 UI 中包含 IVR 步骤,但要获得这些步骤,我必须进行几次 API 调用。没关系,除了我似乎可以获取相关信息的唯一方法是加载所有流执行。

如果我可以通过HTTP Request 小部件传递flow.sid,那么我可以稍后获取我需要的信息,而不必遍历所有先前的执行。我尝试将 {{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;博士- 我需要在 HTTP Request 小部件中传递的 Flow 执行信息,或者我需要从 CallSid 向后工作以获取执行步骤。

【问题讨论】:

    标签: twilio twilio-studio


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      这里是 Twilio 开发者宣传员。

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

      文档中缺少此内容,但我刚刚在此处添加:https://www.twilio.com/docs/studio/user-guide#context-variables

      注意:{{flow.sid}} 目前没有出现在 Studio 的自动完成功能中,但我保证它就在那里!

      【讨论】:

      • 有没有办法从调用到执行倒退?我在 API 文档中没有看到任何内容。
      • 恐怕没有。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-07
      • 2015-10-31
      • 2018-09-23
      • 1970-01-01
      • 2022-01-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多