Access an element of an array using a session.parameter as an index

791 views
Skip to first unread message

Loris Cino

unread,
Feb 8, 2022, 9:19:07 AM2/8/22
to Dialogflow CX Edition users
Hello everyone, 

I'm new in DialogFlow CX. I need to access a element in a array using a variable stored in a session.params. Assuming that the value of 'array is [1, 2, 3] and that the value of index is 0

What I'm trying to do is this:

$session.params.array[$session.params.index]

What I would like to achieve is "1", instead I get "1, 2, 3[0]"

Thanks to everyone for the answer.





Olusayo Akinlaja

unread,
Feb 10, 2022, 5:40:21 PM2/10/22
to Dialogflow CX Edition users
I am not absolutely sure I understand your implementation or your use-case, please be sure to correct me if my understanding is wrong. I understand you are trying to reference parameter in your agent's static response for isList parameters in the format $session.params.parameter-id[i] where i is the index of the parameter[0]. 

From the information that I gathered, it seems this implementation is only possible with Dialogflow CX if you know the expected number of isList parameter. For an unknown number x list of isList parameter, you should use the webhook[1] to collect the parameters and return responses accordingly. I assume here that you do not know the list of the isList parameter, hence, the need to pass the $session.params.index as the index of the parameter. 

Loris Cino

unread,
Feb 21, 2022, 6:33:36 PM2/21/22
to Dialogflow CX Edition users
Thank you for the help. I really appreciated it.

Svetlana Pastukhova

unread,
Feb 22, 2022, 1:01:48 AM2/22/22
to Dialogflow CX Edition users
Please try to use the TO_TEXT system function and see if the following format would help:

$session.params.array[$sys.func.TO_TEXT($session.params.index)]

G. Hussain Chinoy

unread,
Feb 22, 2022, 1:04:20 AM2/22/22
to Dialogflow CX Edition users
Hi, there - 

Please try the $sys.func.TO_TEXT system function on the index to address a list with a parameter, i.e.

$session.params.array[$sys.func.TO_TEXT($session.params.index)]

H

Loris Cino

unread,
Jun 17, 2022, 12:55:45 PM6/17/22
to Dialogflow CX Edition users
Hi to everyone,

Sorry for the delay. Lately i found that google added a GET function to do that, so my solution is:

$sys.func.GET($session.params.array, $session.params.index)

Attention to NOT refer the parameters in the same page where is declared

Reply all
Reply to author
Forward
0 new messages