【问题标题】:I can't find callback parameter in python lambda handler我在 python lambda 处理程序中找不到回调参数
【发布时间】:2018-03-26 20:48:38
【问题描述】:

我正在学习 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);
    }
};

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

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

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

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

如果需要,可以比较一下

python docsnode.js docs


其实我是想得到这个功能(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)));

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

谁能帮帮我?

【问题讨论】:

标签: python node.js amazon-web-services aws-lambda


【解决方案1】:

使用回调是 NodeJS 中常用的一种模式,用于管理异步执行。在 Python 中不需要它(对于这个特定的用例)。

NodeJS 中的这个 sn-p...

callback(null, response)

等价于

return response

在 Python 中。

【讨论】:

猜你喜欢
  • 2015-04-24
  • 2018-03-10
  • 1970-01-01
  • 2021-12-16
  • 2020-08-16
  • 1970-01-01
  • 2013-04-27
  • 1970-01-01
  • 2013-11-02
相关资源
最近更新 更多