Skip to Content
0
Mar 22, 2021 at 07:54 AM

Looping through a json array to show data as Custom message in CAI chatbot

245 Views Last edit Mar 22, 2021 at 07:54 AM 2 rev

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"
      }