Paulo Jade Rivera
Paulo Jade Rivera

Reputation: 31

Received invalid response from Lambda: Can not construct instance of IntentResponse

I have been trying out the lambda codehook on aws lex and this what the response that I'll be returning looks like

response = {
            "dialogAction" : {
                "type": "ElicitSlot",
                "message": {    
                    "contentType": "PlainText",
                    "content": "Please make enter value of slot1 first before proceeding."
                },
              "intentName": "AWSLexIntentName",
              "slots": {
                    "slot1" : null,
                    "slot2" : null,
                    "slot3" : null,
                    "slot4" : null,
                    "slot5" : null
              },
              "slotToElicit" : "slot1"
            }
        }

I've already tried testing it using the lambda test events but when trying it out on Lex I keep getting the error

An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Can not construct instance of IntentResponse, problem: The validated object is null at [Source: {}; line: 1, column: 2]

I'm still new to amazon web services and don't have that much knowledge in programming all in all but I can't trace back this error since this is "Source" key isn't found in any of my code or the amazon documentation. Also thanks for taking your time reading this.

Upvotes: 2

Views: 4044

Answers (2)

vineet
vineet

Reputation: 14236

I was getting the same error. So, the issue with me is that I used lex v2 but used lex v1 response format. The lex v2 has a different response format i.e,

{
  "sessionState": {
    "dialogAction": {
      "type": "Close | ConfirmIntent | Delegate | ElicitIntent | ElicitSlot"
    },
    "intent": {
      "confirmationState": "Confirmed",
      "name": "IntentName",
      "state": "Failed | Fulfilled | InProgress | ReadyForFulfillment",
      
    },
    
  },
  "messages": [
    {
      "contentType": "PlainText",
      "content": "Select from the list",
      
    }
  ]
}

for more details aws lex v2 response

Upvotes: 4

Paulo Jade Rivera
Paulo Jade Rivera

Reputation: 31

Okay so I figured out why the Lex bot is not getting any value. Inside my lambda handler I am receiving a promise from a function that resolves the response that I need. Inside the handler I am receiving this resolve by using the promise.then(data, function(){//do stuff}) and inside the then function I am returning the value of data which contains the response.

This results into the handler returning a undefined value so what I did is that instead of returning I am using the callback functionality of lambda.

Sorry if the explanation is confusing as I am also confused why and to how this works.

Upvotes: 1

Related Questions