【问题标题】:How to return Dialog.Delegate in Amazon Alexa SDK?如何在 Amazon Alexa SDK 中返回 Dialog.Delegate?
【发布时间】:2017-08-24 10:07:02
【问题描述】:

我的 Alexa 应用程序的一些 Intent 需要特定的插槽。 Alexa 技能构建器让这一切变得简单。我可以根据需要标记一个插槽并设置 Alexa 应该询问的内容,以便用户提供该插槽的信息。问题是,作为开发人员,您必须使用您的 lambda 告诉 Alexa,您希望 Alexa 处理插槽填充。

阅读文档,我进入了这部分:

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 {

【问题讨论】:

    标签: java amazon alexa-skills-kit alexa-skill amazon-echo


    【解决方案1】:

    前几天我遇到了这个问题,我得到了基于另一个 post 的解决方案。这是 Alexa Skill Kit 的 1.5.0 版本中适用于我的稍作修改的版本。希望这可以帮助。如果您有超过 1 个插槽要填充,您可能希望以不同方式处理 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;
        }
    

    【讨论】:

    • 亚马逊对 Alexa 开发的支持非常糟糕。我很感激帮助。看起来我错过的最重要的事情是打电话给speechletResp.setNullableShouldEndSession(false); Cheers!
    • 我不能同意更多...文档非常抽象,没有具体的java示例
    猜你喜欢
    • 2019-01-14
    • 1970-01-01
    • 2019-02-16
    • 2018-08-10
    • 2017-08-28
    • 1970-01-01
    • 1970-01-01
    • 2018-04-26
    • 1970-01-01
    相关资源
    最近更新 更多