on 03-22-2021 7:54 AM
I have been trying to loop through a json array and show data in the form of list using custom message but I have been getting an error Message added is not a valid JSON.
{
"type": "list",
"content": {
"elements": [
{{#eachJoin api_service_response.default.body.d.results}}
{
"title": "{{Incident_No}}",
"imageUrl": "",
"description": "{{Incident_Title}}",
"buttons": [
{
"title": "Details",
"value": "{{Incident_No}}",
"type": "postback"
}
]
}{{/eachJoin}}
]
}
}
{
"level": "warning",
"code": "W_EXECUTE_ACTION",
"data": {
"type": "message",
"value": {
"invalid_json": "{\"type\":\"script\",\"content\":\"{\n \"type\": \"list\",\n \"content\": {\n \"elements\": [\n {{#eachJoin api_service_response.default.body.d.results}}\n {\n \"title\": \"{{Incident_No}}\",\n \"imageUrl\": \"\",\n \"description\": \"{{Incident_Title}}\",\n \"buttons\": [\n {\n \"title\": \"Details\",\n \"value\": \"{{Incident_No}}\"\n }\n ]\n }{{/eachJoin}}\n ]\n }\n}\",\"messageType\":\"MessageList\",\"isContentStateEdited\":true,\"delay\":null}",
"scripting_enabled": false
},
"message": "Message added is not a valid JSON"
},
"timestamp": "2021-03-22T05:49:36.100Z"
}
Are you sure you are referring to the results of your API correctly? I took your exact code, changing only to use Northwind service, and it worked perfectly. How are you defining the API call in the chatbot? What does the call return?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is being returned by the api call.
I believe there is an issue with the actual data. If I use only the incident number, it works, but if I use the incident title, it does not. I assume this is because the incident title has some texts like this:
"During Filling of product \"Duoz Respules\" Bottelpack Machine 460 M. (Make Rommelag) moves in Unsterile mode."
and this is messing up the JSON. Depending on what you want to happen, you will need to encode the data or parse it.
I literally cut and pasted your code, but then simply did not use the title field:
{
"type": "list",
"content": {
"elements": [
{{#eachJoin api_service_response.default.body.d.results}}
{
"title": "{{Incident_No}}",
"imageUrl": "",
"description": "{{Incident_No}}",
"buttons": [
{
"title": "Details",
"value": "{{Incident_No}}",
"type": "postback"
}
]
}{{/eachJoin}}
]
}
}
Can you show how you defined the "External API" in your action, including the response tab?
You can escape the title and it will work, though not 100% sure it will be what you want:
"description": "{{escape Incident_Title}}",
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.