Alexa Node js Lambda函数给出响应null

时间:2018-02-06 11:17:31

标签: javascript node.js aws-lambda alexa alexa-skill

我正在返回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
    };

1 个答案:

答案 0 :(得分:1)

只需在buildResponse帮助方法中查看参数顺序即可。你正在反过来传递它。只需更改如下。

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