如何获取和使用确认“是"或“否"来进行 Alexa 技能意图响应 [英] How to get and use confirmation 'yes' or 'no' for Alexa skill intent response

查看:25
本文介绍了如何获取和使用确认“是"或“否"来进行 Alexa 技能意图响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一项 Alexa 技能,在启动时它会询问 您想执行某些操作吗?
根据用户的回复 'yes''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 model,它似乎可以达到目的.但我不确定如何实现它.

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.YesIntentAMAZON.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 技能意图响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