app.intent('Our Events', (conv) =>{
if (!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
conv.ask(getdata());
conv.ask('Events are here!');
});
function getdata()
{
let carouselItems ={};
var events = db.collection('events').get().then(snapshot =>{
snapshot.forEach(doc=>{
let itemdetails ={
title:doc.data().title,
description:doc.data().info,
image: new Image({
url:doc.data().image_url,
alt:'Image',
}),
};
carouselItems[doc.id]=itemdetails;
console.log(carouselItems[doc.id]);
});
});
return new Carousel({
title:'Our Events',
items: carouselItems,
});
}
答案 0 :(得分:0)
轮播是视觉选择响应,它们需要唯一的密钥才能被识别。因此,您必须为所有轮播项目对象提供选择键。就您而言,似乎您将没有键的对象添加到数组。
请检查以下示例,并尝试根据结构创建对象。
items: {
// Add the first item to the carousel
'SELECTION_KEY_ONE': {
synonyms: [
'synonym 1',
'synonym 2',
'synonym 3',
],
title: 'Title of First Carousel Item',
description: 'This is a description of a carousel item.',
image: new Image({
url: 'IMG_URL_AOG.com',
alt: 'Image alternate text',
}),
},
// Add the second item to the carousel
'SELECTION_KEY_GOOGLE_HOME': {
synonyms: [
'Google Home Assistant',
'Assistant on the Google Home',
],
title: 'Google Home',
description: 'Google Home is a voice-activated speaker powered by ' +
'the Google Assistant.',
image: new Image({
url: 'IMG_URL_GOOGLE_HOME.com',
alt: 'Google Home',
}),
},
// Add third item to the carousel
'SELECTION_KEY_GOOGLE_PIXEL': {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: 'Google Pixel',
description: 'Pixel. Phone by Google.',
image: new Image({
url: 'IMG_URL_GOOGLE_PIXEL.com',
alt: 'Google Pixel',
}),
},
},
}));
答案 1 :(得分:0)
您的函数需要重写,以便您的意图处理程序知道该操作是异步的。请注意,还添加了async
和await
关键字,这些关键字将在给定命令完成时通知解释器。
app.intent('Our Events', async (conv) =>{
if (!conv.surface.capabilities.has('actions.capability.SCREEN_OUTPUT')) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
conv.ask(await getdata());
conv.ask('Events are here!');
});
async function getdata() {
let carouselItems ={};
const snapshot = db.collection('events').get()
snapshot.forEach(doc=>{
let itemdetails ={
title:doc.data().title,
description:doc.data().info,
image: new Image({
url:doc.data().image_url,
alt:'Image',
}),
};
carouselItems[doc.id]=itemdetails;
console.log(carouselItems[doc.id]);
});
return new Carousel({
title:'Our Events',
items: carouselItems,
});
}