Using Yes/No Intents with Dialog Management
Justin Jeffress Apr 06, 2018
Share:
Dialog Management Tutorial
Blog_Header_Post_Img

The AMAZON.YesIntent and AMAZON.NoIntent are useful for handling a “yes” or “no” utterance while improving dialog accuracy and creating more natural voice-first experiences. If your skill requires multiple "yes" or "no" confirmations from your user, it would be difficult to correlate which intent the user's confirmation is fulfilling due to the overlap in utterances. To resolve a particular intent from the respective "yes" confirmation, a mechanism would need to be built out to handle it. To solve this, you need to add the Amazon.YesIntent to your model and define an intent handler for it. You also need to keep track of what yes-no question your skill asked the customer so you can programmatically route the customer to the correct intent.

This post will walk you through a typical yes-no scenario and how these intents relate to dialog management.

The Many Meanings of “Yes” and “No”

In everyday conversation, we often encounter yes-no questions. For example, if you're shopping for a smartphone at your preferred retailer, the conversation might go something like:

Jason: I want the latest greatest smartphone and I want it in black.

Sales Associate: Did you want the 128 or 256 gigabyte version?

Jason: 256 gigabytes please.

Sales Associate: You wanted the 256 gigabyte version?
                           
Jason: Yes.


The Sales Associate goes to the back, gets the 256 gigabyte black smartphone, and returns.
                          
Sales Associate: Here is your brand new, latest and greatest, 256 gigabyte black smartphone. Is there anything else I can help you find today?

Jason: No, thanks.

Jason walks to the cash register.

Cashier: Did you want to add the extended warranty for 200 dollars?

Jason: No, thanks.

Cashier: The total for the 256 gigabyte version with no warranty comes to 1000 dollars and 34 cents. Will that be all today?

Jason: Yes.
   
After paying Jason walks to the front of the store.

Greeter: Thanks you for shopping with us today, would you like to take a customer satisfaction survey?
   
Jason: Yes.

Greeter: On a scale of 1 to 5, where 1 is the lowest and 5 is the highest, how would you rate the overall cleanliness of the store?

Each conversation between Jason and the store employees results in an outcome. The conversation with the sales associate results with the brand new, latest and greatest, 256 gigabyte black smart phone in his shopping cart. The conversation with the cashier ends up with Jason's wallet $1,000.34 lighter without the extended warranty. If Jason had said "yes" to the greeter he would have been asked a series of questions about his shopping experience. Let's think of each outcome as an intent and map them to the speaker:

Sales Associate = PutItemIntoCartIntent
Cashier = CheckoutIntent
Greeter = SurveyIntent

For our skill, Alexa will take on the role of sales associate, cashier, and greeter, and Jason is the user.

Where do the AMAZON.YesIntent and AMAZON.NoIntent fit into this scenario? We are going to use AMAZON.YesIntent to handle the “yes” response to "Thank you for shopping with us today, would you like to take a customer satisfaction survey?" by starting the survey asking the first question. When the customer answers the question, the utterance will resolve to the SurveyIntent, which is also managed by dialog management to capture each answer to the survey.

Types of Yes-No Questions

Before I get into the different intents, let’s identify a few different types of yes-no questions. "You wanted the 256 gigabyte version?" is a slot confirmation. If the answer is no, the customer will need to follow up and recorrect the misunderstanding in order to fill the slot with the correct value. "Did you want to add the extended warranty for 200 dollars?" is a yes-no question. Based on the customer's choice, the total balance will either increase or stay the same and it's relevant only to the CheckoutIntent and it fills a slot with a yes or no. "The total for the 256 gigabyte version with no warranty comes to 1,000 dollars and 34 cents. Will that be all today?" is an intent confirmation. The cashier is implicitly confirming that the customer is ready to make their purchase. A "yes" in this situation will finalize the CheckoutIntent. Last, "Thanks you for shopping with us today, would you like to take a customer satisfaction survey?" is a yes-no question that can either launch a survey consisting of multiple questions or the greeter could notify the customer that the instructions to take the survey are on the back of the receipt.

