首页 > 解决方案 > Alexa Skills:如何使用 JOVO 将价值从一个意图发送到另一个意图

问题描述

我有以下意图结构:

async ContactIntent() {
   const contact_id = this.$inputs.contactid.value;
   // Contact detail is fetched from API

   // if this contact is associated with any group
   // ask user whether he wants to know about the groups
   // expected answers could either be YES or NO.
   // if YES, I like to jump to ContactGroupIntent intent with
   // present contact_id
   this.ask('User 19588 is associated with 5 groups. Do you want to know what they are? Say YES or NO.')
},

async ContactGroupIntent() {
   // when called directly
   const contact_id = this.$inputs.contactid.value;
   // or I want to grab the id sent from ContactIntent after user says YES

   // API fetches contact groups and outputs the same

},

'AMAZON.YesIntent': function() {
  // Do I need to do something here?
},

'AMAZON.NoIntent': function() {
},

我正在使用 JOVO 框架来构建技能。

问题是: 1. 如何在不丢失任何状态的情况下将值从一个意图传递到另一个意图 2. 由于我不能同时使用this.ask()and return this.toIntent("intent_name"),如何在 alexa 输出某些内容后将用户导航到另一个意图,以及我拥有的值当前意图?

示例: Intent-A的值为 19558 具有上述 ID 的联系人与 5 个不同的组相关联。Alexa是否可能输出如下内容:

用户 19588 与 5 个组关联。你想知道它们是什么吗?

并期望一个YESor NO。如果答案是“是”,则 alexa 将控件从Intent-A移动到Intent-B,编号为 19588,在 Intent-B 内部,它会执行其余操作并最终输出这些组的名称。

自过去 3 天以来,我一直在努力寻找解决方案,并且也搜索了很多。但是还没有找到任何可以准确解决这种情况的答案。

请问有什么建议吗?我是 Alexa 技能开发的新手。

标签: alexa-skills-kit

解决方案


使用会话数据。

存储您希望其他意图使用的值。例如:

在 Intent-A 中,将值 19588 作为会话数据的一部分存储在其中,并提出一个问题,以便用户回答“是”或“否”。

this.$session.$data.user_number = 19588
this.$speech = 'User 19588 is associated with 5 groups. Do you want to know what they are?'
this.$reprompt = 'Sorry I could not hear you, Do you want to know what they are?'
this.ask(this.$speech, this.$reprompt)

如果用户说“是”,AMAZON.YesIntent 将被触发,所以

'AMAZON.YesIntent': function() {
    let user_number = this.$session.$data.user_number
    // perform all the appropriate verifications here and do the rest you need to do
},

看看这个

现在,当您使用麦克风时this.ask(),麦克风将保持打开状态,等待用户输入,因此请容纳speechreprompt变量以提出正确的问题,并期望用户说“是”或“否”。

我希望这会有所帮助。请让我知道这个答案是否帮助您继续前进,如果您发现更多问题。


推荐阅读