如何在 Amazon Alexa SDK 中返回 Dialog.Delegate?



我的Alexa应用程序的一些Intent需要某些插槽。Alexa技能构建器使这变得容易。我可以根据需要标记插槽并设置 Alexa 应该询问的内容,以便用户提供插槽的信息。问题是,作为一名开发人员,你必须用你的lambda告诉Alexa,你想让Alexa处理插槽填充。

阅读文档,我进入了这一部分:

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/dialog-interface-reference#details

它指出

如果对话框IN_PROGRESS,则返回 Dialog.Delegate,不带更新的意图。

我该怎么做?在我的 lambda 中,我有

@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技能套件的第1.5.0版中对我有用的略微修改的版本。希望这有帮助。如果要填充的插槽超过 1 个,则可能需要以不同的方式处理IN_PROGRESS状态。此处的代码仅适用于 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;
}

最新更新