1

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.

  • By any chance is it possible that the response being returned is empty? – Paulo Jade Rivera Jul 11 '19 at 02:31
  • Can you show how you are returning that response? The callback may take 2 parameters, the first being an error, the second being the response. So a common mistake is to call the callback and only provide the response, which is sent as the error, and the actual response parameter is empty. – Jay A. Little Jul 15 '19 at 08:05
  • I am not using callback. I've been returning it as a json file. – Paulo Jade Rivera Jul 16 '19 at 08:25
  • It looks like using callbacks solved it since I've been using promises so instead of the return statement returning it to the Lex bot it's been returning it to another then() statement. Thanks. – Paulo Jade Rivera Jul 16 '19 at 08:27
  • Ok follow up question, how do I close this thread? – Paulo Jade Rivera Jul 16 '19 at 08:28
  • It may be helpful to others, so you can write the details of what you did to fix the problem in an answer to your own question. Then you can mark that answer as correct by clicking on a green check that will appear next to your own answer. You get points for doing that, and anyone who finds this Q&A helpful will upvote it, giving you more points. Welcome to Stack Overflow! – Jay A. Little Jul 17 '19 at 03:05
  • Done, sorry if its confusing I'm still not used to sharing insights on my codes. – Paulo Jade Rivera Jul 17 '19 at 07:53

2 Answers2

3

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

vineet
  • 13,832
  • 10
  • 56
  • 76
  • 1
    It worked and I was struggling from last 2 days to get this AWS lex v2 syntax in response object. Thanks again – Srikrishna Mar 23 '22 at 00:49
1

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.