我在python lambda处理程序中找不到回调参数 [英] I can't find callback parameter in python lambda handler
问题描述
我正在研究aws lambda-lex,我发现使用node.js的Coffee bot示例代码.
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);
}
};
我想使用回调参数,但是我在python中找不到
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
实际上我想获得此功能(向lex生成消息)
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)));
完整的示例代码在此处( https://github.com/awslabs/amz-ai-building-better-bots/blob/master/src/index.js )
full sample code is here (https://github.com/awslabs/amz-ai-building-better-bots/blob/master/src/index.js)
有人可以帮助我吗?
推荐答案
使用回调是NodeJS中常用的一种模式,用于管理异步执行.对于此特定用例,您不需要在Python中使用它.
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).
NodeJS中的此代码段...
This snippet in NodeJS...
callback(null, response)
等效于
return response
在Python中.
这篇关于我在python lambda处理程序中找不到回调参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!