amazon-web-servicesaws-lambdaaws-lex

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.


Solution

  • 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.