Search code examples
amazon-web-servicesdialogaws-lambdaalexa-skills-kitslot

multi-turn dialog slots confirmation in alexa skill?


I wrote thsi code for individual slot confirmation in lambda.But, this doesn't work.Only it will call name slot not qualification slot.

// Confirm slot: name
                if(intentObj.slots.name.name == "name") {
                    if (intentObj.slots.name.confirmationStatus !== 'CONFIRMED') {
                        if (intentObj.slots.name.confirmationStatus !== 'DENIED') {
                            // slot status: unconfirmed
                            const slotToConfirm = 'name';
                            const speechOutput = 'Your name is ' + intentObj.slots.name.value + ', is that right?';
                            //  const repromptSpeech = speechOutput;
                            this.emit(':confirmSlot', slotToConfirm, speechOutput);
                        } else {
                            // slot status: denied => ask again
                            const slotToElicit = 'name';
                            const speechOutput = 'What is your name?';
                            //const repromptSpeech = 'Please tell me what is your name';
                            const updatedIntent = 'DialogIntent';
                            this.emit(':elicitSlot', slotToElicit, speechOutput, updatedIntent);
                        }
                    }
                }

            // Confirm slot: qualification
            if(intentObj.slots.qualification.qualification == "qualification") {
                    if (intentObj.slots.qualification.confirmationStatus !== 'CONFIRMED') {
                        if (intentObj.slots.qualification.confirmationStatus !== 'DENIED') {
                            // slot status: unconfirmed
                            const slotToConfirm = 'qualification';
                            const speechOutput = 'Your qualification is ' + intentObj.slots.qualification.value + ', is that right?';
                            //  const repromptSpeech = speechOutput;
                            this.emit(':confirmSlot', slotToConfirm, speechOutput);
                        } else {
                            // slot status: denied => ask again
                            const slotToElicit = 'qualification';
                            const speechOutput = 'What is your qualification?';
                            //const repromptSpeech = 'Please tell me what is your qualification';
                            const updatedIntent = 'DialogIntent';
                            this.emit(':elicitSlot', slotToElicit, speechOutput, updatedIntent);
                        }
                    }
                }

please share any information about the slots confirmation.


Solution

  • Your first slot's if statement will always come out as true.

    if(intentObj.slots.name.name == "name") { ... }

    This is because the slots.slotName.name will always be the slot's name. It's a useless if statement.
    You probably want to check if the slot is set and the value is not null. Then you can change your logic a bit.

    if(intentObj.slots.name && intentObj.slots.name.value !== null) { 
        // check if confirmed or not
    } else {
        // elicit slot "name"
    }
    

    Your second slot's if statement will always be false.

    if(intentObj.slots.qualification.qualification == "qualification") {

    This is because there is no qualification key in the slots.slotName array. So just change it to be similar to the one above, checking if the qualification slot is set and the value is not null.

    if(intentObj.slots.qualification && intentObj.slots.qualification.value !== null) { 
        // check if confirmed or not
    } else {
        // elicit slot "qualification"
    }