Lex chat bot error: Reached second execution of fulfillment lambda on the same utterance

随声附和 提交于 2019-12-11 04:37:25

问题


I've read the Lex Docs on Responses.
I've searched and found:
- An unanswered question on same error.
- An unanswered similar question but in Python.
- An unanswered similar question in Amazon Dev Forum.

So my question remains. What is causing / How to fix this error in Lex chat bot:

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

The error is only occurring when attempting to respond with Delegate. Here is my AWS lambda (node.js 6.10) code for the Delegate response:

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
        }
    };
}

I've confirmed that the response is returning as expected with the minimum requirements for Delegate per Docs, which are sessionAttributes and DialogAction: type and slots. The slots are returning null as expected.

Additional possibly relevant information:
- The intent has multiple utterances.
- The intent has multiple slots.
- None of the slots are required.

Any suggestions or information on what might cause this error is much appreciated!


回答1:


My guess is you are calling delegate() in the FulfillmentCodeHook. When delegate is called it means that

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

Now, there are two actions in Lambda function, DialogCodeHook and FulfillmentCodeHook. If you are in DialogCodeHook, then delegate will call FulfillmentCodeHook. But if you are in FulfillmentCodeHook then it will throw an error.

However, if you are in FulfillmentCodeHook, and due to some reason you want to modify value of any slot then you can set value of that slot to null and then call the delegate passing new set of slots. This way, delegate will call DialogCodeHook again.

From AWS docs:

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.

Hope it helps.



来源:https://stackoverflow.com/questions/48230184/lex-chat-bot-error-reached-second-execution-of-fulfillment-lambda-on-the-same-u

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!