alexa - 如何结束自定义 Alexa 技能的会话?
问题描述
我正在为 Alexa 创建自定义技能。我想关闭会话AMAZON.StopIntent
。我怎样才能用下面的代码实现这一点?
const ExitHandler = {
canHandle(handlerInput) {
const request = handlerInput.requestEnvelope.request;
return request.type === 'IntentRequest'
&& (request.intent.name === 'AMAZON.StopIntent');
},
handle(handlerInput) {
return handlerInput.responseBuilder
.speak('bye!')
.reprompt('bye!')
.getResponse();
},
};
解决方案
当响应 JSON 中的shouldEndSession标志设置为 true时,Alexa 结束会话。
...
"shouldEndSession": true
...
在您的响应构建器中,您可以尝试使用辅助函数withShouldEndSession(true)
return handlerInput.responseBuilder
.speak('bye!')
.withShouldEndSession(true)
.getResponse();
此处列出了响应构建器辅助函数
推荐阅读
- mysql - 有条件地删除mysql中的最后一行
- javascript - 如何创建带有随机数的数组?
- java - Java - 摆脱硬编码
- datagrid - devexpress 在数据网格单元格中显示标签框数据
- html - 已启用 已禁用 根据先前的下拉菜单选择选项?
- c# - 未找到 microsoft.ui.xaml
- reactjs - 无法在已删除部分中获取表格项目
- azure-devops - 在 Azure YAML Devops Pipelines 中管理依赖项
- excel - excel vba方法addpicture有时不起作用
- javascript - 使用 post 方法更新循环的进度条