首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Alexa的java SDK中使用Dialog指令

如何在Alexa的java SDK中使用Dialog指令
EN

Stack Overflow用户
提问于 2017-05-02 19:14:24
回答 2查看 2.8K关注 0票数 2

我正在尝试使用java skill kit创建自己的Alexa技能,并且我想使用Dialog Interface。我已经用测试版中的技能构建器创建了我的对话模型,但现在我不明白为了委托我的对话,我需要通过我的the服务返回什么。

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

EN

回答 2

Stack Overflow用户

发布于 2017-08-15 03:05:43

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

代码语言:javascript
复制
<dependency>
            <groupId>com.amazon.alexa</groupId>
            <artifactId>alexa-skills-kit</artifactId>
            <version>1.3.1</version>
</dependency>

下面您将看到来自onIntent方法中的Speechlet的一些用法示例:

代码语言:javascript
复制
        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

  • Create aDelegateDirective并将其分配给
  1. shoulEndSession标志to false,否则Alexa终止会话

在选择您的意图的SkillBuilder中,需要至少有一个标记为必需的插槽。配置发声和提示。您还可以在提示符中使用{slotNames}。

-Sal

票数 1
EN

Stack Overflow用户

发布于 2017-05-09 02:57:14

我想您可能想看看https://github.com/amzn/alexa-skills-kit-java/pull/45最新更新的工作示例。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43736478

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档