As you can see, there are several types of yes-no questions. Depending on the context of the conversation, the way we handle “yes” and “no” responses will differ. Now let's take a look at each intent.

PutItemIntoCartIntent

PutItemIntoCartIntent is a conversation managed by dialog management that manages the conversation that the customer has with the sales associate to put the smartphone they want into their shopping cart. The required slots are recency, specifications, color, and storageCapacity. The customer fills the first three slots with "I want the latest (recency = latest) greatest (specifications = max) smartphone and I want it in black (color = black)." Since the storageCapacity slot hasn't been filled, the skill will delegate slot collection back to Alexa. Once filled, the slot is confirmed by asking, "You wanted the 256 gigabyte version?"

At the end of the dialog, the skill will state what is about to be put into the cart with an Intent Confirmation. "Here is your brand new latest and greatest 256 gigabyte black smartphone. Is there anything else I can help you find today?"

Since PutItemIntoCartIntent is managed my dialog management, all “yes” and “no” utterances will be handled by PutItemIntoCartIntent and NOT the AMAZON.YesIntent and AMAZON.NoIntent.

In a physical store, the customer would line up at the cash register to pay. From our skill the customer will need to communicate that they desire to check out and pay for their items, so we'll have the CheckoutIntent handle the checkout process.

CheckoutIntent

The CheckoutIntent is also managed by dialog management. It needs to capture the wantsExtendedWarranty slot and receive an intent confirmation before making the charge.

The wantsExtendedWarranty slot will determine if the warranty is added to price, which we are going to add at the end of our interaction, so we want to capture “yes” and “no” into the wantsExtendedWarranty slot. We can achieve that with a custom slot type called, yesNoType where the values and synonyms are:

Copied to clipboard
{
    "name": "yesNoType",
    "values": [
        {
            "name": {
                "value": "yes",
                "synonyms": [
                    "yep",
                    "yeah",
                    "I do",
                    "yes please",
                    "you know it"
                ]
            }
        },
        {
            "name": {
                "value": "no",
                "synonyms": [
                    "nope",
                    "I do not",
                    "no thank you"
                ]
            }
        }
    ]
}

When the customer says, "yes" the yesNo slot will be filled with yes. Before finalizing the transaction, the CheckoutIntent will seek an intent confirmation.

Copied to clipboard
'CheckOutIntent': function () {
    let speechOutput = '';

    let filledSlots = delegateSlotCollection.call(this);

    if (!filledSlots) {
        return;
    }

    let slots = getSlotValues(filledSlots);

    console.log('filled slots: ', slots);

    speechOutput = 'Thank you for shopping with us. ';
    let question = 'Would you like to take a survey?';

    this.response.speak(speechOutput + question);
    this.response.listen(question);
    this.emit(':responseReady'); 
}

Like the PutItemIntoCart intent, the CheckoutIntent is managed by dialog management, so the “yes” and “no” responses will not be handled by Amazon.YesIntent and AMAZON.NoIntent. They will be handled by the CheckoutIntent.

The intent confirmation can be defined either in your voice user interface or programmatically from your lambda function using this.emit(':confirmIntent', speechOutput, reprompt);

Upon checking out, the skill will ask the customer if they want to start survey.

SurveyIntent

The SurveyIntent can be invoked in two ways. It can be invoked if the customer says, "take a survey," but when the customer has finished checking out, the CheckoutIntent prompts the customer to take the survey by asking, "Thank you for shopping with us today. Would you like to take a customer satisfaction survey?" If the customer says, "yes" the AMAZON.YesIntent will be invoked.

