1

我使用 Alexa Skills Kit 已经有一段时间了,我的代码部署在用 Node Js 编写的 AWS Lambda 中。现在我想通过 amazon Lex 服务将聊天机器人集成到其中。这样我就可以使用 Amazon Alexa 和 Amazon lex 来控制我的设备。我的问题是,如果我在 Amazon Lex 中使用与我在 Alexa Skill 中相同的意图和插槽名称,AWS Lambda 代码是否可以开箱即用?或者我是否必须修改 AWS Lambda 代码以适应 AWS Lex?

4

1 回答 1

1

您必须适应 Lex 和 Alexa 之间的差异。最显着的区别是请求和响应格式。

需要注意的显着差异:

  1. sessionAttribtues和 的格式和传递之间的主要区别slots
  2. Lex 有 4 个内置的slotTypesAlexa 不使用(还没有?): AMAZON.EmailAddress,AMAZON.PercentageAMAZON.PhoneNumberAMAZON.SpeedUnitAMAZON.WeightUnit. (参考。
  3. Lex 总是通过inputTranscript. 亚历克斯没有。
  4. Alexa 提供resolutions槽值,但用从输入中提取的原始数据填充实际槽值。
  5. 如果您设置了同义词,Lex 将自动解析槽值slotType

在与他们两人合作了很多并且经常处理这个问题之后,我更喜欢 Lex 而不是 Alexa。我发现 Lex 更简单,并为开发人员提供了更多的自由和控制,即使您必须遵守 Lex 的每个输出通道的限制。

比较请求/响应格式:

Alexa JSON 格式
Lex JSON 格式

示例 Alexa 请求:

{
  "version": "1.0",
  "session": {
    "new": true,
    "sessionId": "amzn1.echo-api.session.[unique-value-here]",
    "application": {
      "applicationId": "amzn1.ask.skill.[unique-value-here]"
    },
    "attributes": {
      "key": "string value"
    },
    "user": {
      "userId": "amzn1.ask.account.[unique-value-here]",
      "accessToken": "Atza|AAAAAAAA...",
      "permissions": {
        "consentToken": "ZZZZZZZ..."
      }
    }
  },
  "context": {
    "System": {
      "device": {
        "deviceId": "string",
        "supportedInterfaces": {
          "AudioPlayer": {}
        }
      },
      "application": {
        "applicationId": "amzn1.ask.skill.[unique-value-here]"
      },
      "user": {
        "userId": "amzn1.ask.account.[unique-value-here]",
        "accessToken": "Atza|AAAAAAAA...",
        "permissions": {
          "consentToken": "ZZZZZZZ..."
        }
      },
      "apiEndpoint": "https://api.amazonalexa.com",
      "apiAccessToken": "AxThk..."
    },
    "AudioPlayer": {
      "playerActivity": "PLAYING",
      "token": "audioplayer-token",
      "offsetInMilliseconds": 0
    }
  },
  "request": {}
}

示例 Lex 请求:

{
  "currentIntent": {
    "name": "intent-name",
    "slots": {
      "slot name": "value",
      "slot name": "value"
    },
    "slotDetails": {
      "slot name": {
        "resolutions" : [
          { "value": "resolved value" },
          { "value": "resolved value" }
        ],
        "originalValue": "original text"
      },
      "slot name": {
        "resolutions" : [
          { "value": "resolved value" },
          { "value": "resolved value" }
        ],
        "originalValue": "original text"
      }
    },
    "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)"
  },
  "bot": {
    "name": "bot name",
    "alias": "bot alias",
    "version": "bot version"
  },
  "userId": "User ID specified in the POST request to Amazon Lex.",
  "inputTranscript": "Text used to process the request",
  "invocationSource": "FulfillmentCodeHook or DialogCodeHook",
  "outputDialogMode": "Text or Voice, based on ContentType request header in runtime API request",
  "messageVersion": "1.0",
  "sessionAttributes": { 
     "key": "value",
     "key": "value"
  },
  "requestAttributes": { 
     "key": "value",
     "key": "value"
  }
}
于 2019-03-19T13:30:12.620 回答