Amazon web services Amazon Lex与AWS Lambda的集成

Amazon web services Amazon Lex与AWS Lambda的集成,amazon-web-services,aws-lambda,alexa,aws-lex,Amazon Web Services,Aws Lambda,Alexa,Aws Lex,我使用Alexa Skills Kit已经有一段时间了,我的代码部署在用Node Js编写的AWS Lambda中。现在我想通过AmazonLex服务将聊天机器人集成到其中。因此,我能够使用Amazon Alexa和Amazon lex控制我的设备。我的问题是,如果我在AmazonLex中使用与我在Alexa技能中相同的意图和插槽名称,AWS Lambda代码是否会开箱即用?或者我必须修改AWS Lambda代码以适应AWS Lex?您必须适应Lex和Alexa之间的差异。最显著的区别是请求和响

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

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

应注意的显著差异:
  • sessionattribtue
    slot
    的格式和传递之间的主要差异
  • Lex有4个内置的
    slotTypes
    ,Alexa还没有使用:
    AMAZON.EmailAddress、
    AMAZON.Percentage
    AMAZON.PhoneNumber
    AMAZON.SpeedUnit
    AMAZON.WeightUnit
    。()
  • Lex总是通过
    inputTranscript
    传递完整的用户输入。Alexa没有
  • Alexa为插槽值提供
    分辨率
    ,但使用从输入中提取的原始数据填充实际插槽值
  • 如果为该
    slotType
    设置了同义词,则Lex将自动解析插槽值
  • 在和他们一起工作了很多次,并且经常处理这个问题之后,我更喜欢莱克斯而不是亚历克斯。我发现Lex更简单,提供了更多的开发人员自由和控制,即使您必须遵守Lex的每个输出通道的限制

    比较请求/响应格式:

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