alexa-skills-kit - 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 个组关联。你想知道它们是什么吗?
并期望一个YES
or NO
。如果答案是“是”,则 alexa 将控件从Intent-A移动到Intent-B,编号为 19588,在 Intent-B 内部,它会执行其余操作并最终输出这些组的名称。
自过去 3 天以来,我一直在努力寻找解决方案,并且也搜索了很多。但是还没有找到任何可以准确解决这种情况的答案。
请问有什么建议吗?我是 Alexa 技能开发的新手。
解决方案
使用会话数据。
存储您希望其他意图使用的值。例如:
在 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
变量以提出正确的问题,并期望用户说“是”或“否”。
我希望这会有所帮助。请让我知道这个答案是否帮助您继续前进,如果您发现更多问题。
推荐阅读
- android - 获取谷歌地图中所有标记的位置
- c - 在没有 NUL 终止字符串的情况下编写缓冲区溢出漏洞
- python - 在 Python 中的运费计算器代码中出现错误
- css - 如何在 WordPress.org 中使用 @font-face?
- windows - 在屏幕上移动窗口
- android - 复杂 ListView 项中的 TextView 文本颜色因设备而异
- r - 创建新变量,该变量为 0,直到另一个变量的第一个非 NA 值,然后为 1(在组内)
- node.js - npm 命令:找不到模块 npm-cli.js
- mysql - 获取聚合查询结果
- php - 206.2 kB(加载 204.8 kB)在 LONGBLOB 值前