Skip to content

Commit 3ff8f5b

Browse files
authored
feat: Support async lambda event handlers (#161)
1 parent 7df8e3f commit 3ff8f5b

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ const smartapp = new SmartApp()
129129
.updated(() => { ... })
130130
.subscribedEventHandler( ... );
131131

132-
exports.handler = (event, context, callback) => {
133-
smartapp.handleLambdaCallback(event, context, callback);
132+
exports.handler = (event, context) => {
133+
return smartapp.handleLambdaCallback(event, context);
134134
};
135135
```
136136
There are also a few Glitch examples:

lib/smart-app.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,22 @@ class SmartApp {
354354
/**
355355
* Use with an AWS Lambda function. No signature verification is required.
356356
*
357-
* @param {*} event
358-
* @param {*} context
359-
* @param {*} callback
357+
* @param {*} event Lambda invocation event
358+
* @param {*} context Lambda execution context
359+
* @param {*} callback optional callback function
360360
*/
361-
handleLambdaCallback(event, context, callback) {
362-
this._handleCallback(event, responders.lambdaResponse(callback, this._log))
361+
async handleLambdaCallback(event, context, callback) {
362+
if (callback) {
363+
return this._handleCallback(event, responders.lambdaResponse(callback, this._log))
364+
}
365+
366+
const responder = responders.mockResponder(this._log)
367+
await this._handleCallback(event, responder)
368+
if (responder.response.statusCode === 200) {
369+
return context.succeed(responder.response)
370+
}
371+
372+
return context.fail(responder.response)
363373
}
364374

365375
/**

0 commit comments

Comments
 (0)