使用 Node.js 设置 Alexa AppId

Setting Alexa AppId using Node.js

我在使用服务模拟器测试我的 Alexa 技能时遇到困难。如果我设置了 appId,该技能将不起作用。这是相关代码:

'use strict';
const Alexa = require('alexa-sdk');

var APP_ID = "amzn1.ask.skill.[my skill ID]";

exports.handler = function(event, context, callback) {
    var alexa = Alexa.handler(event, context);
    alexa.appId = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
}

当我在服务模拟器中 运行 此代码时,我在 CloudWatch 日志中得到响应 "The remote endpoint could not be called, or the response it returned was invalid." 和错误消息:

The applicationIds don't match: applicationId and amzn1.ask.skill.[my skill id]
"errorMessage": "Invalid ApplicationId: amzn1.ask.skill.[my skill id]"

如果我注释掉设置 appId

//alexa.appId = APP_ID

模拟器似乎 return 有效响应,但我在日志中看到此警告:

"Warning: Application ID is not set."

这是模拟器发送的 Lambda 请求:

{
  "session": {
    "sessionId": "SessionId.bb263d3e-2018-4aab-a0df-f945b3a25bf9",
    "application": {
      "applicationId": "amzn1.ask.skill.[my skill ID]"
    },
    "attributes": {},
    "user": {
      "userId": "amzn1.ask.account.[accountID]"
    },
    "new": true
  },
  "request": {
    "type": "LaunchRequest",
    "requestId": "EdwRequestId.d8b56c7f-63ea-48e8-8816-9b7c036d5816",
    "locale": "en-US",
    "timestamp": "2017-07-12T12:06:11Z"
  },
  "version": "1.0"
}

一些在线示例建议 appId 属性 应该是 APP_ID:

alexa.APP_ID = APP_ID; 

但这似乎不正确。根据 alexa-sdk 源代码(并尝试它),属性 需要它是我实现的 appId。

看起来问题与亚马逊模拟器创建的 json lambda 请求更相关。需要说明的是,这是Amazon Alexa 开发者门户上的模拟器,而不是AWS lambda 测试事件接口上的测试功能。

奇怪的是,如果我从 Amazon 模拟器剪切并粘贴 lambda 请求并从 AWS 测试界面运行它,它工作正常。

我这两天也遇到了这个问题。我相信这是他们的最终问题。我在亚马逊论坛上看到了这个。

Amazon changed something over the weekend which affects the JSON request received by Lambda from the simulator and breaks verification. Here are two threads regarding this, which include workarounds to allow it to work:

https://forums.developer.amazon.com/questions/78391/application-id-verification-issue-with-nodejs-and.html

https://forums.developer.amazon.com/questions/78393/my-alexa-skill-is-not-returning-a-lambda-response.html

So far there has been no update from Amazon, or even an acknowledgment of the issue.

--- GadgetChannel