[英]Issue regarding the did select in the list card(actions on google)
我正在开发一个购物机器人,用户在其中询问产品,并且他们从数据库动态地显示在列表卡中。 这里我的问题是如何获得用户在项目列表中选择的选项。 附上我的控制台的代码和屏幕截图。
function did_select(conv, input, option)
{
console.log("option",conv);
const param = conv.getArgument('OPTION');
console.log("param",param);
for(var i = 0;i<=temparray1.length;i++)
{
if (option === temparray1[i]) {
conv.close('Number one is a great choice!')
}
}
}
请帮帮我,Thnx Ramya。
当您发送列表时,您为列表中的每个项目指定了一个“选项键”。 这些键是将根据用户选择的内容发回的字符串。 如果您使用这样的方式发送列表
app.intent('List', (conv) => {
if (!conv.screen) {
conv.ask('Sorry, try this on a screen device or select the ' +
'phone surface in the simulator.');
return;
}
conv.ask('This is a list example.');
// Create a list
conv.ask(new List({
title: 'List Title',
items: {
// Add the first item to the list
'SELECTION_KEY_ONE': {
synonyms: [
'synonym 1',
'synonym 2',
'synonym 3',
],
title: 'Title of First List Item',
description: 'This is a description of a list item.',
image: new Image({
url: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Image alternate text',
}),
},
// Add the second item to the list
'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: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Google Home',
}),
},
// Add the third item to the list
'SELECTION_KEY_GOOGLE_PIXEL': {
synonyms: [
'Google Pixel XL',
'Pixel',
'Pixel XL',
],
title: 'Google Pixel',
description: 'Pixel. Phone by Google.',
image: new Image({
url: 'https://storage.googleapis.com/actionsresources/logo_assistant_2x_64dp.png',
alt: 'Google Pixel',
}),
},
},
}));
});
那么你将拥有三个键:
其中之一将在处理程序方法的option
参数中返回给您。 所以你的处理程序可能看起来像
var temparray1 = [
'SELECTION_KEY_ONE',
'SELECTION_KEY_GOOGLE_HOME',
'SELECTION_KEY_GOOGLE_PIXEL'
];
function did_select(conv, input, option)
{
console.log("option",option);
for(var i = 0;i<=temparray1.length;i++)
{
if (option === temparray1[i]) {
conv.close('Number '+(i+1)+' is a great choice!')
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.