|
86 | 86 | AsyncIgnoringSelfEvents, |
87 | 87 | AsyncUrlVerification, |
88 | 88 | AsyncAttachingFunctionToken, |
| 89 | + AsyncAttachingAgentKwargs, |
89 | 90 | ) |
90 | 91 | from slack_bolt.middleware.async_custom_middleware import ( |
91 | 92 | AsyncMiddleware, |
@@ -141,6 +142,7 @@ def __init__( |
141 | 142 | verification_token: Optional[str] = None, |
142 | 143 | # for AI Agents & Assistants |
143 | 144 | assistant_thread_context_store: Optional[AsyncAssistantThreadContextStore] = None, |
| 145 | + attaching_agent_kwargs_enabled: bool = True, |
144 | 146 | ): |
145 | 147 | """Bolt App that provides functionalities to register middleware/listeners. |
146 | 148 |
|
@@ -361,6 +363,7 @@ async def message_hello(message, say): # async function |
361 | 363 | self._async_listeners: List[AsyncListener] = [] |
362 | 364 |
|
363 | 365 | self._assistant_thread_context_store = assistant_thread_context_store |
| 366 | + self._attaching_agent_kwargs_enabled = attaching_agent_kwargs_enabled |
364 | 367 |
|
365 | 368 | self._process_before_response = process_before_response |
366 | 369 | self._async_listener_runner = AsyncioListenerRunner( |
@@ -864,10 +867,13 @@ async def ask_for_introduction(event, say): |
864 | 867 | middleware: A list of lister middleware functions. |
865 | 868 | Only when all the middleware call `next()` method, the listener function can be invoked. |
866 | 869 | """ |
| 870 | + middleware = list(middleware) if middleware else [] |
867 | 871 |
|
868 | 872 | def __call__(*args, **kwargs): |
869 | 873 | functions = self._to_listener_functions(kwargs) if kwargs else list(args) |
870 | 874 | primary_matcher = builtin_matchers.event(event, True, base_logger=self._base_logger) |
| 875 | + if self._attaching_agent_kwargs_enabled: |
| 876 | + middleware.insert(0, AsyncAttachingAgentKwargs(self._assistant_thread_context_store)) |
871 | 877 | return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) |
872 | 878 |
|
873 | 879 | return __call__ |
@@ -928,6 +934,8 @@ def __call__(*args, **kwargs): |
928 | 934 | asyncio=True, |
929 | 935 | base_logger=self._base_logger, |
930 | 936 | ) |
| 937 | + if self._attaching_agent_kwargs_enabled: |
| 938 | + middleware.insert(0, AsyncAttachingAgentKwargs(self._assistant_thread_context_store)) |
931 | 939 | middleware.insert(0, AsyncMessageListenerMatches(keyword)) |
932 | 940 | return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) |
933 | 941 |
|
|
0 commit comments