12

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?

2
  • Hi ! It would be better if you checkout How to create a Minimal, Complete, and Verifiable example of your code for future endeavor at Stack overflow. -Thank you Commented Oct 15, 2017 at 5:14
  • thanks for @Momin and {aUXcoder} to edit, help my question Commented Oct 15, 2017 at 5:51

1 Answer 1

23

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you for your kindness to answer even edit my post cleary.
Given this example, simply returning a string doesn't work as advertised in python. docs.aws.amazon.com/cognito/latest/developerguide/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.