[英]Dialogflow webhook (Actions on Google). Should I be using RichResponse or not?
Reading through the documentation for Actions on Google, I've built a browse carousel by using a rich response class and supplying it with a simple response, the carousel and some suggestion chips. 通读Google Actions的文档,我通过使用丰富的响应类并为它提供了简单的响应,轮播和一些建议芯片,构建了一个浏览轮播。
const carouselItems = [];
items.forEach(item => {
const carouselItem = new BrowseCarouselItem({
description: item.description.text,
image: new Image({
alt: item.title,
url: item.image,
}),
url: item.link,
title: item.title,
})
carouselItems.push(carouselItem)
});
conv.ask(new RichResponse({
items: [{
simpleResponse: new SimpleResponse("the simple response message"),
carouselBrowse: new BrowseCarousel({
items: [ browseCarouselItem1, browseCarouselItem2 ],
}),
}],
suggestions: ["suggestion1", "suggestion2"]
});
After spending time doing this, I discovered that the rich response class appears to be unnecessary. 在花了一些时间之后,我发现丰富的响应类似乎是不必要的。 In fact, I can get the same result by using conv.ask()
three times in a row instead. 实际上,我可以连续三遍使用conv.ask()
来获得相同的结果。
conv.ask("the simple response message");
conv.ask(new BrowseCarousel({
items: [ browseCarouselItem1, browseCarouselItem2 ]
}));
conv.ask(new Suggestions([ "suggestion1", "suggestion2" ]);
With this discovery, I find myself uncertain of the correct approach. 有了这个发现,我发现自己不确定正确的方法。 Does one of these methods replace the other? 这些方法中的一种可以替代另一种吗? What is the best practice? 最佳做法是什么? I've used RichResponse
a few times throughout my webhook and I'm now unsure if I am working with an obsolete class. 我在整个RichResponse
都使用过RichResponse
,但现在不确定我是否正在使用过时的课程。
It is not "obsolete", but it is unnecessary. 它不是“过时的”,但是它是不必要的。 The standard practice is to call ask()
multiple times and have the library build the RichResponse
object for you. 标准做法是多次调用ask()
并让该库为您构建RichResponse
对象。 But the library does use it internally, so it isn't obsolete. 但是库确实在内部使用它,因此它不是过时的。
When I use the actions-on-google library, I prefer to use the multiple ask()
since I don't have to use all of them. 当我使用Google Actions-on-Google库时,我更喜欢使用多个ask()
因为我不必全部使用它们。 I can include some of them in different blocks depending on what features were available or what responses may be appropriate. 我可以根据可用的功能或适当的响应将它们中的一些包含在不同的块中。
Use whatever works best for you. 使用最适合您的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.