如何在 Alexa 的 java SDK 中使用 Dialog Directives

编程入门 行业动态 更新时间:2024-10-06 10:31:50
本文介绍了如何在 Alexa 的 java SDK 中使用 Dialog Directives的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用 java 技能工具包创建我自己的 Alexa 技能,并且我想使用对话框界面.我已经使用 beta 版的技能构建器创建了我的对话模型,但现在我不明白我需要通过我的网络服务返回什么才能委托我的对话.

I'm trying to create my own Alexa's skill with the java skill kit, and I would like to use the Dialog Interface. I have created my Dialog model with the skill builder in beta, but now I don't understand what I need to return via my webservice in order to delegate my dialog.

我应该使用哪个类向 Alexa 发送命令来处理对话框中的下一个回合?此外,我在 IntentRequest 类中没有 dialogState 属性...

Which class should I use to send Alexa a command to handle the next turn in the dialog ? Moreover, I don't have the dialogState property in the IntentRequest class...

推荐答案

首先 dialogState 属性在 IntentRequest 中.我使用以下依赖项 (maven) 的 1.3.1 版.要获取值,请使用 yourIntentRequestObject.getDialogState().

First of all the dialogState property is in the IntentRequest. I use version 1.3.1 of the following dependency (maven). To get the value use yourIntentRequestObject.getDialogState().

<dependency> <groupId>com.amazon.alexa</groupId> <artifactId>alexa-skills-kit</artifactId> <version>1.3.1</version> </dependency>

下面是 onIntent 方法中 Speechlet 的一些示例用法:

Below you see some sample usage from a 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 属性
  • 将 shoulEndSession 标志设置为 false,否则 Alexa 将终止会话
  • Create a new DialogIntent
  • Create a DelegateDirectiveand assign it to the updatedIntentproperty
  • Set the shoulEndSession flag to false, otherwise Alexa terminates the session
  • 在 SkillBuilder 中选择您的 Intent,它需要至少有一个标记为所需的插槽.配置话语和提示.您还可以在提示中使用 {slotNames}.

    Within the SkillBuilder select your Intent, it needs to have at least one slot which is marked as required. Configure utterances and prompts. You can also use {slotNames} within prompts.

    -萨尔

    更多推荐

    如何在 Alexa 的 java SDK 中使用 Dialog Directives

    本文发布于:2023-11-28 06:19:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1641266.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:如何在   Alexa   java   Directives   Dialog

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!