关于列表卡片中的 select 的问题(对 google 的操作)
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!')
}
}
}
请帮帮我,
感谢拉米亚。
发送列表时,您为列表中的每个项目指定了一个 "option key"。这些键是将根据用户选择返回的字符串。如果您使用类似这样的方式发送列表
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',
}),
},
},
}));
});
那么您将拥有三个密钥:
- SELECTION_KEY_ONE
- SELECTION_KEY_GOOGLE_HOME
- SELECTION_KEY_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!')
}
}
}
我正在开发一个购物机器人,用户可以在其中询问产品,并且他们会从数据库中动态显示在列表卡中。 这里我的问题是如何获得用户在项目列表中选择的选项。附上我的控制台的代码和截图。
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!')
}
}
}
请帮帮我, 感谢拉米亚。
发送列表时,您为列表中的每个项目指定了一个 "option key"。这些键是将根据用户选择返回的字符串。如果您使用类似这样的方式发送列表
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',
}),
},
},
}));
});
那么您将拥有三个密钥:
- SELECTION_KEY_ONE
- SELECTION_KEY_GOOGLE_HOME
- SELECTION_KEY_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!')
}
}
}