Java 如何在Amazon Alexa SDK中返回Dialog.Delegate?
我的Alexa应用程序的一些意图需要特定的插槽。Alexa skills builder使这变得简单。我可以根据需要标记插槽,并设置Alexa应该询问的内容,以便用户提供插槽信息。问题是,作为一名开发人员,您必须用lambda告诉Alexa,您希望Alexa处理插槽填充 通过阅读文档,我了解到这一部分: 它说 如果对话框正在进行中,请返回dialog.Delegate(不带更新内容) 我该怎么做?在我的lambda里我有Java 如何在Amazon Alexa SDK中返回Dialog.Delegate?,java,amazon,alexa-skills-kit,alexa-skill,amazon-echo,Java,Amazon,Alexa Skills Kit,Alexa Skill,Amazon Echo,我的Alexa应用程序的一些意图需要特定的插槽。Alexa skills builder使这变得简单。我可以根据需要标记插槽,并设置Alexa应该询问的内容,以便用户提供插槽信息。问题是,作为一名开发人员,您必须用lambda告诉Alexa,您希望Alexa处理插槽填充 通过阅读文档,我了解到这一部分: 它说 如果对话框正在进行中,请返回dialog.Delegate(不带更新内容) 我该怎么做?在我的lambda里我有 @Override public SpeechletRespon
@Override
public SpeechletResponse onIntent(final IntentRequest request, final Session session)
throws SpeechletException {
Intent intent = request.getIntent();
String intentName = (intent != null) ? intent.getName() : null;
if ("AddTwoNumbers".equals(intentName)) {
if (!request.getDialogState().equals("COMPLETED")) {
return new DelegateDirective();
} else {
handleAdditionIntent();
}
} else { // handle other intents}
}
他们的代码示例似乎也没有太大帮助
} else if (intentRequest.dialogState != "COMPLETED"){
// return a Dialog.Delegate directive with no updatedIntent property.
} else {
前几天我遇到了这个问题,我根据另一个问题得到了解决方案。这是我在Alexa Skill Kit的
1.5.0版中使用的稍加修改的版本。希望这有帮助。如果有多个插槽需要填充,您可能希望以不同的方式处理进行中的状态。这里的代码只针对1个插槽设计
if (speechletRequestEnvelope.getRequest().getDialogState() != IntentRequest.DialogState.COMPLETED)
// 1. Create DialogIntent based on your original intent
DialogIntent dialogIntent = new DialogIntent(speechletRequestEnvelope.getRequest().getIntent());
// 2. Create Directive
DelegateDirective dd = new DelegateDirective();
dd.setUpdatedIntent(dialogIntent);
List<Directive> directiveList = new ArrayList<>();
directiveList.add(dd);
SpeechletResponse speechletResp = new SpeechletResponse();
speechletResp.setDirectives(directiveList);
// 3. return the response.
speechletResp.setNullableShouldEndSession(false);
return speechletResp;
}
if(speechletRequestEnvelope.getRequest().getDialogState()!=IntentRequest.DialogState.COMPLETED)
// 1. 基于您的原始意图创建DialogIntent
DialogIntent DialogIntent=新的DialogIntent(speechletRequestEnvelope.getRequest().getIntent());
// 2. 创建指令
DelegateDirective dd=新的DelegateDirective();
dd.setUpdatedIntent(dialogIntent);
List directiveList=新建ArrayList();
directiveList.add(dd);
SpeechletResponse speechletResp=新SpeechletResponse();
speechletResp.setDirectives(directiveList);
// 3. 返回响应。
speechletResp.setNullableShouldEndSession(false);
返回演讲者;
}
Amazons对Alexa开发的支持非常糟糕。我感谢你的帮助。看起来我错过的一件大事是调用speechletResp.setNullableShouldEndSession(false)代码>干杯!我完全同意。。。这些文档非常抽象,没有具体的java示例