3
votes

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

1 Answers

4
votes

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.