Alexa技能:如何使用JOVO将价值从一种意图传递到另一种意图

时间:2019-06-24 08:24:06

标签: alexa-skills-kit

我具有以下意图结构:

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()return this.toIntent("intent_name"),在alexa输出某些东西后,又如何使用当前意图中的值,如何导航用户到另一个意图?

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

  

用户19588与5个组相关联。你想知道他们   是吗?

,并且期望为YESNO。 如果答案为“是”,那么alexa会使用19588将控件从 Intent-A 移至 Intent-B ,在Intent-B内执行其余操作,最后输出名称这些团体。

自最近三天以来,我一直在努力寻找解决方案,并且Google搜索量也很多。但是找不到任何解决这种情况的答案。

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

1 个答案:

答案 0 :(得分:2)

使用会话数据。

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

在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
},

看看WMT '14 English to German translation task

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

我希望这会有所帮助。请告诉我这个答案是否有助于您前进,以及是否发现更多问题。