0

我正在构建一项 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}

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

*例子

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;
}

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

谢谢并恭祝安康

4

3 回答 3

0

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

于 2017-09-11T15:46:02.523 回答
0

就像Amit说的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在更高的范围内(在方法之外)初始化字符串变量,使其可用于任何其他方法。

于 2017-09-12T14:25:43.310 回答
0

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

Map<String, Slot> slots =  intent.getSlots();
Slot example = slots.get(SampleSlot);
session.setAttributes(Sample_String);
session.getAttributes(SampleSessionString);
于 2017-10-11T07:00:52.533 回答