Copied to clipboard
'AMAZON.YesIntent': function () {
    let speechOutput = 'On a scale of one to five where one is the lowest and five is the highest. ';
    let question = 'How would rate the knowledge of the staff?';

    this.response.speak(speechOutput + question);
    this.response.listen(question;

    this.emit(':responseReady'); 
}

Notice that the Amazon.YesIntent asks the first question of the survey. Once the customer replies with a number, the SurveyIntent triggers and the remaining questions are asked. The SurveyIntent is using dialog management to collect the slots. Since the customer provided the answer to the first question, it will automatically follow up with any remaining survey questions.

Copied to clipboard
'SurveyIntent': function () {
    let filledSlots = delegateSlotCollection.call(this);

    if (!filledSlots) {
        return;
    }

    let slots = getSlotValues(filledSlots);

    let slotStatus = '';
    let resolvedSlot;

    // log the results of the survey in your database
    // slots.question_one.resolved
    // slots.question_two.resolved
    // slots.question_three.resolved

    let speechOutput = 'Thanks for taking the time to complete the survey. ';
    speechOutput += 'As a thank you you will receive a $5 coupon that will be ';
    speechOutput += 'automatically applied to your next order. ';

    this.response.speak(speechOutput);
    this.emit(':responseReady'); 
}

If the the customer says "no" then we end the interaction.

Copied to clipboard
'AMAZON.NoIntent': function () {
    let say = 'Thank you. It\'s a pleasure doing business with you.';

    this.response.speak(say);
    this.emit(':responseReady'); 
}

DelegateSlotCollection

The dialog management state machine is managed from the delegateSlotCollection function. We are hooking into the dialog management state machine to manage how we collect the slots. When the dialogState is IN_PROGRESS we are confirming the intent with this.emit('confirmIntent', speechOutput, speechOutput);.

Copied to clipboard
function delegateSlotCollection(){
    console.log("current dialogState: " + this.event.request.dialogState);
    let updatedIntent = this.event.request.intent;
    
    if (this.event.request.dialogState === "STARTED") {
    
        this.emit(":delegate");
        
    } else if (this.event.request.dialogState !== "COMPLETED") {
    
        if (this.event.request.intent.name === 'CheckoutIntent' &&
            this.event.request.intent.confirmationStatus !== 'CONFIRMED' &&
            this.event.request.intent.slots.wantsExtendedWarranty &&
            this.event.request.intent.slots.wantsExtendedWarranty.value) {
        
            let speechOutput = `So you want the ${this.attributes[recency]} `;
            speechOutput += `${this.attributes[specifications]}`;
            speechOutput += `${this.attributes[storageCapacity]}`;
            speechOutput += `${this.attributes[color]} smartphone. `;
        
            if (this.event.request.intent.slots.wantsExtendedWarranty.value == 'yes') {
                speechOutput = "The total with the extended warranty is $1500. "
            } else {
                speechOutput = "The total without the extended warranty is $1000. ";
            }
            speechOutput += "Would you like me to complete the transaction?";
            this.emit(':confirmIntent', speechOutput, speechOutput);
        } else 
        {
            this.emit(":delegate");
        }
    } else {
        // console.log("returning: "+ JSON.stringify(this.event.request.intent));
        return this.event.request.intent.slots;
    }
}

The confirmIntent dialog directive takes both a prompt and a reprompt so we can reprompt the user with a follow up if they take longer than 8 seconds to reply to the confirmation. Notice that the total price increases $500 up to $1,500 from $1,000 if the customer accepts the extended warranty during the CheckOutIntent.

Confirm Things with the User Sparingly

When designing your interactions, you should consider the conversation that your customer will have with the skill. Following up with slot confirmations after everything they say may, at the surface, appear to be a great way to ensure that your skill has collected the correct information. However, overdoing it can wear your customers out.

In our everyday conversations there are many types of yes-no questions. When designing your Alexa skills, you should take the time to properly identify your yes-no questions and think about how they fit into the conversation that your customer will have with your skill. This will help you easily identify when to use the AMAZON.YesIntentAMAZON.NoIntentyes-no slot typesslot confirmations, and intent confirmations.

Tell me about your experiences building Alexa skills using dialog management! Find me on Twitter at @sleepydeveloper.

More Resources on Dialog Management

Build Engaging Skills, Earn Money with Alexa Developer Rewards

Every month, developers can earn money for eligible skills that drive some of the highest customer engagement. Developers can increase their level of skill engagement and potentially earn more by improving their skill, building more skills, and making their skills available in in the US, the UK and Germany. Learn more about our rewards program and start building today.