【问题标题】:Lex & Lambda: Slots Being Set Manually Reset to NullLex 和 Lambda:手动设置的插槽重置为空
【发布时间】:2021-10-19 15:50:38
【问题描述】:

构建一个我们在 Lambda 函数中实现意图的机器人。在此函数中,根据用户的选择,我们必须将两个插槽设置为特定值。

有问题的槽是“userResponse”、“chatType”和“segment”。

代码尝试根据 userResponse 槽填充后面的槽。看起来像这样:

let requestedService = event.currentIntent.slots.userResponse;
        
if (requestedService === "a") {
    event.currentIntent.slots.segment = 'a';
    event.currentIntent.slots.chatType = 'a';
} else {
    event.currentIntent.slots.segment = 'b';
    event.currentIntent.slots.chatType = 'b';
}

因此,在代码运行时,插槽可能如下所示:

{
    "userResponse": "a",
    "chatType": "a",
    "segment" "a"
}

现在我们已经完成了所有的槽,我们将完成意图对话操作传回给 Lex。

callback(null, {    
    "sessionAttributes": event.sessionAttributes,   
    "dialogAction": {   
        "type": "Close",
        "fulfillmentState": "Fulfilled",
        "message": {    
            "contentType": "PlainText", 
            "content": "Please wait"    
         }  
     }  
});

问题是,当我将此信息发送回 Lex 时,我刚刚手动设置的插槽不知何故被清除并作为 null 返回给 Lex,因此插槽如下所示:

{
    "userResponse": "a",
    "chatType": null
    "segment" null
}

在设置槽值和调用对话框操作之间没有其他代码。在此 Lambda 函数的 CloudWatch 日志中,我已经在对话操作调用之前记录了该事件,并将插槽显示为已完成。然而……不知何故,Lex 并没有用正确的数据取回这些插槽。

我有什么遗漏吗?为什么 Lex 在 Lambda 中不为空时会接收空值?

【问题讨论】:

    标签: node.js aws-lambda bots chatbot amazon-lex


    【解决方案1】:

    根据document,我认为你必须在响应对象中引入slots

    callback(null, {    
        "sessionAttributes": event.sessionAttributes,   
        "dialogAction": {   
            "type": "Close",
            "fulfillmentState": "Fulfilled",
            "stols": event.currentIntent.slots, // this change
            "message": {    
                "contentType": "PlainText", 
                "content": "Please wait"    
             }  
         }  
    });
    

    【讨论】:

    • 我实际上已经尝试过了。当意图仍有更多工作要做并且您可以使用“委托”对话操作时,这似乎有效。但是,在“关闭”对话框操作中包含 slot 属性会产生错误。
    猜你喜欢
    • 1970-01-01
    • 2014-09-05
    • 2018-09-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-09
    • 1970-01-01
    相关资源
    最近更新 更多