简体   繁体   中英

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?

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.

Yes, you can create a lot of complex conditions using only the Studio.

The Studio uses the liquid template for the texts, you can see all the possibilities on this documentation .

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:

//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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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