【问题标题】:Fetch the slot value used for a previous intent(method) and use it in current method?获取用于先前意图(方法)的槽值并在当前方法中使用它?
【发布时间】:2017-09-11 08:11:29
【问题描述】:

我正在开发一项 alexa 技能,要求获取上一个插槽的值..

User:  Alexa,create an appointment
Alexa: please state the subject for appointment
User : subject is {subject}
Alexa: on which day?
User : {Day}
Alexa : Appointment has been created with {subject} on {day}

Final 方法应该从之前的槽(主题和日期)中获取值并创建一个约会。 到目前为止,我能够获取当前意图的插槽值...但我想获取先前意图的插槽值并在当前方法中使用它。

*示例

protected SpeechletResponse method1(Intent intent,Session session)throws 
Exception{
    SpeechletResponse response=null;

Map<String, Slot> slots =  intent.getSlots();
Slot example = slots.get(SampleSlot);
String value=example.getValue().toString();
String output="something";

response = SpeechletResponseHelper.getSpeechletResponse(output, reprompt, 
true);
    return response;
}

protected SpeechletResponse method2(Intent intent,Session session)throws 
Exception{
SpeechletResponse response=null;

****How to fetch the slot value used for method1 and use it in method2? ****

response = SpeechletResponseHelper.getSpeechletResponse(xxxx, reprompt, 
true);
return response;
}

这可能吗?如果可以,我该怎么做?

感谢和问候

【问题讨论】:

    标签: amazon-web-services alexa alexa-skills-kit alexa-skill alexa-slot


    【解决方案1】:

    我相信您应该能够使用这里提到的session.setAttribute()session.getAttribute() - https://github.com/amzn/alexa-skills-kit-java/blob/master/src/com/amazon/speech/speechlet/Session.java

    【讨论】:

      【解决方案2】:

      就像阿米特说的,你应该可以使用session.setAttribute,但是,如果由于某种原因你想保留session.setAttribute 可能不接受的东西,你总是可以有一个字段变量 始终可用,当然,直到会话关闭,一旦会话关闭,它就没有数据库了。

      String output;
      
          protected SpeechletResponse method1(Intent intent,Session session)throws 
          Exception{
              SpeechletResponse response=null;
      
          Map<String, Slot> slots =  intent.getSlots();
          Slot example = slots.get(SampleSlot);
          String value=example.getValue().toString();
          output="something";
      
          response = SpeechletResponseHelper.getSpeechletResponse(output, reprompt, 
          true);
              return response;
          }
      
          protected SpeechletResponse method2(Intent intent,Session session)throws 
          Exception{
          SpeechletResponse response=null;
      
          ****How to fetch the slot value used for method1 and use it in method2? ****
      
          response = SpeechletResponseHelper.getSpeechletResponse(output, reprompt, 
          true);
          return response;
          }
      

      我所做的只是在更高的范围(在方法之外)初始化字符串变量output,使其可用于任何其他方法。

      【讨论】:

      • 感谢您抽出宝贵时间回答我的问题,我使用会话解决了问题!
      【解决方案3】:

      我使用会话来实现这样的查询....

      Map<String, Slot> slots =  intent.getSlots();
      Slot example = slots.get(SampleSlot);
      session.setAttributes(Sample_String);
      session.getAttributes(SampleSessionString);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2019-09-12
        • 1970-01-01
        • 2016-12-11
        • 1970-01-01
        • 2016-11-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多