gpt4 book ai didi

actions-on-google - 在 actions-on-google Nodejs v2 中构建列表

转载 作者:行者123 更新时间:2023-12-04 09:00:34 24 4
gpt4 key购买 nike

我可能遗漏了一些非常明显的东西,但我还没有想出如何在 tne actions-on-google Nodejs 客户端库的 v2 中以编程方式构建列表。

换句话说,我想做类似下面的conv.ask代码的事情,但事先不知道项目,所以需要创建一个列表,将项目添加到列表中,然后动态询问列表方式。我可以在 v1 中使用:

var rList = app.buildList("Please select one option:");
for (var r =0; r < resp_text.length; r++) {
rList.addItems(app.buildOptionItem(resp_value[r], resp_matches[r]).setTitle(resp_text[r]));
}
app.askWithList(question_str, rList);

...所以我基本上是在寻找与上述等价的 v2。

感谢任何帮助,谢谢!

conv.ask(new List({
title: 'Things to learn about',
items: {
// Add the first item to the list
'MATH_AND_PRIME': {
synonyms: [
'math',
'math and prime',
'prime numbers',
'prime',
],
title: 'Title of the First List Item',
description: '42 is an abundant number',
image: new Image({
url: 'https://example.com/math_and_prime.jpg',
alt: 'Math & prime numbers',
}),
},
// Add the second item to the list
'EGYPT': {
synonyms: [
'religion',
'egypt',
'ancient egyptian',
],
title: 'Ancient Egyptian religion',
description: '42 gods ruled on the fate of the dead in the afterworld',
image: new Image({
url: 'http://example.com/egypt',
alt: 'Egypt',
}),
},
// Add the last item to the list
'RECIPES': {
synonyms: [
'recipes',
'recipe',
'42 recipes',
],
title: '42 recipes in 42 ingredients',
description: 'A beautifully simple recipe',
image: new Image({
url: 'http://example.com/recipe',
alt: 'Recipe',
}),
},
},
}));

最佳答案

好吧,回答我自己的问题以防它能帮助别人......

做到这一点的方法(或至少一种方法)是动态创建一个项目数组并在列表构造函数中使用它:

 var ritems = {}
for (var r=0; r < resp_text.length; r++) {
ritems[resp_value[r]] = {
synonyms: [resp_matches[r]],
title: resp_text[r]
}
}
conv.ask(question_str);
conv.ask(new List({
title: "Please select one option:",
items: ritems
}))

关于actions-on-google - 在 actions-on-google Nodejs v2 中构建列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50222662/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com