node.js - Lex 聊天机器人错误 : Reached second execution of fulfillment lambda on the same utterance

标签 node.js amazon-web-services aws-lambda amazon-lex

我已阅读Lex Docs on Responses .
我搜索并发现:
- 一个未答复的question on same error.
- 一个未答复的similar question but in Python.
- 一个未答复的similar question in Amazon Dev Forum.

所以我的问题仍然存在。是什么原因导致/如何修复 Lex 聊天机器人中的此错误:

An error has occurred: Invalid Lambda Response:
Reached second execution of fulfillment lambda on the same utterance

仅在尝试使用委托(delegate)进行响应时才会发生该错误。以下是我的委托(delegate)响应的 AWS lambda (node.js 6.10) 代码:

exports.handler = (event, context, callback) => {
    try {
        intentProcessor(event,
            (response) => {
                callback(null, response);
            });
    } catch (err) {
        callback(err);
    }
};

function intentProcessor(intentRequest, callback) {
     respond = delegate(sessionAttributes,intentRequest['currentIntent']['slots']);
     callback(respond);
}

function delegate(sessionAttributes, slots){
    return {
        sessionAttributes,
        dialogAction: {
            type: "Delegate",
            slots
        }
    };
}

我已确认响应按预期返回,并且满足每个文档的委托(delegate)的最低要求,即 sessionAttributes 和 DialogAction:类型和插槽。插槽按预期返回 null。

其他可能相关的信息:
- 意图有多种表述。
- 意图有多个槽。
- 不需要任何插槽。

非常感谢任何有关可能导致此错误的原因的建议或信息!

最佳答案

我的猜测是您正在 FulfillmentCodeHook 中调用 delegate()。当委托(delegate)被调用时,这意味着

Lambda function directs Amazon Lex to choose the next course of action

现在,Lambda 函数中有两个操作:DialogCodeHookFulfillmentCodeHook。如果您处于 DialogCodeHook 中,则 delegate 将调用 FulfillmentCodeHook。但如果你在 FulfillmentCodeHook 中,那么它会抛出错误。

但是,如果您处于 FulfillmentCodeHook 中,并且由于某种原因您想要修改任何 slot 的值,那么您可以将该 slot 的值设置为 null,然后调用传递新的一组槽的委托(delegate)。这样,delegate就会再次调用DialogCodeHook。

来自 AWS 文档:

If the value of the field is unknown, you must set it to null. You will get a DependencyFailedException exception if your fufillment function returns the Delegate dialog action without removing any slots.

希望有帮助。

关于node.js - Lex 聊天机器人错误 : Reached second execution of fulfillment lambda on the same utterance,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48230184/

相关文章:

javascript - 将数组的最后一个元素复制到不同的位置,然后从数组的末尾删除它

amazon-web-services - 在 AWS Step Function 中将多个输入传递到 Map State

amazon-web-services - 无法找到或加载主类 com.amazon.aes.webservices.client.cmd

aws-lambda - 具有 Last-Modified header 的 Api 网关 304 响应

aws-lambda - 在无服务器框架命令行中运行带输入参数的 lambda 函数

amazon-web-services - 从 Lambda 访问 ElasticSearch 的权限?

javascript - 在指定的超时时间内未调用 jasmine 异步回调

javascript - Node.js CPU 负载平衡多个 CPU 内核上的 Websocket 客户端

javascript - Node.js 中的 Promise.all 不会调用 then 函数

java - 如何设置从当前日期起 1 年内的 Amazon S3 存储桶预签名 URL 过期时间