我在网上几乎找不到任何与这个话题相关的信息。我不知道如何访问意图,或者如何使用它们来返回响应,因为某些参数满足该意图。我正在尝试创建一个可以像这样简单的对话,
我:“添加一个单元”
Alexa:“这个单位应该叫什么?”
我:“工程”
Alexa:“好的,增加了单位工程。”
目前我所知道做的就是一旦技能被调用,就执行一个动作,而不管说什么。例如,我可以从字面上说,
我:"Alexa,打开StudyPal“
Alexa:“当技能被激活时返回的东西”
或者..。
我:"Alexa,问问StudyPal关于我的单位的事。“
Alexa:“当技能被激活时返回的东西”
任何帮助都将不胜感激。作为参考,这是我的一些代码...
public class StudyPalHandler implements RequestStreamHandler {
private final Skill skill;
private final JacksonSerializer serializer;
public StudyPalHandler() {
skill = new StandardSkillBuilder()
.addRequestHandler(new StudyPalExtraHandler())
.build();
serializer = new JacksonSerializer();
}
@Override
public void handleRequest(InputStream inputStream, OutputStream outputStream, Context context) throws IOException {
String request = IOUtils.toString(inputStream);
RequestEnvelope requestEnvelope = serializer.deserialize(request, RequestEnvelope.class);
ResponseEnvelope responseEnvelope = skill.invoke(requestEnvelope);
byte[] response = serializer.serialize(responseEnvelope).getBytes(StandardCharsets.UTF_8);
outputStream.write(response);
}
}
public class StudyPalExtraHandler implements RequestHandler {
@Override
public boolean canHandle(HandlerInput handlerInput) {
return true;
}
@Override
public Optional<Response> handle(HandlerInput handlerInput) {
return handlerInput.getResponseBuilder().withSpeech("Something that is returned whenever the skill is activated").build();
}
}发布于 2018-09-18 14:42:31
您应该使用关联的处理程序类的canHandle()方法来检查该特定处理程序是否可以处理该请求。
例如:如果您想处理StudyPalIntent,那么
public class StudyPalIntentHandler implements RequestHandler {
@Override
public boolean canHandle(HandlerInput input) {
return input.matches(intentName("StudyPalIntent"));
}
@Override
public Optional<Response> handle(HandlerInput input) {
return input.getResponseBuilder()
.withSpeech("your response speech here")
.withReprompt("your re prompt here")
.build();
}在sdk源代码中,您可以使用如下对话框指令
return input.getResponseBuilder()
.withSpeech("your response speech here")
.withReprompt("your re prompt here")
.addDelegateDirective(updatedIntent)
.build();其他对话指令帮助器方法包括
addElicitSlotDirective(String slotName, Intent updatedIntent)
addConfirmSlotDirective(String slotName, Intent updatedIntent)
addConfirmIntentDirective(Intent updatedIntent)https://stackoverflow.com/questions/52376212
复制相似问题