Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions slack_bolt/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,11 @@
from slack_bolt.oauth.oauth_settings import OAuthSettings
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import create_web_client, get_boot_message
from slack_bolt.util.utils import (
create_web_client,
get_boot_message,
get_name_for_callable,
)
from slack_bolt.workflows.step import WorkflowStep, WorkflowStepMiddleware


Expand Down Expand Up @@ -347,7 +351,7 @@ def middleware_next():
return resp

for listener in self._listeners:
listener_name = listener.ack_function.__name__
listener_name = get_name_for_callable(listener.ack_function)
self._framework_logger.debug(debug_checking_listener(listener_name))
if listener.matches(req=req, resp=resp):
# run all the middleware attached to this listener first
Expand Down
5 changes: 3 additions & 2 deletions slack_bolt/app/async_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
AsyncMessageListenerMatches,
)
from slack_bolt.oauth.async_internals import select_consistent_installation_store
from slack_bolt.util.utils import get_name_for_callable
from slack_bolt.workflows.step.async_step import AsyncWorkflowStep
from slack_bolt.workflows.step.async_step_middleware import AsyncWorkflowStepMiddleware
from slack_sdk.oauth.installation_store.async_installation_store import (
Expand Down Expand Up @@ -385,7 +386,7 @@ async def async_middleware_next():
return resp

for listener in self._async_listeners:
listener_name = listener.ack_function.__name__
listener_name = get_name_for_callable(listener.ack_function)
self._framework_logger.debug(debug_checking_listener(listener_name))
if await listener.async_matches(req=req, resp=resp):
# run all the middleware attached to this listener first
Expand Down Expand Up @@ -917,7 +918,7 @@ def _register_listener(

for func in functions:
if not inspect.iscoroutinefunction(func):
name = func.__name__
name = get_name_for_callable(func)
raise BoltError(error_listener_function_must_be_coro_func(name))

listener_matchers = [
Expand Down
8 changes: 4 additions & 4 deletions slack_bolt/listener/asyncio_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
)
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import create_copy, name_for_callable
from slack_bolt.util.utils import create_copy, get_name_for_callable


class AsyncioListenerRunner:
Expand Down Expand Up @@ -71,7 +71,7 @@ async def run(

for lazy_func in listener.lazy_functions:
if request.lazy_function_name:
func_name = name_for_callable(lazy_func)
func_name = get_name_for_callable(lazy_func)
if func_name == request.lazy_function_name:
await self.lazy_listener_runner.run(
function=lazy_func, request=request
Expand Down Expand Up @@ -128,7 +128,7 @@ async def run_ack_function_asynchronously(

for lazy_func in listener.lazy_functions:
if request.lazy_function_name:
func_name = name_for_callable(lazy_func)
func_name = get_name_for_callable(lazy_func)
if func_name == request.lazy_function_name:
await self.lazy_listener_runner.run(
function=lazy_func, request=request
Expand Down Expand Up @@ -163,7 +163,7 @@ def _start_lazy_function(
self, lazy_func: Callable[..., Awaitable[None]], request: AsyncBoltRequest
) -> None:
# Start a lazy function asynchronously
func_name: str = name_for_callable(lazy_func)
func_name: str = get_name_for_callable(lazy_func)
self.logger.debug(debug_running_lazy_listener(func_name))
copied_request = self._build_lazy_request(request, func_name)
self.lazy_listener_runner.start(function=lazy_func, request=copied_request)
Expand Down
8 changes: 4 additions & 4 deletions slack_bolt/listener/thread_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import create_copy, name_for_callable
from slack_bolt.util.utils import create_copy, get_name_for_callable


class ThreadListenerRunner:
Expand Down Expand Up @@ -72,7 +72,7 @@ def run( # type: ignore

for lazy_func in listener.lazy_functions:
if request.lazy_function_name:
func_name = name_for_callable(lazy_func)
func_name = get_name_for_callable(lazy_func)
if func_name == request.lazy_function_name:
self.lazy_listener_runner.run(
function=lazy_func, request=request
Expand Down Expand Up @@ -127,7 +127,7 @@ def run_ack_function_asynchronously():

for lazy_func in listener.lazy_functions:
if request.lazy_function_name:
func_name = name_for_callable(lazy_func)
func_name = get_name_for_callable(lazy_func)
if func_name == request.lazy_function_name:
self.lazy_listener_runner.run(
function=lazy_func, request=request
Expand Down Expand Up @@ -162,7 +162,7 @@ def _start_lazy_function(
self, lazy_func: Callable[..., None], request: BoltRequest
) -> None:
# Start a lazy function asynchronously
func_name: str = name_for_callable(lazy_func)
func_name: str = get_name_for_callable(lazy_func)
self.logger.debug(debug_running_lazy_listener(func_name))
copied_request = self._build_lazy_request(request, func_name)
self.lazy_listener_runner.start(function=lazy_func, request=copied_request)
Expand Down
4 changes: 2 additions & 2 deletions slack_bolt/middleware/async_custom_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse
from .async_middleware import AsyncMiddleware
from slack_bolt.util.utils import name_for_callable
from slack_bolt.util.utils import get_name_for_callable


class AsyncCustomMiddleware(AsyncMiddleware):
Expand Down Expand Up @@ -46,4 +46,4 @@ async def async_process(

@property
def name(self) -> str:
return f"AsyncCustomMiddleware(func={name_for_callable(self.func)})"
return f"AsyncCustomMiddleware(func={get_name_for_callable(self.func)})"
4 changes: 2 additions & 2 deletions slack_bolt/middleware/custom_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse
from .middleware import Middleware
from slack_bolt.util.utils import name_for_callable
from slack_bolt.util.utils import get_name_for_callable


class CustomMiddleware(Middleware):
Expand Down Expand Up @@ -42,4 +42,4 @@ def process(

@property
def name(self) -> str:
return f"CustomMiddleware(func={name_for_callable(self.func)})"
return f"CustomMiddleware(func={get_name_for_callable(self.func)})"
12 changes: 8 additions & 4 deletions slack_bolt/util/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,13 @@ def get_boot_message(development_server: bool = False) -> str:
return "⚡️ Bolt app is running!"


def name_for_callable(func: Callable) -> str:
def get_name_for_callable(func: Callable) -> str:
"""Returns the name for the given Callable function object.

:param func: either a Callable instance or a function, which as __name__
:return: name of the given Callable object
"""
if hasattr(func, "__name__"):
func_name = func.__name__
return func.__name__
else:
func_name = f"{func.__class__.__module__}.{func.__class__.__name__}"
return func_name
return f"{func.__class__.__module__}.{func.__class__.__name__}"
3 changes: 2 additions & 1 deletion slack_bolt/workflows/step/async_step_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from slack_bolt.middleware.async_middleware import AsyncMiddleware
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import get_name_for_callable
from slack_bolt.workflows.step.async_step import AsyncWorkflowStep


Expand Down Expand Up @@ -51,6 +52,6 @@ async def _run(
return await self.listener_runner.run(
request=req,
response=resp,
listener_name=listener.ack_function.__name__,
listener_name=get_name_for_callable(listener.ack_function),
listener=listener,
)
3 changes: 2 additions & 1 deletion slack_bolt/workflows/step/step_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from slack_bolt.middleware import Middleware
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.util.utils import get_name_for_callable
from slack_bolt.workflows.step.step import WorkflowStep


Expand Down Expand Up @@ -49,6 +50,6 @@ def _run(
return self.listener_runner.run(
request=req,
response=resp,
listener_name=listener.ack_function.__name__,
listener_name=get_name_for_callable(listener.ack_function),
listener=listener,
)