我在python lambda处理程序中找不到回调参数

mgc*_*ion 0 python amazon-web-services node.js aws-lambda

我正在研究aws lambda-lex,我发现用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);
    }
};
Run Code Online (Sandbox Code Playgroud)

我想使用回调参数,但在python中找不到

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

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

# >>> this handler doesn't include callback <<<
Run Code Online (Sandbox Code Playgroud)

如果需要,将两者进行比较

python文档 vs node.js文档


实际上我想获得此功能(向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)));
Run Code Online (Sandbox Code Playgroud)

完整的示例代码在这里(https://github.com/awslabs/amz-ai-building-better-bots/blob/master/src/index.js

有人可以帮助我吗?

das*_*mug 5

使用回调是NodeJS中用于管理异步执行的常用模式。您无需在Python中使用它(针对此特定用例)。

NodeJS中的此代码段...

callback(null, response)
Run Code Online (Sandbox Code Playgroud)

相当于

return response
Run Code Online (Sandbox Code Playgroud)

在Python中。