我已阅读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 函数中有两个操作:DialogCodeHook
和 FulfillmentCodeHook
。如果您处于 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/