我正在尝试使用 java 技能套件创建我自己的 Alexa 技能,并且我想使用对话框界面。我已经使用测试版的技能生成器创建了我的对话模型,但现在我不明白我需要通过我的网络服务返回什么才能委托我的对话。
我应该使用哪个类向 Alexa 发送命令来处理对话框中的下一个回合?
此外,我在 IntentRequest 类中没有dialogState 属性...
首先dialogState
财产是在IntentRequest
。我使用以下依赖项 (maven) 的 1.3.1 版本。获得使用价值yourIntentRequestObject.getDialogState()
.
<dependency>
<groupId>com.amazon.alexa</groupId>
<artifactId>alexa-skills-kit</artifactId>
<version>1.3.1</version>
</dependency>
下面您可以看到一些示例用法Speechlet
in the onIntent
method:
if ("DoSomethingSpecialIntent".equals(intentName))
{
// If the IntentRequest dialog state is STARTED
// This is where you can pre-fill slot values with defaults
if (dialogueState == IntentRequest.DialogState.STARTED)
{
// 1.
DialogIntent dialogIntent = new DialogIntent(intent);
// 2.
DelegateDirective dd = new DelegateDirective();
dd.setUpdatedIntent(dialogIntent);
List<Directive> directiveList = new ArrayList<Directive>();
directiveList.add(dd);
SpeechletResponse speechletResp = new SpeechletResponse();
speechletResp.setDirectives(directiveList);
// 3.
speechletResp.setShouldEndSession(false);
return speechletResp;
}
else if (dialogueState == IntentRequest.DialogState.COMPLETED)
{
String sampleSlotValue = intent.getSlot("sampleSlotName").getValue();
String speechText = "found " + sampleSlotValue;
// Create the Simple card content.
SimpleCard card = new SimpleCard();
card.setTitle("HelloWorld");
card.setContent(speechText);
// Create the plain text output.
PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
speech.setText(speechText);
return SpeechletResponse.newTellResponse(speech, card);
}
else
{
// This is executed when the dialog is in state e.g. IN_PROGESS. If there is only one slot this shouldn't be called
DelegateDirective dd = new DelegateDirective();
List<Directive> directiveList = new ArrayList<Directive>();
directiveList.add(dd);
SpeechletResponse speechletResp = new SpeechletResponse();
speechletResp.setDirectives(directiveList);
speechletResp.setShouldEndSession(false);
return speechletResp;
}
}
- 创建一个新的
DialogIntent
- 创建一个
DelegateDirective
并将其分配给updatedIntent
property
- Set the
shoulEndSession
标记为false
,否则 Alexa 将终止会话
在 SkillBuilder 中选择您的意图,它需要至少有一个标记为必需的插槽。配置话语和提示。您还可以在提示中使用 {slotNames}。
-Sal
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)