简体   繁体   English

Dialogflow webhook(Google上的操作)。 是否应该使用RichResponse?

[英]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.

相关问题 使用 Google 上的操作 SDK 获取 Dialogflow webhook 路径参数 - Getting Dialogflow webhook path parameters using Actions On Google SDK 使用Dialogflow在Google App上的主机操作在自托管HTTPS服务器上使用节点JS(MalformedResponse:Webhook错误(206)) - Host Actions On Google App With Dialogflow Using Node JS on Self Hosted HTTPS Server (MalformedResponse: Webhook error (206)) 为什么我应该在Google Node.js客户端库中的Actions中的actionsdk()之上使用dialogflow() - Why should I used dialogflow() over actionssdk() in Actions on Google Nodejs client Library cMalformedResponse:Webhook错误(206)同时看似有效的Webhook响应-Node.js中对Google Dialogflow应用的操作 - cMalformedResponse: Webhook error (206) whilst a seemingly valid webhook response - Actions on Google Dialogflow app in Node.js Dialogflow 中的任何 RichResponse 是否有可用的回调 - Is there callback available for any RichResponse in Dialogflow 在dialogflow的WebhookClient中使用Google上的轮播或列表操作时出错 - Error using actions-on-google Carousel or List with dialogflow's WebhookClient 如何使用 Google Actions Dialogflow 播放实时音频 stream - How to play live audio stream using Google Actions Dialogflow Google上的操作不起作用,但它们在dialogflow中起作用 - actions on google not working but they does in dialogflow 关于dialogflow的意图不会在Google的操作上更新 - Intents on dialogflow not updating on actions on google 在对话流中使用 webhook 创建实体而不使用对话流 UI - Create entities using webhook in dialogflow without using dialogflow UI
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM