Alexa Skills Dialog Management: how to repeat last intent without specifing its utterances again

Andrea

I'm developing my first Alexa skill and I want to try to improve its dialog management.
My skill has several intents: one to get the temperature indoor, one to get the humidity and so on.
Every intent has one slot that represents the floor/room of my house so the typical question to Alexa is "What's the temperature on the first floor?"

Every time intent is executed it stores the slot in a session attribute so I can handle a conversation like this:

me: "Alexa what's the temperature on the first floor?"
Alexa: "The temperature on the first floor is 24 degrees"
me: "and the humidity?"
Alexa: "The humidity on the first floor is 50%"


The next step that I'm trying to implement is this type of dialog:

me: "Alexa what's the temperature on the first floor?"
Alexa: "The temperature on the first floor is 24 degrees"
me: "and on the second floor?"
Alexa: "The temperature on the second floor is 26 degrees"

In practice, I need to launch the last executed intent without saying its utterances.
I was thinking of creating a new generic intent that receives only the slot and then dispatches the request to the last executed intent.
I can keep track of the last intent executed saving its ID in a session attribute.

Is there a better way to do this?
Every suggestion is welcome because I am developing Alexa skills since last Monday! :-)

Thanks a lot.

LetMyPeopleCode

You're on the right track. The thing to remember is you can have one intent for multiple slots and NOT require them all.

Here's how you can create a single intent for all of it.

Intents The sample utterances are:

How are things on the {floor}
And on the {floor}
What is the {condition}
What is the {condition} on the {floor}

Then you create the "condition" and "floor" slot types, filling them with appropriate sample values like "temperature" for condition and "first floor" for floor. Then make sure to assign those slot types to the slots in your intent.

Then your handler code looks like this...

    const conditionIntentHandler = {
      canHandle(handlerInput) {
            return Alexa.getRequestType(handlerInput.requestEnvelope) === 'IntentRequest'
                && Alexa.getIntentName(handlerInput.requestEnvelope) === 'conditionIntent';
        },
        handle(handlerInput) {
          var speakOutput = "";
          var condition = "";
          var floor = "";
          const attributesManager = handlerInput.attributesManager;
          const attributes = attributesManager.getSessionAttributes();
          
          if (handlerInput.requestEnvelope.request.intent.slots.condition.hasOwnProperty('value')) {
            condition = handlerInput.requestEnvelope.request.intent.slots.condition.value;
          } else if (attributes.hasOwnProperty('condition')) {
            if(attributes.condition !== "") condition = attributes.condition;
          }    
            
          if (handlerInput.requestEnvelope.request.intent.slots.floor.hasOwnProperty('value')) {
            floor = handlerInput.requestEnvelope.request.intent.slots.floor.value;
          } else if (attributes.hasOwnProperty('floor')) {
            if(attributes.floor !== "") floor = attributes.floor;
          }    
        
          if (floor !== "" && condition === ""){
              speakOutput = "Here's the conditions for the " + floor; 
          }  else if (floor === "" && condition !== ""){
              speakOutput = "Here's the " + condition + " throughout the house";
          } else if (floor !== "" && condition !== ""){
              speakOutput = "Here's the " + condition + " on the " + floor;
          } else {
              speakOutput = "I have no idea what you're saying. Are you okay?"
          }

          attributes.floor = floor;
          attributes.condition = condition;
          attributesManager.setSessionAttributes(attributes);
          
            return handlerInput.responseBuilder
                .speak(speakOutput)
                .reprompt('What else can I tell you?')
                .getResponse();
        }
    };

I haven't written the actual code to present the values, just placeholder responses, but you should get the idea. Add more carrier phrases that contain one or both slot types to make this handle more ways people might ask for this info.

Results

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

how to make Alexa correctly respond to: Alexa, ask (tell) [invocation name] (linking word if any) [intent Utterances]?

Submit intent schema for slots and utterances for an Alexa Skill in JSON form?

How to handle out of domain utterances in Amazon Alexa

Alexa skills kit fallback intent not calling

How to repeat a code in html without writing the same code again and again

Precedence of slot utterances over intent utterances

How to capture Alexa utterances that I did not anticipate to improve my Alexa Skill?

Amazon Alexa: Certain utterances not working

"Catch-all" for Alexa Skills Kit input not in defined intent

How to use Intent Chaining with Intent Confirmation in Alexa?

Alexa how to implement intent confirmation?

How to implement a next intent in alexa

How to write query to select value without repeat same values again?

Understanding slots and getting its values in Alexa Skills Kit

How to test alexa custom skills on alexa app before publishing?

How to test alexa skills for multiple countries / regions?

Alexa Skills - How does sessionAttributes actually work?

How to set dialog window background to transparent, without affecting its margin

How to encrypt a specific image by its location without opening dialog box?

How to Develop alexa to speak latest response again

How to repeat (recursive) query, again and again?

How to repeat powershell command again and again?

How do I repeat the last command without using the arrow keys?

How can I request the permission dialog without the "Never ask again" option?

How to implement `Dataframe.value_counts()` without specifing a column name when using `Series.value_counts`

How to use session-specific variables in Alexa Skills?

How to set a AWS lambda trigger to Alexa Skills in YAML file

How do you go about making a sessionAttribute in Alexa Skills?

Deploying or publishing Alexa skills