mgcation
mgcation

Reputation: 547

I can't find callback parameter in python lambda handler

I'm studying for aws lambda - lex and I found coffee bot sample code with node.js.

// --------------- Main handler -----------------------
// --------------- in node.js -----------------------

// Route the incoming request based on intent.
// The JSON body of the request is provided in the event slot.

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

I want use callback parameter but i can't find it in python

// --------------- Main handler -----------------------
// --------------- in python -----------------------

def lambda_handler(event, context):    
    dispatch(event)

# >>> this handler doesn't include callback <<<

If you need, compare both about

python docs vs node.js docs


Actually I want to get this function (build message to lex)

callback(elicitSlot(outputSessionAttributes, intentRequest.currentIntent.name, slots, 'BeverageType', 
                buildMessage('Sorry, but we can only do a mocha or a chai. What kind of beverage would you like?'), 
                buildResponseCard("Menu", "Today's Menu", menuItem)));

full sample code is here (https://github.com/awslabs/amz-ai-building-better-bots/blob/master/src/index.js)

anyone can help me?

Upvotes: 12

Views: 8626

Answers (1)

Noel Llevares
Noel Llevares

Reputation: 16067

Using callbacks is a pattern commonly-used in NodeJS for managing asynchronous execution. You don't need it in Python (for this specific use-case).

This snippet in NodeJS...

callback(null, response)

is equivalent to

return response

in Python.

Upvotes: 23

Related Questions