Displaying values correctly from Json array // bot dialog

hello,
I’m building a new bot and I’m executing a customer API to get some customer information via JSON post.
My problem is that when displaying the data the values are showed with brackets [DATA] into the conversation dialog

How can I take the brackets out as is being displayed that way as in the attached image.

I’m doing for example result .document[0].value and is displaying the number into brackets [4557788], I wanted to display with no bracket since I need this value to execute another API.

thanks in advance

Hi @dtorres265

Welcome to the Freshworks developer community!

Can you check if the API response itself returns data inside brackets?

To remove brackets from your data you can use data.replace(/[\[\]]+/g, '');

Hope this helps.

Regards,
Mughela Chandresh

1 Like

There is some information that I am not able to put together, @dtorres265

Are you working with the bots module in Freshdesk or Freshservice or Freshchat? If you could point me to the right support article that can also be helpful.

Based on your topic being created in the “App Category”, if you have an opportunity to modify incoming data then you can use the following:

hello Saif,
I’m working with the freshchat bot module, and the response from the API is with no brackets, but when I use this value into a dialog it’s represented with brackets like this [value]
The only thing that I can do as far as I saw is to use a split but has some limitations. So if I can do that on the api library section will be great and I’m not sure if I can use data.replace in there as I do not have a way to do that in there.
thanks!

@dtorres265 At a glimpse, this looks like you are calling .toString() on an Array. I am not sure if I understand the issue clearly. Can you share the payload that you receive from the bots API call (redacting any sensitive information)?

hello,
thanks for your reply

this is what is being received on the payload
hope somebody can help me as I was not able to resolve this so far.

thank you

@dtorres265 I am not familiar with building Freshworks bots. I was hoping to see the API response from the customer API. The screenshot you have shared does not show the response payload clearly.

Can you share the response that you receive after making a call using Postman or a similar tool (or any public documentation for the customer API)?

It will help further if you can point out which fields in the response are used in the bot.

Hi @dtorres265

From your screen shot, I believe you are selecting the response parameters from an array from the API response and therefore its coming with in bot flow.

In order to select elements from response which are of type array, please use following syntax. In the example below, I want to select the first group of 4th agents in my API response.

image

This is then rendered properly i.e as a string
image

if I directly select it using + sign after the variable it will be like as below;

then it will rendered in brackets like below;
image

3 Likes

Hello Sachin, that worked thank you very much for your response.
DT

1 Like

hello Sachin,
I was replacing all the fields to be displayed with no array quotes and all are fine but some of them are not displayed for some unknown reason.
As you can see in the image I have a field called inicio which is date so I’m doing result.0.inicio but is not being displayed. Works well if I do result.inicio, the weird thing is that result.0.fin which is also date is coming correctly.
any ideas?
thanks again

Hi Dario,

This sounds weird and ideally should not be the case. However I am guessing that something got cached in config which happens sometimes.
Try removing the response parameter from api library → Save the flow - >close the flow
and
then open the flow again → select the parameter again and use it in your flow.

1 Like

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.