简体   繁体   English

是否可以在 Twilio Studio Flow 中定义复杂变量?

[英]Is it possible to define complex variables in Twilio Studio Flow?

I'm building a subflow to manage the menus, because I have multiple of them and it is turning very complex to read.我正在构建一个子流程来管理菜单,因为我有多个菜单并且阅读起来变得非常复杂。

I need to send an array or a structured type of parameter to the subflow.我需要将数组或结构化类型的参数发送到子流。

Is there any way to create a multilevel (like JSON) or array variable using the Set Variable Widget?有什么方法可以使用 Set Variable Widget 创建多级(如 JSON)或数组变量?

I need to send to the subflow the indexes and descriptions of each items of the menu, so I can build the menu using Liquid Template Language inside a Send & Wait Widget.我需要向子流发送菜单中每个项目的索引和描述,这样我就可以在 Send & Wait Widget 中使用 Liquid Template Language 构建菜单。

Yes, you can create a lot of complex conditions using only the Studio.是的,您可以仅使用 Studio 创建许多复杂的条件。

The Studio uses the liquid template for the texts, you can see all the possibilities on this documentation . Studio 使用文本的液体模板,您可以在本文档中看到所有可能性。

I'll give some examples of what you can do using the liquid template (These examples can be used on Message, Voice, and Set variables widgets:我将提供一些示例,说明您可以使用 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 %}

I hope that it can help you:D.我希望它可以帮助你:D。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM