Charan Kumar
Charan Kumar

Reputation: 55

How to handle lambda responses to Amazon Lex?

I want to store the inputs given in Amazon Lex Chatbot in Amazon DynamoDB via Lambda Integration. How to handle the Responses from Amazon Lambda. I am receiving the error as - ( An error has occurred: Invalid Lambda Response: Received invalid response from Lambda: Unexpected token (END_OBJECT), expected FIELD_NAME: missing property 'type' that is to contain type id (for class DialogAction) at [Source: {"dialogAction":{"Type":"Close","fulfillmentState":"failed","message":{"ContentType":"PlainText","Content":"Hey null, Your Requested nullTickets on null at null"}}}; line: 1, column: 164] )

Kindly help on this. My Amazon Lambda Code is as below,

exports.handler = (event, context, callback) => {

var Name = event.currentIntent.slots.Name;
var TicketType = event.currentIntent.slots.TicketType;
var BookingDate = event.currentIntent.slots.BookingDate;
var BookingTime = event.currentIntent.slots.BookingTime;
callback(null, {
    "dialogAction": {
        "Type":"Close",
        "fulfillmentState": "failed",
        "message": {
            "ContentType": "PlainText",
            "Content":  "Hey " +Name+ ",  Your Requested "+ TicketType + "Tickets on " +BookingDate+" at " +BookingTime+"" ,
        }
    }

})

}

Upvotes: 2

Views: 776

Answers (1)

omuthu
omuthu

Reputation: 6333

The below is the typical response for Lex from Lambda.

There is a typo in "type", please have it in lowercase ("type" instead of "Type")

{
    "sessionAttributes": {
    "key1": "value1",
    "key2": "value2"
    ...
  },
  "recentIntentSummaryView": [
    {
       "intentName": "Name",
       "checkpointLabel": "Label",
       "slots": {
         "slot name": "value",
         "slot name": "value"
        },
       "confirmationStatus": "None, Confirmed, or Denied (intent confirmation, if configured)",
        "dialogActionType": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close",
        "fulfillmentState": "Fulfilled or Failed",
        "slotToElicit": "Next slot to elicit
    }
  ],
  "dialogAction": {
    "type": "ElicitIntent, ElicitSlot, ConfirmIntent, Delegate, or Close",
    Full structure based on the type field.
  }
}

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

Upvotes: 2

Related Questions