1
votes

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.

1

1 Answers

1
votes

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