@@ -327,11 +327,11 @@ def middleware_next():
327327 # -------------------------
328328 # middleware
329329
330- def use (self , * args ) -> None :
330+ def use (self , * args ) -> Optional [ Callable ] :
331331 """Refer to middleware method's docstring for details."""
332332 return self .middleware (* args )
333333
334- def middleware (self , * args ) -> None :
334+ def middleware (self , * args ) -> Optional [ Callable ] :
335335 """Registers a new middleware to this Bolt app.
336336
337337 :param args: a list of middleware. Passing a single middleware is supported.
@@ -341,10 +341,16 @@ def middleware(self, *args) -> None:
341341 middleware_or_callable = args [0 ]
342342 if isinstance (middleware_or_callable , Middleware ):
343343 self ._middleware_list .append (middleware_or_callable )
344- else :
344+ elif isinstance ( middleware_or_callable , Callable ) :
345345 self ._middleware_list .append (
346346 CustomMiddleware (app_name = self .name , func = middleware_or_callable )
347347 )
348+ return middleware_or_callable
349+ else :
350+ raise BoltError (
351+ f"Unexpected type for a middleware ({ type (middleware_or_callable )} )"
352+ )
353+ return None
348354
349355 # -------------------------
350356 # Workflows: Steps from Apps
@@ -372,7 +378,9 @@ def step(
372378 # -------------------------
373379 # global error handler
374380
375- def error (self , func : Callable [..., None ]) -> None :
381+ def error (
382+ self , func : Callable [..., None ]
383+ ) -> Optional [Callable [..., Optional [BoltResponse ]]]:
376384 """Updates the global error handler.
377385
378386 :param func: The function that is supposed to be executed
@@ -382,6 +390,7 @@ def error(self, func: Callable[..., None]) -> None:
382390 self ._listener_runner .listener_error_handler = CustomListenerErrorHandler (
383391 logger = self ._framework_logger , func = func ,
384392 )
393+ return func
385394
386395 # -------------------------
387396 # events
@@ -391,7 +400,7 @@ def event(
391400 event : Union [str , Pattern , Dict [str , str ]],
392401 matchers : Optional [List [Callable [..., bool ]]] = None ,
393402 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
394- ) -> Callable [..., None ]:
403+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
395404 """Registers a new event listener.
396405
397406 :param event: The conditions to match against a request payload
@@ -414,7 +423,7 @@ def message(
414423 keyword : Union [str , Pattern ],
415424 matchers : Optional [List [Callable [..., bool ]]] = None ,
416425 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
417- ) -> Callable [..., None ]:
426+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
418427 """Registers a new message event listener.
419428 Check the #event method's docstring for details.
420429 """
@@ -441,7 +450,7 @@ def command(
441450 command : Union [str , Pattern ],
442451 matchers : Optional [List [Callable [..., bool ]]] = None ,
443452 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
444- ) -> Callable [..., None ]:
453+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
445454 """Registers a new slash command listener.
446455
447456 :param command: The conditions to match against a request payload
@@ -467,7 +476,7 @@ def shortcut(
467476 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
468477 matchers : Optional [List [Callable [..., bool ]]] = None ,
469478 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
470- ) -> Callable [..., None ]:
479+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
471480 """Registers a new shortcut listener.
472481
473482 :param constraints: The conditions to match against a request payload
@@ -490,7 +499,7 @@ def global_shortcut(
490499 callback_id : Union [str , Pattern ],
491500 matchers : Optional [List [Callable [..., bool ]]] = None ,
492501 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
493- ) -> Callable [..., None ]:
502+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
494503 """Registers a new global shortcut listener."""
495504
496505 def __call__ (* args , ** kwargs ):
@@ -507,7 +516,7 @@ def message_shortcut(
507516 callback_id : Union [str , Pattern ],
508517 matchers : Optional [List [Callable [..., bool ]]] = None ,
509518 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
510- ) -> Callable [..., None ]:
519+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
511520 """Registers a new message shortcut listener."""
512521
513522 def __call__ (* args , ** kwargs ):
@@ -527,7 +536,7 @@ def action(
527536 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
528537 matchers : Optional [List [Callable [..., bool ]]] = None ,
529538 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
530- ) -> Callable [..., None ]:
539+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
531540 """Registers a new action listener.
532541
533542 :param constraints: The conditions to match against a request payload
@@ -550,7 +559,7 @@ def block_action(
550559 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
551560 matchers : Optional [List [Callable [..., bool ]]] = None ,
552561 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
553- ) -> Callable [..., None ]:
562+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
554563 """Registers a new block_actions listener."""
555564
556565 def __call__ (* args , ** kwargs ):
@@ -567,7 +576,7 @@ def attachment_action(
567576 callback_id : Union [str , Pattern ],
568577 matchers : Optional [List [Callable [..., bool ]]] = None ,
569578 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
570- ) -> Callable [..., None ]:
579+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
571580 """Registers a new interactive_message listener."""
572581
573582 def __call__ (* args , ** kwargs ):
@@ -584,7 +593,7 @@ def dialog_submission(
584593 callback_id : Union [str , Pattern ],
585594 matchers : Optional [List [Callable [..., bool ]]] = None ,
586595 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
587- ) -> Callable [..., None ]:
596+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
588597 """Registers a new dialog_submission listener."""
589598
590599 def __call__ (* args , ** kwargs ):
@@ -601,7 +610,7 @@ def dialog_cancellation(
601610 callback_id : Union [str , Pattern ],
602611 matchers : Optional [List [Callable [..., bool ]]] = None ,
603612 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
604- ) -> Callable [..., None ]:
613+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
605614 """Registers a new dialog_cancellation listener."""
606615
607616 def __call__ (* args , ** kwargs ):
@@ -621,7 +630,7 @@ def view(
621630 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
622631 matchers : Optional [List [Callable [..., bool ]]] = None ,
623632 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
624- ) -> Callable [..., None ]:
633+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
625634 """Registers a new view submission/closed event listener.
626635
627636 :param constraints: The conditions to match against a request payload
@@ -644,7 +653,7 @@ def view_submission(
644653 constraints : Union [str , Pattern ],
645654 matchers : Optional [List [Callable [..., bool ]]] = None ,
646655 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
647- ) -> Callable [..., None ]:
656+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
648657 """Registers a new view_submission listener."""
649658
650659 def __call__ (* args , ** kwargs ):
@@ -661,7 +670,7 @@ def view_closed(
661670 constraints : Union [str , Pattern ],
662671 matchers : Optional [List [Callable [..., bool ]]] = None ,
663672 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
664- ) -> Callable [..., None ]:
673+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
665674 """Registers a new view_closed listener."""
666675
667676 def __call__ (* args , ** kwargs ):
@@ -681,7 +690,7 @@ def options(
681690 constraints : Union [str , Pattern , Dict [str , Union [str , Pattern ]]],
682691 matchers : Optional [List [Callable [..., bool ]]] = None ,
683692 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
684- ) -> Callable [..., None ]:
693+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
685694 """Registers a new options listener.
686695
687696 :param constraints: The conditions to match against a request payload
@@ -704,7 +713,7 @@ def block_suggestion(
704713 action_id : Union [str , Pattern ],
705714 matchers : Optional [List [Callable [..., bool ]]] = None ,
706715 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
707- ) -> Callable [..., None ]:
716+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
708717 """Registers a new block_suggestion listener."""
709718
710719 def __call__ (* args , ** kwargs ):
@@ -721,7 +730,7 @@ def dialog_suggestion(
721730 callback_id : Union [str , Pattern ],
722731 matchers : Optional [List [Callable [..., bool ]]] = None ,
723732 middleware : Optional [List [Union [Callable , Middleware ]]] = None ,
724- ) -> Callable [..., None ]:
733+ ) -> Optional [ Callable [..., Optional [ BoltResponse ]] ]:
725734 """Registers a new dialog_submission listener."""
726735
727736 def __call__ (* args , ** kwargs ):
@@ -758,9 +767,14 @@ def _register_listener(
758767 matchers : Optional [List [Callable [..., bool ]]],
759768 middleware : Optional [List [Union [Callable , Middleware ]]],
760769 auto_acknowledgement : bool = False ,
761- ) -> None :
770+ ) -> Optional [Callable [..., Optional [BoltResponse ]]]:
771+ value_to_return = None
762772 if not isinstance (functions , list ):
763773 functions = list (functions )
774+ if len (functions ) == 1 :
775+ # In the case where the function is registered using decorator,
776+ # the registration should return the original function.
777+ value_to_return = functions [0 ]
764778
765779 listener_matchers = [
766780 CustomListenerMatcher (app_name = self .name , func = f ) for f in (matchers or [])
@@ -785,6 +799,7 @@ def _register_listener(
785799 auto_acknowledgement = auto_acknowledgement ,
786800 )
787801 )
802+ return value_to_return
788803
789804
790805# -------------------------
0 commit comments