@@ -26,7 +26,11 @@ <h1 class="title">Module <code>slack_bolt.adapter.aws_lambda</code></h1>
26
26
< summary >
27
27
< span > Expand source code</ span >
28
28
</ summary >
29
- < pre > < code class ="python "> from .handler import SlackRequestHandler # noqa: F401</ code > </ pre >
29
+ < pre > < code class ="python "> from .handler import SlackRequestHandler
30
+
31
+ __all__ = [
32
+ "SlackRequestHandler",
33
+ ]</ code > </ pre >
30
34
</ details >
31
35
</ section >
32
36
< section >
@@ -67,6 +71,160 @@ <h2 class="section-title" id="header-submodules">Sub-modules</h2>
67
71
< section >
68
72
</ section >
69
73
< section >
74
+ < h2 class ="section-title " id ="header-classes "> Classes</ h2 >
75
+ < dl >
76
+ < dt id ="slack_bolt.adapter.aws_lambda.SlackRequestHandler "> < code class ="flex name class ">
77
+ < span > class < span class ="ident "> SlackRequestHandler</ span > </ span >
78
+ < span > (</ span > < span > app: < a title ="slack_bolt.app.app.App " href ="../../app/app.html#slack_bolt.app.app.App "> App</ a > )</ span >
79
+ </ code > </ dt >
80
+ < dd >
81
+ < div class ="desc "> </ div >
82
+ < details class ="source ">
83
+ < summary >
84
+ < span > Expand source code</ span >
85
+ </ summary >
86
+ < pre > < code class ="python "> class SlackRequestHandler:
87
+ def __init__(self, app: App): # type: ignore
88
+ self.app = app
89
+ self.logger = get_bolt_app_logger(app.name, SlackRequestHandler, app.logger)
90
+ self.app.listener_runner.lazy_listener_runner = LambdaLazyListenerRunner(
91
+ self.logger
92
+ )
93
+ if self.app.oauth_flow is not None:
94
+ self.app.oauth_flow.settings.redirect_uri_page_renderer.install_path = "?"
95
+
96
+ @classmethod
97
+ def clear_all_log_handlers(cls):
98
+ # https://stackoverflow.com/questions/37703609/using-python-logging-with-aws-lambda
99
+ root = logging.getLogger()
100
+ if root.handlers:
101
+ for handler in root.handlers:
102
+ root.removeHandler(handler)
103
+
104
+ def handle(self, event, context):
105
+ self.logger.debug(f"Incoming event: {event}, context: {context}")
106
+
107
+ method = event.get("requestContext", {}).get("http", {}).get("method")
108
+ if method is None:
109
+ method = event.get("requestContext", {}).get("httpMethod")
110
+
111
+ if method is None:
112
+ return not_found()
113
+ if method == "GET":
114
+ if self.app.oauth_flow is not None:
115
+ oauth_flow: OAuthFlow = self.app.oauth_flow
116
+ bolt_req: BoltRequest = to_bolt_request(event)
117
+ query = bolt_req.query
118
+ is_callback = query is not None and (
119
+ (
120
+ _first_value(query, "code") is not None
121
+ and _first_value(query, "state") is not None
122
+ )
123
+ or _first_value(query, "error") is not None
124
+ )
125
+ if is_callback:
126
+ bolt_resp = oauth_flow.handle_callback(bolt_req)
127
+ return to_aws_response(bolt_resp)
128
+ else:
129
+ bolt_resp = oauth_flow.handle_installation(bolt_req)
130
+ return to_aws_response(bolt_resp)
131
+ elif method == "POST":
132
+ bolt_req = to_bolt_request(event)
133
+ # https://docs.aws.amazon.com/lambda/latest/dg/python-context.html
134
+ aws_lambda_function_name = context.function_name
135
+ bolt_req.context["aws_lambda_function_name"] = aws_lambda_function_name
136
+ bolt_req.context["lambda_request"] = event
137
+ bolt_resp = self.app.dispatch(bolt_req)
138
+ aws_response = to_aws_response(bolt_resp)
139
+ return aws_response
140
+ elif method == "NONE":
141
+ bolt_req = to_bolt_request(event)
142
+ bolt_resp = self.app.dispatch(bolt_req)
143
+ aws_response = to_aws_response(bolt_resp)
144
+ return aws_response
145
+
146
+ return not_found()</ code > </ pre >
147
+ </ details >
148
+ < h3 > Static methods</ h3 >
149
+ < dl >
150
+ < dt id ="slack_bolt.adapter.aws_lambda.SlackRequestHandler.clear_all_log_handlers "> < code class ="name flex ">
151
+ < span > def < span class ="ident "> clear_all_log_handlers</ span > </ span > (< span > )</ span >
152
+ </ code > </ dt >
153
+ < dd >
154
+ < div class ="desc "> </ div >
155
+ < details class ="source ">
156
+ < summary >
157
+ < span > Expand source code</ span >
158
+ </ summary >
159
+ < pre > < code class ="python "> @classmethod
160
+ def clear_all_log_handlers(cls):
161
+ # https://stackoverflow.com/questions/37703609/using-python-logging-with-aws-lambda
162
+ root = logging.getLogger()
163
+ if root.handlers:
164
+ for handler in root.handlers:
165
+ root.removeHandler(handler)</ code > </ pre >
166
+ </ details >
167
+ </ dd >
168
+ </ dl >
169
+ < h3 > Methods</ h3 >
170
+ < dl >
171
+ < dt id ="slack_bolt.adapter.aws_lambda.SlackRequestHandler.handle "> < code class ="name flex ">
172
+ < span > def < span class ="ident "> handle</ span > </ span > (< span > self, event, context)</ span >
173
+ </ code > </ dt >
174
+ < dd >
175
+ < div class ="desc "> </ div >
176
+ < details class ="source ">
177
+ < summary >
178
+ < span > Expand source code</ span >
179
+ </ summary >
180
+ < pre > < code class ="python "> def handle(self, event, context):
181
+ self.logger.debug(f"Incoming event: {event}, context: {context}")
182
+
183
+ method = event.get("requestContext", {}).get("http", {}).get("method")
184
+ if method is None:
185
+ method = event.get("requestContext", {}).get("httpMethod")
186
+
187
+ if method is None:
188
+ return not_found()
189
+ if method == "GET":
190
+ if self.app.oauth_flow is not None:
191
+ oauth_flow: OAuthFlow = self.app.oauth_flow
192
+ bolt_req: BoltRequest = to_bolt_request(event)
193
+ query = bolt_req.query
194
+ is_callback = query is not None and (
195
+ (
196
+ _first_value(query, "code") is not None
197
+ and _first_value(query, "state") is not None
198
+ )
199
+ or _first_value(query, "error") is not None
200
+ )
201
+ if is_callback:
202
+ bolt_resp = oauth_flow.handle_callback(bolt_req)
203
+ return to_aws_response(bolt_resp)
204
+ else:
205
+ bolt_resp = oauth_flow.handle_installation(bolt_req)
206
+ return to_aws_response(bolt_resp)
207
+ elif method == "POST":
208
+ bolt_req = to_bolt_request(event)
209
+ # https://docs.aws.amazon.com/lambda/latest/dg/python-context.html
210
+ aws_lambda_function_name = context.function_name
211
+ bolt_req.context["aws_lambda_function_name"] = aws_lambda_function_name
212
+ bolt_req.context["lambda_request"] = event
213
+ bolt_resp = self.app.dispatch(bolt_req)
214
+ aws_response = to_aws_response(bolt_resp)
215
+ return aws_response
216
+ elif method == "NONE":
217
+ bolt_req = to_bolt_request(event)
218
+ bolt_resp = self.app.dispatch(bolt_req)
219
+ aws_response = to_aws_response(bolt_resp)
220
+ return aws_response
221
+
222
+ return not_found()</ code > </ pre >
223
+ </ details >
224
+ </ dd >
225
+ </ dl >
226
+ </ dd >
227
+ </ dl >
70
228
</ section >
71
229
</ article >
72
230
< nav id ="sidebar ">
@@ -91,6 +249,17 @@ <h1>Index</h1>
91
249
< li > < code > < a title ="slack_bolt.adapter.aws_lambda.local_lambda_client " href ="local_lambda_client.html "> slack_bolt.adapter.aws_lambda.local_lambda_client</ a > </ code > </ li >
92
250
</ ul >
93
251
</ li >
252
+ < li > < h3 > < a href ="#header-classes "> Classes</ a > </ h3 >
253
+ < ul >
254
+ < li >
255
+ < h4 > < code > < a title ="slack_bolt.adapter.aws_lambda.SlackRequestHandler " href ="#slack_bolt.adapter.aws_lambda.SlackRequestHandler "> SlackRequestHandler</ a > </ code > </ h4 >
256
+ < ul class ="">
257
+ < li > < code > < a title ="slack_bolt.adapter.aws_lambda.SlackRequestHandler.clear_all_log_handlers " href ="#slack_bolt.adapter.aws_lambda.SlackRequestHandler.clear_all_log_handlers "> clear_all_log_handlers</ a > </ code > </ li >
258
+ < li > < code > < a title ="slack_bolt.adapter.aws_lambda.SlackRequestHandler.handle " href ="#slack_bolt.adapter.aws_lambda.SlackRequestHandler.handle "> handle</ a > </ code > </ li >
259
+ </ ul >
260
+ </ li >
261
+ </ ul >
262
+ </ li >
94
263
</ ul >
95
264
</ nav >
96
265
</ main >
0 commit comments