I have a Lex bot with a single intent, I have added multiple slots. in these slot I have builtin slot with the name "AppointmentDate" with a prompt "Which day would you like". I am using a Lambda to validate the "APpointmentDate" slot value which I have a hardcoded in the Lambda "2024-05-22". If the user entered the Same hardcoded Date then the lambda will return the prompt "Sorry, no appointment available on that day, chose another day" then the user will enter another date and the lex will continue to another slot.
So my question here is that how to invoke lambda at "AppointmentDate" slot only?
Is the Lambda Code correct or according to the format of Lex?
export const handler = async (event) => {
console.log("Event", JSON.stringify(event));
const inputText = event.inputTranscript;
if ((inputText)) {
// Assuming AppointmentDate is a slot
const appointmentDate = event.currentIntent.slots.AppointmentDate;
// Check if the appointment date is a specific value
if (appointmentDate === '2024-05-09') {
return {
dialogAction: {
type: 'Close',
fulfillmentState: 'Failed',
message: { contentType: 'PlainText', content: 'I’m sorry, I do not have availability on that day. Can you please try another day?' }
}
};
} else {
// If the appointment date is not the specific value, proceed to the next slot
return {
dialogAction: {
type: 'Delegate',
slots: event.currentIntent.slots
}
};
}
} else {
return {
dialogAction: {
type: 'Delegate',
slots: event.currentIntent.slots
}
};
}
};