首页 > 解决方案 > 使用 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();  
   },
};

任何帮助将不胜感激。

标签: amazon-web-services

解决方案


我的第一个建议是.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

我希望它会帮助你!


推荐阅读