How to use Dialog Directives with Alexa's java SDK

牧云@^-^@ 提交于 2019-12-13 16:08:27

问题


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.

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...


回答1:


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>

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;
            }
        }
  1. Create a new DialogIntent
  2. Create a DelegateDirectiveand assign it to the updatedIntentproperty
  3. Set the shoulEndSession flag to false, otherwise Alexa terminates the session

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.

-Sal




回答2:


I think you may want to look at the newly updated working example at https://github.com/amzn/alexa-skills-kit-java/pull/45.



来源:https://stackoverflow.com/questions/43736478/how-to-use-dialog-directives-with-alexas-java-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!