【问题标题】:Is it possible to define complex variables in Twilio Studio Flow?是否可以在 Twilio Studio Flow 中定义复杂变量?
【发布时间】:2023-01-13 01:54:29
【问题描述】:

我正在构建一个子流程来管理菜单,因为我有多个菜单并且阅读起来变得非常复杂。

我需要将数组或结构化类型的参数发送到子流。

有什么方法可以使用 Set Variable Widget 创建多级(如 JSON)或数组变量?

我需要向子流发送菜单中每个项目的索引和描述,这样我就可以在 Send & Wait Widget 中使用 Liquid Template Language 构建菜单。

【问题讨论】:

    标签: twilio-studio


    【解决方案1】:

    是的,您可以仅使用 Studio 创建许多复杂的条件。

    工作室使用液体模板的文本,你可以在这个documentation看到所有的可能性。

    我将提供一些示例,说明您可以使用 liquid 模板执行哪些操作(这些示例可用于消息、语音和设置变量小部件:

    //example 01
    //iterating between an array of 25 items
    {% for item in (1..15) offset:0 limit:15 %}
    {%- if forloop.last -%}
    {{forloop.index | plus: flow.variables.offset}} - Last Item {{forloop.index | plus: flow.variables.offset}} 
    {%- else -%}
    {{forloop.index | plus: flow.variables.offset}} - Items {{forloop.index | plus: flow.variables.offset}}
    {% endif %}
    {% endfor %}
    
    //in the above example I used an array with a specific size, but you can get the array from an API and iterate in the same way, and as you can see, you can set variables inside of the context of the widget using the assign
    
    //example 02
    //A If condition using Liquid
    
    {%- if widgets.send_and_reply_1.inbound.Body == "1" -%}
    item 1
    {%- else -%}
    item 2
    {%- endif -%}
    
    //example 03
    //these variables are used how anchors on iteration, because the studio has a limit of 15 items by time, so this will control it, I iterate by ten items by time and last, I give the option to customer select more 
    {% assign iterationSize = flow.variables.offset | plus: 10 %}
    {% assign arraySize = flow.variables.arraySize | plus: 0 %}
    
    Encontrei {{widgets.getAvailableDays.parsed.data.qtd}} opções. 
    
    Selecione um dia.
    //here I'm iterating from data that brings from an API, so I'm getting it from the parsed.
    {% for day in widgets.getAvailableDays.parsed.data.resultado offset:flow.variables.offset limit:10 %}
    {% if forloop.last %}
    //here I'm using the iterating item to show to customer, in this case it's just a string, but if you've an object you can access it from the same way, i.e day.someDataInsideOfThisObject
    {{- forloop.index | plus: flow.variables.offset -}} - Dia {{day}}
    {% if iterationSize < arraySize %}
    {{forloop.index | plus: 1 | plus: flow.variables.offset}} - Mais opções
    {% endif %}
    {% else %}
    {{-forloop.index | plus: flow.variables.offset -}} - Dia {{day}}
    {%- endif -%}
    {% endfor %}
    

    我希望它可以帮助你 :D。

    【讨论】:

    • 也许我不清楚。使用您的示例,是否可以在第 2 行将 (1..15) 替换为 flow.variables.list
    • 是的!!如果您的变量是一个数组,那完全有可能,我添加了更多示例来展示使用来自 API 的数据进行迭代
    猜你喜欢
    • 2022-01-07
    • 1970-01-01
    • 2015-09-27
    • 1970-01-01
    • 2011-08-18
    • 2021-10-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多