AngryJS
AngryJS

Reputation: 955

Getting response from AWS Lambda function to AWS Lex bot is giving error?

I have created one AWS Lex bot and I am invoking one lambda function from that bot. When testing the lambda function I am getting proper response but at bot I am getting below error:

An error has occurred: Received invalid response from Lambda: Can not construct instance of IntentResponse: no String-argument constructor/factory method to deserialize from String value ('2017-06-22 10:23:55.0') at [Source: "2017-06-22 10:23:55.0"; line: 1, column: 1]

Not sure, what is wrong and where I am missing. Could anyone assist me please?

Upvotes: 1

Views: 6629

Answers (2)

thepurpleowl
thepurpleowl

Reputation: 146

no String-argument constructor/factory method to deserialize from String value

You are getting this error because you must be passing string values in the response of lambda function. You have to pass a predefined json object blueprint in the response.

Because the communication between Lex and Lambda is not simple value passing like normal functions. Amazon Lex expects output from Lambda in a particular JSON format and data is sent to Lambda in a particular JSON. The examples are here: Lambda Function Input Event and Response Format.

And just copying and pasting the blueprint won't work because in some fields you have choose between some predefined values and in some fields you have to entry valid input.

For example in,

"dialogAction": { "type": "Close", "fulfillmentState": "Fulfilled or Failed", "message": { "contentType": "PlainText or SSML", "content": "Thanks, your pizza has been ordered." } }

you have assign a value "Fulfilled" or "Failed" to field 'fulfillmentState'. And same goes for 'contentType'.

Upvotes: 2

AngryJS
AngryJS

Reputation: 955

The solution to above problem is that we need to make sure response returned by lambda function, to be used at AWS lex chat bot should be in below format:

{
"sessionAttributes": {
"key1": "value1",
"key2": "value2"
...
 },
  "dialogAction": {
"type": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close",
Full structure based on the type field. See below for details.
}
}

By this, chat bot expectd DialogAction and corresponding elements in order to process the message i.e. IntentResponse.

Reference: http://docs.aws.amazon.com/lex/latest/dg/lambda-input-response-format.html

Upvotes: 2

Related Questions