2017-08-24 71 views
2

我的一些關於我的Alexa應用程序的意圖需要某些插槽。 Alexa技能生成器使這一切變得簡單。我可以根據需要標記一個插槽,並設置Alexa應該詢問的內容,以便用戶爲插槽提供信息。問題是,作爲一名開發人員,你必須告訴Alexa你的lambda,你希望Alexa能夠處理插槽填充。如何返回亞馬遜Alexa SDK中的Dialog.Delegate?

閱讀該文檔,我到了這個部分:

https://developer.amazon.com/public/solutions/alexa/alexa-skills-kit/docs/dialog-interface-reference#details

它指出

如果對話框是IN_PROGRESS,沒有updatedIntent返回Dialog.Delegate。

我該怎麼做?在我的lambda中,我有

@Override 
    public SpeechletResponse onIntent(final IntentRequest request, final Session session) 
     throws SpeechletException { 

    Intent intent = request.getIntent(); 
    String intentName = (intent != null) ? intent.getName() : null; 

    if ("AddTwoNumbers".equals(intentName)) { 
     if (!request.getDialogState().equals("COMPLETED")) { 
      return new DelegateDirective(); 
     } else { 
     handleAdditionIntent(); 
     } 
    } else { // handle other intents} 
    } 

他們的代碼示例似乎也不太有用。

} else if (intentRequest.dialogState != "COMPLETED"){ 
    // return a Dialog.Delegate directive with no updatedIntent property. 
} else { 

回答

1

我在前幾天遇到了這個問題,並得到了另一個post的解決方案。以下是Alexa Skill Kit版本1.5.0中稍有修改的版本。希望這可以幫助。如果要填充多個插槽,則可能需要以不同的方式處理IN_PROGRESS狀態。此代碼僅適用於1個插槽。

 if (speechletRequestEnvelope.getRequest().getDialogState() != IntentRequest.DialogState.COMPLETED) 
     // 1. Create DialogIntent based on your original intent 
     DialogIntent dialogIntent = new DialogIntent(speechletRequestEnvelope.getRequest().getIntent()); 

     // 2. Create Directive 
     DelegateDirective dd = new DelegateDirective(); 
     dd.setUpdatedIntent(dialogIntent); 

     List<Directive> directiveList = new ArrayList<>(); 
     directiveList.add(dd); 

     SpeechletResponse speechletResp = new SpeechletResponse(); 
     speechletResp.setDirectives(directiveList); 
     // 3. return the response. 
     speechletResp.setNullableShouldEndSession(false); 
     return speechletResp; 
    } 
+0

亞馬遜對Alexa開發的支持是超出可怕的。我很感激幫助。看起來我缺少的重要東西是對'speechletResp.setNullableShouldEndSession(false)的調用;'乾杯! – EGHDK

+0

我不能同意更多...文件非常抽象,沒有具體的Java示例 – DLee