0

我正在使用 ask-sdk 版本 2.3.0

const SessionEndedRequest = {
    canHandle(handlerInput) {
        const request = handlerInput.requestEnvelope.request;
        return request.type === 'SessionEndedRequest'
    }, 
    handle(handlerInput) {
        return handlerInput.responseBuilder.speak("Good bye").withShouldEndSession(true).getResponse();
    }
};


const skillBuilder = Alexa.SkillBuilders.custom();

exports.handler = skillBuilder
  .addRequestHandlers(
    LaunchRequest, 
    SessionEndedRequest
  )
  .lambda();

SessionEndedRequest 是当用户说“停止”或“取消”时执行的函数

用户说“取消”时的输出

{
    "body": {
        "version": "1.0",
        "response": {
            "outputSpeech": {
                "type": "SSML",
                "ssml": "<speak>Good bye</speak>"
            },
            "shouldEndSession": true,
            "type": "_DEFAULT_RESPONSE"
        },
        "sessionAttributes": {},
        "userAgent": "ask-node/2.3.0 Node/v8.10.0"
    }
}

Alexa的回应是这样的

请求的技能响应有问题

4

1 回答 1

1

收到 SessionEndedRequest 后,您无法返回任何语音、卡片或指令的响应,SessionEndedRequestHandler 是放置清理逻辑的好地方。它通常有这种形式(注意它发送一个空响应):

const SessionEndedRequestHandler : RequestHandler = {
      canHandle(handlerInput : HandlerInput) : boolean {
        return handlerInput.requestEnvelope.request.type === 'SessionEndedRequest';
      },
      handle(handlerInput : HandlerInput) : Response {
        console.log(`Session ended with reason: ${(handlerInput.requestEnvelope.request as SessionEndedRequest).reason}`);

        return handlerInput.responseBuilder.getResponse();
      },
    };

如果您想在“取消”或“停止”之后说些什么,您需要为AMAZON.CancelIntent和/或实现处理程序AMAZON.StopIntent

于 2019-02-19T10:18:06.730 回答