【问题标题】:How to return Dialog.Delegate directive to Alexa Skill model?如何将 Dialog.Delegate 指令返回给 Alexa Skill 模型?
【发布时间】:2019-01-14 08:38:50
【问题描述】:

我想使用 Alexa Skill 模型创建一个简单的多轮对话。我的意图由 3 个插槽组成,每个插槽都是实现意图所必需的。我提示每个位置并定义所有需要的话语。

现在我想使用 Lambda 函数处理请求。这是我针对此特定 Intent 的功能:

function getData(intentRequest, session, callback) {
    if (intentRequest.dialogState != "COMPLETED"){
        // return a Dialog.Delegate directive with no updatedIntent property.
    } else {
        // do my thing
    }
}

那么,如 Alexa 文档中所述,我将如何继续使用 Dialog.Delegate 指令构建我的响应?

https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html#scenario-delegate

提前谢谢你。

【问题讨论】:

    标签: node.js aws-lambda alexa alexa-skills-kit alexa-slot


    【解决方案1】:

    使用Dialog.Delegate 指令,您无法从代码中发送outputSpeechreprompt。而是使用交互模型中定义的那些。

    不要在 Dialog.Directive 中包含 outputSpeech 或 reprompt。 Alexa 使用对话模型中定义的提示来询问用户 槽值和确认。

    这意味着您不能delegate 并提供您自己的回复,但您可以使用任何其他Dialog 指令来提供您的outputSpeechreprompt

    例如:Dialog.ElicitSlotDialog.ConfirmSlotDialog.ConfirmIntent

    在任何时候,您都可以接管对话,而不是继续委托给 Alexa。

    ...
        const updatedIntent = handlerInput.requestEnvelope.request.intent;
        if (intentRequest.dialogState != "COMPLETED"){
           return handlerInput.responseBuilder
                  .addDelegateDirective(updatedIntent)
                  .getResponse();
        } else {
            // Once dialoState is completed, do your thing.
            return handlerInput.responseBuilder
                  .speak(speechOutput)
                  .reprompt(reprompt)
                  .getResponse();
        }
    ...
    

    addDelegateDirective() 中的updatedIntent 参数是可选的。 它是一个意图对象,表示发送到您的技能的意图。如有必要,您可以使用此属性集或更改槽值和确认状态。

    更多关于对话框指令here

    【讨论】:

    • 完美,谢谢。我在 Alexa 文档中苦苦挣扎,这非常有帮助。
    • @Cicil 我建议您添加如何获取 currentIntent 以供参考
    • const currentIntent = handlerInput.requestEnvelope.request.intent
    【解决方案2】:

    在nodejs中你可以使用

    if (this.event.request.dialogState != 'COMPLETED'){
        //your logic
        this.emit(':delegate');
    } else {
         this.response.speak(message);
         this.emit(':responseReady');
    }
    

    【讨论】:

    • 谢谢,这有助于掌握工作中的机械原理。
    • 这是 v1 代码。 Cicil 的答案使用 v2,所以它更可取
    【解决方案3】:

    在 nodeJS 中,我们可以检查 dialogState 并采取相应措施。

    if (this.event.request.dialogState === 'STARTED') {
          let updatedIntent = this.event.request.intent;
          this.emit(':delegate', updatedIntent);
    } else if (this.event.request.dialogState != 'COMPLETED'){
         if(//logic to elicit slot if any){
              this.emit(':elicitSlot', slotToElicit, speechOutput, repromptSpeech);
         } else {
              this.emit(':delegate');
         }
    } else {
         if(this.event.request.intent.confirmationStatus == 'CONFIRMED'){
               //logic for message
               this.response.speak(message);
               this.emit(':responseReady');
         }else{
               this.response.speak("Sure, I will not create any new service request");
               this.emit(':responseReady');
         }
    }
    

    【讨论】:

    • 感谢您提供代码 sn-p。我采用了另一种解决方案,但它对理解这个 elicitSlot 功能有很大帮助。
    猜你喜欢
    • 1970-01-01
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-09
    相关资源
    最近更新 更多