Api.ai Facebook Messenger Integration for cards and Carousel

300 views Asked by At

Hope you guys are doing good !

I need a help to get api.ai facebook carousel to my chat bot. I am unable to iterate over the json array to get the multiple cards using Nodejs. Could you please guide me to get it done Here is the piece of code.

function(results){

var cardResponses = [];
for(var i=0;i<results.length;i++){

var richResponses = {

'facebook': {
'attachment': {
'type': 'template',
'payload': {
'template_type': 'generic',
'elements': [
  {
    'title': results[i].ItemAttributes.Title,
    'image_url': results[i].MediumImage.URL,
    'subtitle': "INR 250",

    'buttons': [
      {
        'type': 'web_url',
        'url': results[i].DetailPageURL,
        'title': 'Shop Now '
      }
    ]
  }
]
}
}
}
}
cardResponses.push(richResponses);

}
// need to get the response in object form to pass on data field of res.json

res.json({
speech : “hi this is response”,
displayText: “This is from API.AI”,
data: cardResponses
});

I need to iterate over cardResponses to get the multiple value. Currently cardResponses Array contains 10 values.

Help me on this.

Thanks in Advance.

0

There are 0 answers