amazon-web-services - 使用 aws-sdk2 时如何在启动请求后保持会话活动
问题描述
这是我用于 lambda 函数的代码片段,但我使用的是 sdk v2。当我运行它时,该技能在启动请求后立即超时。
我已经尝试.keepSession()
过.listen()
const LaunchRequestHandler = {
canHandle(handlerInput) {
return handlerInput.requestEnvelope.request.type==='LaunchRequest';
},
handle(handlerInput) {
const speakOutput = 'Hello,Welcome to DXC\'s google.How may I help you?';
return handlerInput.responseBuilder
.speak(speakOutput) // The text passed to speak, is what Alexa will say.
.getResponse();
},
};
//asks for employee id
const EmployeeIdIntentHandler = {
canHandle(handlerInput) {
console.log(handlerInput.requestEnvelope.request.intent.name);
return handlerInput.requestEnvelope.request.type === 'IntentRequest'
&& handlerInput.requestEnvelope.request.intent.name === 'EmployeeIdIntent'
},
handle(handlerInput) {
const speakOutput = 'Please tell me your employee id';
return handlerInput.responseBuilder
.speak(speakOutput) // The text passed to speak, is what Alexa will say.
.getResponse();
},
};
任何帮助将不胜感激。
解决方案
我的第一个建议是.reprompt(REPROMPT_MESSAGE)
在 LaunchRequest 处添加一个来提醒用户回答。您也可以尝试添加
return handlerInput.responseBuilder
.speak(speakOutput)
.withShouldEndSession(false)
.getResponse();
我通常在需要关闭会话时使用它(参数中为 true)。
您可以在文档中找到更多信息: https ://developer.amazon.com/es/docs/custom-skills/request-and-response-json-reference.html#response-format
我希望它会帮助你!
推荐阅读
- git - 使用 Git 合并二进制文件时,有没有办法让 Difftool 询问是否只合并其中一个文件?
- javascript - D3线由多段组成
- php - RatchetPHP - 客户端在收到来自服务器的消息之前立即与服务器断开连接
- c# - C# HttpClient 请求 HTTPS 异常错误
- android - Android Volley StringRequest 有时会提供空婴儿车
- javascript - 如何从一个网页播放音乐并从另一个网页停止
- python - pyplot,为什么不显示 x 轴?
- reactjs - 反应,风格与 if inside
- pandas - 使用 Pandas 在每个 PeriodIndex 中选择最旧的行
- python - 如何使用python获取行簇