【问题标题】:How to get and use confirmation 'yes' or 'no' for Alexa skill intent response如何为 Alexa 技能意图响应获取和使用确认“是”或“否”
【发布时间】:2018-09-10 07:26:06
【问题描述】:

我正在开发一项 Alexa 技能,在启动时它会询问 Do you want to perform something ?
根据用户的回复'yes''no' 我想启动另一个意图。

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,它似乎可以达到目的。但我不确定如何实现它。

【问题讨论】:

  • 我会说在启动集状态期间使用状态来处理是或否作为开始,然后为是或否添加基于会话的处理程序。

标签: amazon-web-services aws-lambda alexa alexa-skills-kit alexa-skill


【解决方案1】:

从技能中寻找所需的最简单方法是处理技能中的AMAZON.YesIntentAMAZON.NoIntent(确保也将它们添加到交互模型中):

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
  }
};

请注意,在更复杂的技能中,您可能需要存储一些状态来确定用户是否发送了“是”意图以响应您关于是否“做某事”的问题。您可以使用session object 中的技能会话属性保存此状态。例如:

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 ..
  }
};

最后,您还可以考虑使用Dialog Interface,正如您在问题中提到的那样,但如果您想要做的只是从启动请求中获得一个简单的“是/否”确认作为提示,那么我认为我的上面的例子很容易实现。

【讨论】:

  • 我为我的用例尝试了这种方法,但它并没有完全按照我需要的方式工作。我的“SomethingIntent”具有填充与意图相关联的插槽的逻辑,但“SomethingIntent”内部的请求上下文来自 YesIntent 用户话语事件。因此,当尝试访问“SomethingIntent”处理程序中的this.event.request.intent.slots 时,插槽未定义。我什至无法通过在 YesIntent 上定义插槽来解决这个问题。我还询问了亚马逊开发团队,他们说这只是内部完成意图转发工作方式的一个限制。
猜你喜欢
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 2023-01-21
  • 1970-01-01
  • 1970-01-01
  • 2017-08-15
  • 2019-01-23
  • 1970-01-01
相关资源
最近更新 更多