简体   繁体   English

Alexa Skills Dialog Management:如何在不再次指定其话语的情况下重复上一个意图

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


I'm developing my first Alexa skill and I want to try to improve its dialog management. 我正在开发我的第一个 Alexa 技能,我想尝试改进它的对话管理。
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?" 每个意图都有一个槽代表我家的地板/房间,所以 Alexa 的典型问题是“一楼的温度是多少?”

Every time intent is executed it stores the slot in a session attribute so I can handle a conversation like this:每次执行意图时,它都会将插槽存储在 session 属性中,因此我可以处理这样的对话:

me: "Alexa what's the temperature on the first floor?"我:“Alexa 一楼的温度是多少?”
Alexa: "The temperature on the first floor is 24 degrees" Alexa:“一楼的温度是 24 度”
me: "and the humidity?"我:“还有湿度?”
Alexa: "The humidity on the first floor is 50%" Alexa:“一楼的湿度是 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 一楼的温度是多少?”
Alexa: "The temperature on the first floor is 24 degrees" Alexa:“一楼的温度是 24 度”
me: "and on the second floor?"我:“在二楼呢?”
Alexa: "The temperature on the second floor is 26 degrees" Alexa:“二楼的温度是 26 度”

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.我可以跟踪最后执行的意图,将其 ID 保存在 session 属性中。

Is there a better way to do this?有一个更好的方法吗?
Every suggestion is welcome because I am developing Alexa skills since last Monday: :-)欢迎提出每一个建议,因为自上周一以来我正在开发 Alexa 技能::-)

Thanks a lot.非常感谢。

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.以下是如何为所有这些创建一个单一的意图。

意图 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.添加更多包含一种或两种槽类型的载体短语,以使其处理人们可能要求此信息的更多方式。

结果

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Alexa技能的自定义意图中添加人声? - how to add a human sound to the utterances of a custom intent in alexa skills? Alexa技能-如何从另一个意图返回带有插槽值的意图? - Alexa Skills - how to return an intent with slot values from another intent? 如何使Alexa正确响应:Alexa,问(告诉)[调用名称](如果有链接的话)[意图陈述]? - how to make Alexa correctly respond to: Alexa, ask (tell) [invocation name] (linking word if any) [intent Utterances]? 用户在使用 Node js 在 Alexa 上的引发对话期间说重复后如何返回原始意图? - How to return to original intent after user says Repeat during an elicit dialog on Alexa using Node js? Alexa技能中的多轮对话错误 - Errors with multi turn dialog in alexa skills 如何处理Amazon Alexa中的域外言语 - How to handle out of domain utterances in Amazon Alexa Amazon Alexa-更改意图插槽并更新简单话语列表 - Amazon Alexa - changing intent slots and updating simple utterances list 语音生成器工具(例如,语音扩展器)生成的Alexa技能中的语音自动填充 - Autofilling of utterances in alexa skills generated by utterance generator tool(ex. utternance expander) 如何在 Alexa Skills 中动态设置 Slot 值? - How to set Slot values dynamically in Alexa Skills? 如何为 alexa 技能创建共享槽 - How to create shared slots for alexa skills
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM