@@ -61,11 +61,14 @@ def __init__(self, *args, **kwargs):
6161 self ._is_valid_app_id = self .request .data .get ("api_app_id" ) == self .slack_config .get ("app_id" )
6262
6363 self ._request_slash_command = self .request .data .get ("command" )
64+ self ._request_slash_command_text = self .request .data .get ("text" )
6465 self ._configured_slash_command = self .slack_config .get ("slash_command_name" )
6566
6667 is_valid_slash_command = False
6768 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+ )
6972
7073 self ._is_valid_slash_command = is_valid_slash_command
7174
@@ -226,34 +229,45 @@ def _get_slack_processor_actor_configs(self, input_data):
226229 )
227230
228231 def _is_app_accessible (self ):
232+ error_message = ""
233+
229234 if (
230235 self .request .headers .get (
231236 "X-Slack-Request-Timestamp" ,
232237 )
233238 is None
234239 or self .request .headers .get ("X-Slack-Signature" ) is None
235240 ):
236- raise Exception ( "Invalid Slack request" )
241+ error_message = "Invalid Slack request"
237242
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"
240245
241246 elif not self ._is_valid_app_id :
242- raise Exception ( "Invalid App ID" )
247+ error_message = "Invalid App ID"
243248
244249 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 '-' } `"
246257
247258 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 } `"
249260
250261 # Validate that the app token, app ID and the request type are all valid.
251262 elif not (
252263 self ._is_valid_app_token
253264 and self ._is_valid_app_id
254265 and (self ._is_valid_request_type or self ._is_valid_slash_command )
255266 ):
256- raise Exception ("Invalid Slack request" )
267+ error_message = "Invalid Slack request"
268+
269+ if error_message :
270+ raise Exception (error_message )
257271
258272 # URL verification is allowed without any further checks
259273 if self ._request_type == "url_verification" :
@@ -422,7 +436,11 @@ def _get_actor_configs(
422436
423437 def run_app (self ):
424438 # 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 )} " }
426444
427445 csp = self ._get_csp ()
428446
@@ -462,12 +480,6 @@ def run_app(self):
462480 template ,
463481 )
464482
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-
471483 return {
472- "message" : message ,
484+ "message" : f"Processing the Command - ` { self . request . data . get ( 'command' ) } { self . request . data . get ( 'text' ) } `" ,
473485 }
0 commit comments