How to get a a)the range of and b)a specific entry of a JSON object based on user-input?

36 Views Asked by At

I have a call-flow in place which is triggered by a webhook. As part of the API call, a json in the following format is provided:

    "myActions": [
        {
            "number": 1,
            "text": "Do A"
        },
        {
            "number": 2,
            "text": "Do B"
        },
        {
            "number": 3,
            "text": "Do nothing"
        }
    ]

Obviously, I can access this data via {{flow.data.myActions}} (or a variable).

Now in my call-flow, I use a Gather Input on Call to let the user select one of those entries by looping through them:

{% for action in flow.data.myActions%}
{{ action.text }} press {{ action.number }}
{% endfor %}

Subsequently, I can use the widgets.myActions.Digits variable to get the actual digit a user has entered, so for example "3" for "Do nothing". So far so good.

There are two things I cannot wrap my head around:

  1. How can I look up the corresponding text of the selected number? My goal is to repeat the text based on the selected number, so for example say "Thank you, we will do nothing" if the user has pressed 3 or "Thank you, we will do B" if the user pressed 2.

  2. The second thing concerns the validation: the range of options/numbers provided in the JSON might differ from 1...n - in my "Split" condition I would like to use "Matches any of" and the dynamically have all numbers from 1 to n in there separated via comma. How do I do that?

0

There are 0 best solutions below