Alexa Node js Lambda 函数给出响应 null

Alexa Node js Lambda Function is giving response null

我正在返回来自 Nodejs Lambda 函数的响应,并给出这样的空白响应:

{
  "version": "1.0",
  "sessionAttributes": {
    "outputSpeech": {
      "type": "PlainText",
      "text": "Welcome to Alexa Skill"
    },
    "shouldEndSession": true
  },
  "response": {}
}

会话属性应为空白,响应应包含会话属性的内容,但它恰好相反。这是生成响应的代码。

 context.succeed(
              buildResponse(
                buildSpeechletResponse("Welcome to Alexa Skill", true),
                {}
              )
            )

这些是辅助函数:

function buildSpeechletResponse(outputText, shouldEndSession) {
    return {
        outputSpeech: {
            type: "PlainText",
            text: outputText
        },
        // card: {
        //     type: "Simple",
        //     title: title,
        //     content: output
        // },
        // reprompt: {
        //     outputSpeech: {
        //         type: "PlainText",
        //         text: repromptText
        //     }
        // },
        shouldEndSession: shouldEndSession
    };
}

function buildResponse(sessionAttributes, speechletResponse) {
    return {
        version: "1.0",
        sessionAttributes: sessionAttributes,
        response: speechletResponse
    };

只需注意 buildResponse 辅助方法中的参数顺序。你正在反向传递它。只需更改如下。

context.succeed(
          buildResponse({},
            buildSpeechletResponse("Welcome to Alexa Skill", true)
          )
        )