@@ -61,11 +61,14 @@ def __init__(self, *args, **kwargs):
61
61
self ._is_valid_app_id = self .request .data .get ("api_app_id" ) == self .slack_config .get ("app_id" )
62
62
63
63
self ._request_slash_command = self .request .data .get ("command" )
64
+ self ._request_slash_command_text = self .request .data .get ("text" )
64
65
self ._configured_slash_command = self .slack_config .get ("slash_command_name" )
65
66
66
67
is_valid_slash_command = False
67
68
if self ._request_slash_command and self ._configured_slash_command :
68
- is_valid_slash_command = self ._request_slash_command == self ._configured_slash_command
69
+ is_valid_slash_command = (
70
+ self ._request_slash_command == self ._configured_slash_command and self ._request_slash_command_text
71
+ )
69
72
70
73
self ._is_valid_slash_command = is_valid_slash_command
71
74
@@ -226,34 +229,45 @@ def _get_slack_processor_actor_configs(self, input_data):
226
229
)
227
230
228
231
def _is_app_accessible (self ):
232
+ error_message = ""
233
+
229
234
if (
230
235
self .request .headers .get (
231
236
"X-Slack-Request-Timestamp" ,
232
237
)
233
238
is None
234
239
or self .request .headers .get ("X-Slack-Signature" ) is None
235
240
):
236
- raise Exception ( "Invalid Slack request" )
241
+ error_message = "Invalid Slack request"
237
242
238
- if not self ._is_valid_app_token :
239
- raise Exception ( "Invalid App Token" )
243
+ elif not self ._is_valid_app_token :
244
+ error_message = "Invalid App Token"
240
245
241
246
elif not self ._is_valid_app_id :
242
- raise Exception ( "Invalid App ID" )
247
+ error_message = "Invalid App ID"
243
248
244
249
elif self ._request_slash_command and not self ._is_valid_slash_command :
245
- raise Exception ("Invalid Slash Command" )
250
+ error_message = f"Invalid Slack Command - `{ self .request .data .get ('command' )} `"
251
+
252
+ elif self ._request_type and not self ._is_valid_request_type :
253
+ error_message = "Invalid Slack request type. Only url_verification and event_callback are allowed."
254
+
255
+ if self ._request_slash_command and not self ._request_slash_command_text :
256
+ error_message = f"Invalid Slash Command arguments. Command: `{ self .request .data .get ('command' )} `. Arguments: `{ self .request .data .get ('text' ) or '-' } `"
246
257
247
258
elif self ._request_type and not self ._is_valid_request_type :
248
- raise Exception ( "Invalid Slack request type. Only url_verification and event_callback are allowed." )
259
+ error_message = f "Invalid Slack event request type - ` { self . _request_type } `"
249
260
250
261
# Validate that the app token, app ID and the request type are all valid.
251
262
elif not (
252
263
self ._is_valid_app_token
253
264
and self ._is_valid_app_id
254
265
and (self ._is_valid_request_type or self ._is_valid_slash_command )
255
266
):
256
- raise Exception ("Invalid Slack request" )
267
+ error_message = "Invalid Slack request"
268
+
269
+ if error_message :
270
+ raise Exception (error_message )
257
271
258
272
# URL verification is allowed without any further checks
259
273
if self ._request_type == "url_verification" :
@@ -422,7 +436,11 @@ def _get_actor_configs(
422
436
423
437
def run_app (self ):
424
438
# Check if the app access permissions are valid
425
- self ._is_app_accessible ()
439
+
440
+ try :
441
+ self ._is_app_accessible ()
442
+ except Exception as e :
443
+ return {"message" : f"{ str (e )} " }
426
444
427
445
csp = self ._get_csp ()
428
446
@@ -462,12 +480,6 @@ def run_app(self):
462
480
template ,
463
481
)
464
482
465
- message = ""
466
- if self ._is_valid_slash_command :
467
- message = f"Processing the Command - `{ self .request .data .get ('command' )} { self .request .data .get ('text' )} `"
468
- elif self ._request_slash_command and not self ._is_valid_slash_command :
469
- message = f"Invalid Slack Command - `{ self .request .data .get ('command' )} `"
470
-
471
483
return {
472
- "message" : message ,
484
+ "message" : f"Processing the Command - ` { self . request . data . get ( 'command' ) } { self . request . data . get ( 'text' ) } `" ,
473
485
}
0 commit comments