如何使用 JOVO 将价值从一个意图发送到另一个意图?

问题描述 投票:0回答:2

我有以下意图结构:

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个群组。你想知道他们是什么吗 是?

并期待

YES
NO
。 如果答案是“是”,Alexa 会将控件从 Intent-A 移动到 Intent-B(19588),在 Intent-B 中它会执行其余操作,并最终输出这些组的名称。

有什么建议吗?

alexa-skills-kit
2个回答
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
},

看看这个

现在,当您使用

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


1
投票

实际上,如果您使用状态,您甚至不需要“保存”数据。

您可以通过以下方式“访问它”:

let person = this.$inputs.*<PARAMETER1>*.value; //Change PARAMETER1 for the name of the parameter used on your model. 

这是一个例子:

 numberOneIntent(){
    
    return this.toStateIntent('awesomeState', 'numberTwoIntent');
}
   

我假设您知道如何在此 numberOneIntent 上使用您的模型询问/要求参数

awesomeState: {

      numberTwoIntent(){

      let person = this.$inputs.person.value;

      let amount = this.$inputs.amount.value;

      console.log("congrats, you got your data from numberOneIntent");
    
      this.tell("yada yada");

    }
}
© www.soinside.com 2019 - 2024. All rights reserved.