0

私はAlexaで次のことをするスキルを作成しています。Alexa会話スキルエラー

  1. ユーザー:ジョン
  2. アレクサ:お会いできてやあジョン、良いこんにちは
  3. アレクサ、こんにちは私
  4. ユーザーが自分の名前を記入してください。あなたは何歳
  5. ユーザー:私の発言は以下
    StartTheFlow Hi 
    StartTheFlow {custName} 
    StartTheFlow {age} 
    

    は私onIntent()

    @Override 
        public SpeechletResponse onIntent(final IntentRequest request, final Session session) throws SpeechletException { 
         log.info("onIntent requestId={}, sessionId={}", request.getRequestId(), session.getSessionId()); 
    
         Intent intent = request.getIntent(); 
         String intentName = (intent != null) ? intent.getName() : null; 
    
         if ("StartTheFlow".equals(intentName)) { 
          return getTheFlow(intent, session); 
         } else if ("AMAZON.HelpIntent".equals(intentName)) { 
          return getHelpResponse(); 
         } else if ("WelcomeChubb".equals(intentName)) { 
          return getWelcomeResponse(); 
         } else { 
          throw new SpeechletException("Invalid Intent"); 
         } 
        } 
    
    は以下

25は私の意図下記

{ 
    "intents": [ 
    { 
     "intent": "StartTheFlow", 
     "slots": [ 
     { 
      "name": "custName", 
      "type": "list_of_userNames" 
     }, 
     { 
      "name": "age", 
      "type": "AMAZON.NUMBER" 
     } 
     ] 
    }, 
    { 
     "intent": "AMAZON.HelpIntent" 
    },{ 
     "intent": "Welcome" 
    }, 
    { 
     "intent": "AMAZON.StopIntent" 
    }, 
    { 
     "intent": "AMAZON.CancelIntent" 
    } 
    ] 
} 

されています

私も

private SpeechletResponse getTheFlow(Intent intent, Session session) { 

     boolean isAskResponse = true; 
     String responseText = ""; 
     String nameFromSession = (String) session.getAttribute("name"); 
     if (StringUtils.isNullOrEmpty(nameFromSession)) { 
      responseText = "please give me your name"; 
      getTheNameText(intent, session); 
     } else { 
      System.out.println(session.getAttribute("nameFromSession")); 
      responseText = "please give me your date of birth"; 
     } 

     return getSpeechletResponse(responseText, "", isAskResponse); 

    } 

    private String getTheNameText(Intent intent, Session session) { 
     String userNameFrmIntent = getNameFromSlot(intent).toString(); 
     session.setAttribute("nameFromSession", userNameFrmIntent); 
     return getNameFromSlot(intent).toString(); 

    } 

    private String getNameFromSlot(Intent intent) { 
     Slot userName = intent.getSlot(Slot_Name); 
     return userName.getValue(); 
    } 

以下のようにこれを処理しようとしている、私は以下のようにトップのスロットを定義しました。

private static final String Slot_Name = "custName"; 

しかし、ここで私が代わりに、それは私のログにエラーを与えている私に私の名前を尋ねると、Hiを入力する際に​​は、JavaにNullPointer例外を示しています。私がHiと入力したときの反応は以下の通りです。誰かがある場合は私に知らせてくださいすることができ、誰かが私に教えてくださいすることができ

{ 
    "session": { 
    "sessionId": "SessionId.a2740ca4-73ff-4a15-856d-6461b3c7b2e1", 
    "application": { 
     "applicationId": "amzn1.ask.skill.e3dfb30e-0089-423c-a325-30ad28dd2e2b" 
    }, 
    "attributes": {}, 
    "user": { 
     "userId": "amzn1.ask.account.AEQYTT5HFHEGGDSUCT3NW45HKR7O3FBL5YCBSZIS7P5LNP5BXFEMUR7AUYOZVKC2FT5V6RKJC7RNA5VMZVREBAXAQP3NFNTQSFSSKSEXIYT4FQYMS5JCI2CCAOPUF4FN4C6DHEU6ONNY3D6GN5AWK75KOQNJH2IWROIIXTPNXSNI6FLQYRBBMP7TRSOWVNCY73WJUT2VLHDACWA" 
    }, 
    "new": true 
    }, 
    "request": { 
    "type": "IntentRequest", 
    "requestId": "EdwRequestId.cf686fc0-cbfd-4496-bb09-c41714563507", 
    "locale": "en-US", 
    "timestamp": "2017-02-15T20:12:44Z", 
    "intent": { 
     "name": "StartTheFlow", 
     "slots": { 
     "custName": { 
      "name": "custName", 
      "value": "hi" 
     } 
     } 
    } 
    }, 
    "version": "1.0" 
} 

はどこで間違ったんだと私はこの問題を解決することができますどのように、私は25のように、非常に多くの疑問をリ​​ンクするしましたJavaでこれを行うためのより良い方法。

おかげ

答えて

0

私は、ユーザーが言うことを各事に別々の意図を作成することをお勧めします。たとえば、HelloIntent、NameIntent、AgeIntentなどです。

次に、情報のこれらのビットを必ずセッション内のすべてのインテントに転送してください。したがって、各インテントは最初に共通の機能を使用して、セッション(存在する場合)から各文字列を読み込み、新しいスロットデータを追加してから、終了する前にすべての文字列を応答セッションに書き戻すことができます。

別のインテントがあるため、ユーザーはそれらの順序が間違っていると思われる可能性があるため、必要な文字列がすべて入力されているかどうかを確認したり、

セッションにデータを保存する際の問題は、次にユーザーがスキルを開始したときにデータが失われることです。これを解決するには、データベースを使用してユーザーデータを保持し、userIdにキーを保存します。それを行う方法には多くの例があります。いくつかのデータベースは基本的に無料ですが、毎月の使用回数に応じて課金されることに注意してください。