1

I have been working with Alexa Skills Kit for some time now with my code deployed in AWS Lambda written in Node Js. Now i want to integrate chatbots into it via the amazon Lex service. So that i am able to control my device using both Amazon Alexa and Amazon lex. My question was that if i use the same intent and slots name in Amazon Lex as i have did in my Alexa Skill would the AWS Lambda code just work out of the box? Or would i have to modify the AWS Lambda code to accommodate the AWS Lex?

Muneeb Rehman
  • 135
  • 2
  • 10

1 Answers1

1

You will have to accommodate for the differences between Lex and Alexa. The most notable differences are the request and response formats.

Notable differences to be aware of:

  1. Major differences between the formats and passing of sessionAttribtues and slots.
  2. Lex has 4 built-in slotTypes that Alexa does not use (yet?): AMAZON.EmailAddress,, AMAZON.Percentage, AMAZON.PhoneNumber, AMAZON.SpeedUnit, and AMAZON.WeightUnit. (Reference.)
  3. Lex always passes the full user input through inputTranscript. Alexa does not.
  4. Alexa provides resolutions for slot values but fills the actual slot value with the raw data extracted from the input.
  5. Lex will automatically resolve a slot value if you have synonyms set for that slotType.

After working with both of them quite a lot, and often dealing with this, I much prefer Lex to Alexa. I have found Lex to be simpler and provides more developer freedom and control, even though you do have to conform to the restrictions of each of Lex's output channels.

Compare Request / Response Formats:

Alexa JSON format
Lex JSON format

Example Alexa Request:

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

Example Lex 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"
  }
}
Jay A. Little
  • 3,239
  • 2
  • 11
  • 32