javascript - Alexa Node js Lambda 函数给出响应 null

标签 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": {}
}

session 属性应该为空,响应应该包含 session 属性的内容,但情况恰恰相反。这是生成响应的代码。

 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)
          )
        )

关于javascript - Alexa Node js Lambda 函数给出响应 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48641763/

相关文章:

javascript - 访问 NodeJS 变量?

python - Lambda 错误 : no module found. Cryptography.hamtaz.bindings._constant_time

javascript - 为什么 'value' 的 Jquery 选择器在动态变化的情况下不起作用

javascript - 将左侧 div 垂直居中,同时保持右侧 div 标准

sql-server - 在 Windows 上将 ODBC 与 SQL Server 和 Node.js 结合使用的最简单方法

mysql - promise 自定义方法

node.js - 没有可用的 Nodejs 包。 Elastic Beanstalk 上的错误 : Nothing to do. Rails 应用程序

python-3.x - 如何使用 sqs 启动 ec2 实例并在实例中触发 python 脚本

c# - AWS Lambda 函数在第一次运行时有效,但在第二次运行时无效

javascript - 如何正确注册一个基本的渐进式网络应用服务 worker ?