Api.ai Facebook Коммуникатор Интеграция карт и Carousel

голоса
1

Надеюсь, что вы, ребята, делаете хорошо!

Мне нужна помощь, чтобы получить api.ai facebook карусели на мой чате бот. Я не могу перебрать массив JSON, чтобы получить несколько карт с помощью Nodejs. Не могли бы вы, пожалуйста, руководство меня, чтобы сделать это Вот кусок кода.

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
});

Мне нужно перебрать cardResponses, чтобы получить многократное значение. В настоящее время cardResponses массив содержит 10 значений.

Помогите мне в этом.

Заранее спасибо.

Задан 09/09/2017 в 16:13
источник пользователем
На других языках...                            


1 ответов

Api.ai Facebook Коммуникатор Интеграция карт и Carousel

голоса
1

Надеюсь, что вы, ребята, делаете хорошо!

Мне нужна помощь, чтобы получить api.ai facebook карусели на мой чате бот. Я не могу перебрать массив JSON, чтобы получить несколько карт с помощью Nodejs. Не могли бы вы, пожалуйста, руководство меня, чтобы сделать это Вот кусок кода.

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
});

Мне нужно перебрать cardResponses, чтобы получить многократное значение. В настоящее время cardResponses массив содержит 10 значений.

Помогите мне в этом.

Заранее спасибо.

Ответил 09/09/2017 в 16:13
источник пользователем

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more