2017-05-02 6 views
0

自分のAlexaのスキルをJavaスキルキットで作成しようとしていますが、Dialog Interfaceを使用したいと思います。私は、ベータ版のスキルビルダーを使ってDialogモデルを作成しましたが、ダイアログを委任するためにWebサービス経由で返す必要があることを理解できません。AlexaのJava SDKでDialogディレクティブを使用する方法

ダイアログの次の順番を処理するコマンドをAlexaに送信するのに、どのクラスを使用しますか? さらに、私はIntentRequestクラスのdialogStateプロパティを持っていません...

答えて

1

まず、dialogStateプロパティはIntentRequestにあります。私は以下の依存関係(バージョン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; 
      } 
     } 
  1. DelegateDirectiveを作成し、updatedIntent財産
  2. に割り当てる新しいDialogIntent
  3. を作成します。 shoulEndSessionフラグをfalseに設定します。それ以外の場合はAlexa ter

SkillBuilder内でIntentを選択するには、必要に応じて少なくとも1つのスロットが必要です。発声とプロンプトを設定する。プロンプト内で{slotNames}を使用することもできます。

-al

関連する問題