alexa技能中的多转对话

时间:2018-06-06 11:28:05

标签: dialog alexa slot

我们开发技能需要多转对话。然而,当alexa确认第一个插槽时,它会抛出“#strong; 请求技能的响应存在问题。"

alexa调用的lambda代码如下所示。

 'DialogIntent': function(){
       if (this.event.request.dialogState === "STARTED") {
        console.log("in STARTED");

        var updatedIntent = this.event.request.intent;
        this.emit(":delegate", updatedIntent);
    } else if (this.event.request.dialogState !== "COMPLETED") {
        console.log("in not completed");
        this.emit(":delegate", updatedIntent);
    } else {
        console.log("in completed");
        return this.event.request.intent.slots;
    }
    return null;
}

we are doing everything suggested in https://developer.amazon.com/docs/custom-skills/dialog-interface-reference.html

Can you let us know if we are missing something?

1 个答案:

答案 0 :(得分:0)

我的回答

当Dialog状态处于启动以外的任何状态时,您没有在响应期间定义updatedIntent变量。要解决此问题,请尝试将updatedIntent声明移到if / else语句之前。

'DialogIntent': function(){
    var updatedIntent = this.event.request.intent;

    if (this.event.request.dialogState === "STARTED") {
        this.emit(":delegate", updatedIntent);
    } else if (this.event.request.dialogState !== "COMPLETED") {
        this.emit(":delegate", updatedIntent);
    } else {
        return this.event.request.intent.slots;
    }
    return null;
}

需要这样做的原因是因为每个请求都会将Dialog设置为以下三种状态之一:1)STARTED,仅在Dialog的第一个请求时发送,2)IN_PROGRESS,它在每个后续请求中设置为对话框已完成,并且在完成所有必需的插槽后设置的COMPLETE已完成,并且已完成任何必要的确认。

在您的示例中,您只在对话框状态设置为STARTED的请求上设置updatedIntent,因此仅在对话框的第一个请求上设置。之后的每个请求都将跳过if语句中的初始步骤,因此永远不会定义更新的intent变量,您尝试在'else if'语句中将其传递回Alexa。

重构#1

如果在对话状态刚刚“STARTED”时你不需要进行任何额外的设置,你可以在if else语句中省略该部分,因为你在两个方面都做了完全相同的事情== =“STARTED和!==”已完成“:

'DialogIntent': function(){
     var updatedIntent = this.event.request.intent;

     if (this.event.request.dialogState !== "COMPLETED") {
         this.emit(":delegate", updatedIntent);
     } else {
         return this.event.request.intent.slots;
     }
     return null;
}

重构#2

您可能不需要使用updatedIntent。虽然我不完全确定Node.js中的Alexa Skills Kit是如何工作的(我假设你正在使用它),但你不需要将updatedIntent传递给Alexa。仅在出于某种原因需要在代码中手动更新意图时才需要更新的intent变量。如果不这样做,Alexa可以在没有它的情况下处理整个对话框:

'DialogIntent': function(){
     if (this.event.request.dialogState !== "COMPLETED") {
         this.emit(":delegate");
     } else {
         return this.event.request.intent.slots;
     }
     return null;
}