Alexa 会话保持打开状态,无需任何用户输入
Alexa session remains open without any user input
我有一个 Alexa 技能,用户提出问题并发出适当的响应。示例:
网友:哪个州的首都是哈里斯堡?
Alexa:宾夕法尼亚
我使用询问意图来实现此目的(会话保持活动状态),但在提交我的技能时收到回复说会话在没有任何用户输入的情况下保持打开状态。
我不想结束会话。我希望用户能够不断地提问。处理此问题的最佳方法是什么?
我想通过在每个答案的末尾添加一个问题来实现这一点。示例:
网友:哪个州的首都是哈里斯堡?
Alexa:宾夕法尼亚州。还有什么可以帮您的吗?
上面的问题是我不确定如何处理 Yes/No 回复。
如有任何帮助,我们将不胜感激。
您建议的修复是合理的,并且是 Alexa 技能中的一个常见模式——Alexa 支持内置意图 AMAZON.YesIntent
和 AMAZON.NoIntent
,它们已经被配置为监听一组相关的话语,例如"yes"、"no" 等。对于“是”的意图,您可能想再次 :ask
并提出类似 "What question would you like to ask?" 的问题,而对于“否”的意图,您可能想要:tell
用户再见,使用 tell 将结束会话。
状态管理
就是说,您不希望 Alexa 总是以这种方式回复 'Yes'——如果您的技能有其他交互,而您对这个问题的 'Yes' 的回复却没有说得通?
要解决这个问题,请查看 alexa-sdk 中的 skill state management。来自文档:
Alexa-sdk use state manager to route the incoming intents to the correct function handler. State is stored as a string in the session attributes indicating the current state of the skill. You can emulate the built-in intent routing by appending the state string to the intent name when defining your intent handlers, but alexa-sdk helps do that for you.
因此,当您的 alexa 技能回答问题时,您的部分响应逻辑可以设置如下状态:
this.handler.state = 'AskAnotherQuestion';
对于像 AskAnotherQuestion
这样的状态字符串,您可以使用:
1。字面意思
向名为 AMAZON.YesIntentAskAnotherQuestion
的意图处理程序添加一个条目,以处理 YesIntent 的是响应,并按字面附加状态。
示例:
'AMAZON.YesIntentAskAnotherQuestion': function() {
this.emit(':ask', 'What would you like to ask?', 'Could you repeat that?');
},
2。 Alexa-SDK 状态处理器
使用 alexa-sdk CreateStateHandler(state, obj)
创建一个意图处理程序,将传递的状态附加到所有条目。
示例:
const askQuestionHandlers = Alexa.CreateStateHandler('AskAnotherQuestion', {
'AMAZON.YesIntent': function() {
this.emit(':ask', 'What would you like to ask?', 'Could you repeat that?');
},
'AMAZON.NoIntent': function() {
this.emit(':tell', 'See you later!');
}
// NOTE: Add another intent here that routes to your question answering logic,
// so that the user can just immediately ask their question again without
// saying yes or no.
}
有关 CreateStateHandler 的代码完整示例实现,请参阅 skill state management 文档。
卡瓦茨
如果不在 YesIntent 中设置其他状态,此技能将停留在 'AskAnotherQuestion' 状态。对于您问题中定义的范围,这可能没问题,但请记住,随着您的技能变得更加复杂,您可能希望切换到其他状态。
将状态重置为 null 或空目前很麻烦,需要设置多个字段。可以在 github issue.
中找到对此的讨论和建议的解决方法
进一步阅读
这个帖子 How to keep an alexa skill open? 似乎是同一主题,也符合我的经验。在 Alexa 关闭您的技能之前,您可以保持会话打开的最长时间为 ~10 到 20 秒。
我有一个 Alexa 技能,用户提出问题并发出适当的响应。示例:
网友:哪个州的首都是哈里斯堡? Alexa:宾夕法尼亚
我使用询问意图来实现此目的(会话保持活动状态),但在提交我的技能时收到回复说会话在没有任何用户输入的情况下保持打开状态。
我不想结束会话。我希望用户能够不断地提问。处理此问题的最佳方法是什么?
我想通过在每个答案的末尾添加一个问题来实现这一点。示例:
网友:哪个州的首都是哈里斯堡? Alexa:宾夕法尼亚州。还有什么可以帮您的吗?
上面的问题是我不确定如何处理 Yes/No 回复。
如有任何帮助,我们将不胜感激。
您建议的修复是合理的,并且是 Alexa 技能中的一个常见模式——Alexa 支持内置意图 AMAZON.YesIntent
和 AMAZON.NoIntent
,它们已经被配置为监听一组相关的话语,例如"yes"、"no" 等。对于“是”的意图,您可能想再次 :ask
并提出类似 "What question would you like to ask?" 的问题,而对于“否”的意图,您可能想要:tell
用户再见,使用 tell 将结束会话。
状态管理
就是说,您不希望 Alexa 总是以这种方式回复 'Yes'——如果您的技能有其他交互,而您对这个问题的 'Yes' 的回复却没有说得通?
要解决这个问题,请查看 alexa-sdk 中的 skill state management。来自文档:
Alexa-sdk use state manager to route the incoming intents to the correct function handler. State is stored as a string in the session attributes indicating the current state of the skill. You can emulate the built-in intent routing by appending the state string to the intent name when defining your intent handlers, but alexa-sdk helps do that for you.
因此,当您的 alexa 技能回答问题时,您的部分响应逻辑可以设置如下状态:
this.handler.state = 'AskAnotherQuestion';
对于像 AskAnotherQuestion
这样的状态字符串,您可以使用:
1。字面意思
向名为 AMAZON.YesIntentAskAnotherQuestion
的意图处理程序添加一个条目,以处理 YesIntent 的是响应,并按字面附加状态。
示例:
'AMAZON.YesIntentAskAnotherQuestion': function() {
this.emit(':ask', 'What would you like to ask?', 'Could you repeat that?');
},
2。 Alexa-SDK 状态处理器
使用 alexa-sdk CreateStateHandler(state, obj)
创建一个意图处理程序,将传递的状态附加到所有条目。
示例:
const askQuestionHandlers = Alexa.CreateStateHandler('AskAnotherQuestion', {
'AMAZON.YesIntent': function() {
this.emit(':ask', 'What would you like to ask?', 'Could you repeat that?');
},
'AMAZON.NoIntent': function() {
this.emit(':tell', 'See you later!');
}
// NOTE: Add another intent here that routes to your question answering logic,
// so that the user can just immediately ask their question again without
// saying yes or no.
}
有关 CreateStateHandler 的代码完整示例实现,请参阅 skill state management 文档。
卡瓦茨
如果不在 YesIntent 中设置其他状态,此技能将停留在 'AskAnotherQuestion' 状态。对于您问题中定义的范围,这可能没问题,但请记住,随着您的技能变得更加复杂,您可能希望切换到其他状态。
将状态重置为 null 或空目前很麻烦,需要设置多个字段。可以在 github issue.
中找到对此的讨论和建议的解决方法进一步阅读
这个帖子 How to keep an alexa skill open? 似乎是同一主题,也符合我的经验。在 Alexa 关闭您的技能之前,您可以保持会话打开的最长时间为 ~10 到 20 秒。