我正在尝试使用java skill kit创建自己的Alexa技能,并且我想使用Dialog Interface。我已经用测试版中的技能构建器创建了我的对话模型,但现在我不明白为了委托我的对话,我需要通过我的the服务返回什么。
我应该使用哪个类向Alexa发送一个命令来处理对话框中的下一轮操作?此外,我在IntentRequest类中没有dialogState属性...
发布于 2017-08-15 03:05:43
首先,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>下面您将看到来自onIntent方法中的Speechlet的一些用法示例:
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并将其分配给shoulEndSession标志to false,否则Alexa终止会话在选择您的意图的SkillBuilder中,需要至少有一个标记为必需的插槽。配置发声和提示。您还可以在提示符中使用{slotNames}。
-Sal
发布于 2017-05-09 02:57:14
我想您可能想看看https://github.com/amzn/alexa-skills-kit-java/pull/45最新更新的工作示例。
https://stackoverflow.com/questions/43736478
复制相似问题