Amazon Lex Integration into AWS Lambda
我使用 Alexa Skills Kit 已经有一段时间了,我的代码部署在用 Node Js 编写的 AWS Lambda 中。现在我想通过 amazon Lex 服务将聊天机器人集成到其中。这样我就可以使用 Amazon Alexa 和 Amazon lex 来控制我的设备。我的问题是,如果我在 Amazon Lex 中使用与我在 Alexa Skill 中相同的意图和插槽名称,AWS Lambda 代码是否可以开箱即用?还是我必须修改 AWS Lambda 代码以适应 AWS Lex?
您必须适应 Lex 和 Alexa 之间的差异。最显着的区别是请求和响应格式。
需要注意的显着差异:
在与他们两人合作了很多并且经常处理这个问题之后,我更喜欢 Lex 而不是 Alexa。我发现 Lex 更简单,并为开发人员提供更多的自由和控制,即使您必须遵守 Lex 的每个输出通道的限制。
比较请求/响应格式:
Alexa JSON 格式
Lex JSON 格式
示例 Alexa 请求:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | { "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 请求:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | { "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" } } |