Skip to content

Invoking Lambda at specific Lex-Bot Slot instead of whole intent

0

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
            }
        };
    }
};

1 Answer
0

Have a look at this example lambda. In it you can see examples of validations of slot values. https://github.com/aws-samples/amazon-lex-v2-lambdahook-for-booktripbot/blob/main/lambda_function.py

AWS
answered 2 years ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.