如何获得和使用Alexa技能意图响应的确认``是''或``否''

编程入门 行业动态 更新时间:2024-10-07 14:28:35
本文介绍了如何获得和使用Alexa技能意图响应的确认``是''或``否''的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在开发一项Alexa技能,该技能在启动时会询问您要执行某些操作吗? 根据用户的答复,'是'或'no',我要启动另一个意图.

I am developing a Alexa skill in which on launch it will ask Do you want to perform something ? Depending upon user's reply 'yes' or 'no' I want to launch another intent.

var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.emit(':responseReady'); }, "SomethingIntent": function () { //Launch this intent if the user's response is 'yes' } };

我确实看过了 dialog模型,看来它将达到目的.但是我不确定如何实现.

I did have a look at dialog model and it seems that it will serve the purpose. But I am not sure how to implement it.

推荐答案

执行此技能所需的最简单方法是处理 AMAZON.YesIntent 和熟练掌握AMAZON.NoIntent (请确保也将其添加到交互模型中):

The simplest way to do what you're looking for from the skill, is to handle the AMAZON.YesIntent and AMAZON.NoIntent from your skill (make sure to add them to the interaction model as well):

var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.emit(':responseReady'); }, "AMAZON.YesIntent": function () { // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below this.emit('SomethingIntent'); }, "AMAZON.NoIntent": function () { // handle the case when user says No this.emit(':responseReady'); } "SomethingIntent": function () { // handle the "Something" intent here } };

请注意,在更复杂的技能中,您可能必须存储一些状态才能弄清楚用户是否针对您关于是否做某事"的问题发送了是"意图.您可以使用会话对象.例如:

Note, that in a more complex skill you might have to store some state to figure out that the user sent a 'Yes' intent in response to your question as to whether to "do something". You can save this state using the skill session attributes in the session object. For instance:

var handlers = { 'LaunchRequest': function () { let prompt = this.t("ASK_FOR_SOMETHING"); let reprompt = this.t("LAUNCH_REPROMPT"); this.response.speak(this.t("WELCOME_MSG") + ' ' + prompt).listen(reprompt); this.attributes.PromptForSomething = true; this.emit(':responseReady'); }, "AMAZON.YesIntent": function () { if (this.attributes.PromptForSomething === true) { // raise the `SomethingIntent` event, to pass control to the "SomethingIntent" handler below this.emit('SomethingIntent'); } else { // user replied Yes in another context.. handle it some other way // .. TODO .. this.emit(':responseReady'); } }, "AMAZON.NoIntent": function () { // handle the case when user says No this.emit(':responseReady'); } "SomethingIntent": function () { // handle the "Something" intent here // .. TODO .. } };

最后,您还可以使用对话框界面就像您在问题中提到的那样,但是如果您要做的只是从启动请求中获得一个简单的是/否"确认作为提示,那么我认为上面的示例很容易实现.

Finally, you could also look into using the Dialog Interface as you alluded to in your question but if all you're trying to do is get a simple Yes/No confirmation as a prompt from the launch request than I think my example above would be pretty straight forward to implement.

更多推荐

如何获得和使用Alexa技能意图响应的确认``是''或``否''

本文发布于:2023-11-28 03:10:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1640731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:意图   如何获得   技能   Alexa

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!