- Newest
- Most votes
- Most comments
Guys, I solved the issue, the problem was with my lambda code, once I fixed that, it worked fine. here is the corrected Lambda Code:
import { DynamoDBClient, QueryCommand } from "@aws-sdk/client-dynamodb";
import { unmarshall } from "@aws-sdk/util-dynamodb";
const REGION = "us-east-1";
const dynamodbClient = new DynamoDBClient({ region: REGION });
export const handler = async (event) => {
console.log("EVENT: ", JSON.stringify(event, null, 2));
try {
const sessionState = event.sessionState || {};
const intent = sessionState.intent || {};
const slots = intent.slots || {};
const dateSlot = slots.Dates || {};
let appointmentDate = event.interpretations[0].intent.slots.NewAppointmentDate.value.interpretedValue;
console.log("AppointmentDate: ", appointmentDate);
const params = {
TableName: "ACME_Healthcare_Demo_Schedule",
KeyConditionExpression: "availableDates = :date",
ExpressionAttributeValues: {
":date": { S: appointmentDate }
}
};
const command = new QueryCommand(params);
const response = await dynamodbClient.send(command);
const items = response.Items.map((item) => unmarshall(item));
console.log('Data from ACME_Healthcare_Demo_Schedule: ', items);
// Extract unique available times for the given date
let availableTimesSet = new Set();
items.forEach(item => {
if (item.availableTimes) {
availableTimesSet.add(item.availableTimes);
}
});
// Convert Set to a comma-separated string
const availableTimesArray = Array.from(availableTimesSet);
const availableTimes = availableTimesArray.join(', ');
// Set available times as session attribute
sessionState.sessionAttributes = sessionState.sessionAttributes || {};
sessionState.sessionAttributes.availableTimes = availableTimes;
console.log("Availeble time: ", availableTimes);
return {
sessionState: {
sessionAttributes: sessionState.sessionAttributes || {},
dialogAction: {
type: "ElicitSlot",
slotToElicit: "appointmentTime"
},
intent: {
name: intent.name,
slots: slots
}
}
};
}
catch (error) {
console.error('Error querying DynamoDB', error);
return {
sessionAttributes: event.sessionState ? event.sessionState.sessionAttributes : {},
dialogAction: {
type: "Close",
fulfillmentState: "Failed",
message: {
contentType: "PlainText",
content: `There was an error retrieving available times. Please try again later.`
}
}
};
}
};
After updating the code, I worked. thanks All,
Hello,
Greetings! Hope you are doing good!
I understand that you are getting the below error from lambda while using Lex:
Invalid Lambda Response: Received invalid response from Lambda: Cannot construct instance of java.util.LinkedHashMap
(although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('slots').
You also have a lambda function which query DynamoDb table for available time and as the user enters the date Lambda function will add that available time to the session attribute.
I would like to inform you that in order to fetch more information regarding this issue and dive deep further I would suggest you to please raise a case with the AWS premium support and provide the following information on the case:
- Please share your bot .zip export so that we can replicate this issue on our end. please follow the link below to know more about exporting your bot [ https://docs.aws.amazon.com/lex/latest/dg/export-to-lex.html#export-console ]
- Region where your resources are present.
Relevant content
- Accepted Answerasked 2 years ago
- AWS OFFICIALUpdated 2 years ago