首页 文章

如何将Dialog.Delegate指令返回给Alexa Skill模型?

提问于
浏览
4

我想用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
    }
}

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

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

先感谢您 .

3 回答

  • 4

    使用 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 参数是可选的 . 它是一个意图对象,表示发送给您技能的意图 . 如有必要,您可以使用此属性集或更改槽值和确认状态 .

    更多关于Dialog指令here

  • 6

    在nodejs中,您可以使用

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

    在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');
         }
    }
    

相关问题