diff --git a/docs/reference/app/app.html b/docs/reference/app/app.html index c91d020ef..bf0d5ee00 100644 --- a/docs/reference/app/app.html +++ b/docs/reference/app/app.html @@ -48,7 +48,7 @@

Classes

class App -(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
token_verification_enabled: bool = True,
client: slack_sdk.web.client.WebClient | None = None,
before_authorize: Middleware | Callable[..., Any] | None = None,
authorize: Callable[..., AuthorizeResult] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: OAuthSettings | None = None,
oauth_flow: OAuthFlow | None = None,
verification_token: str | None = None,
listener_executor: concurrent.futures._base.Executor | None = None,
assistant_thread_context_store: AssistantThreadContextStore | None = None)
+(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
token_verification_enabled: bool = True,
client: slack_sdk.web.client.WebClient | None = None,
before_authorize: Middleware | Callable[..., Any] | None = None,
authorize: Callable[..., AuthorizeResult] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: OAuthSettings | None = None,
oauth_flow: OAuthFlow | None = None,
verification_token: str | None = None,
listener_executor: concurrent.futures._base.Executor | None = None,
assistant_thread_context_store: AssistantThreadContextStore | None = None,
attaching_conversation_kwargs_enabled: bool = True)
@@ -95,6 +95,7 @@

Classes

listener_executor: Optional[Executor] = None, # for AI Agents & Assistants assistant_thread_context_store: Optional[AssistantThreadContextStore] = None, + attaching_conversation_kwargs_enabled: bool = True, ): """Bolt App that provides functionalities to register middleware/listeners. @@ -315,6 +316,7 @@

Classes

listener_executor = ThreadPoolExecutor(max_workers=5) self._assistant_thread_context_store = assistant_thread_context_store + self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled self._process_before_response = process_before_response self._listener_runner = ThreadListenerRunner( @@ -799,10 +801,13 @@

Classes

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -860,6 +865,8 @@

Classes

primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -1356,20 +1363,6 @@

Classes

# It is intended for apps that start lazy listeners from their custom global middleware. req.context["listener_runner"] = self.listener_runner - # For AI Agents & Assistants - if is_assistant_event(req.body): - assistant = AssistantUtilities( - payload=to_event(req.body), # type:ignore[arg-type] - context=req.context, - thread_context_store=self._assistant_thread_context_store, - ) - req.context["say"] = assistant.say - req.context["set_status"] = assistant.set_status - req.context["set_title"] = assistant.set_title - req.context["set_suggested_prompts"] = assistant.set_suggested_prompts - req.context["get_thread_context"] = assistant.get_thread_context - req.context["save_thread_context"] = assistant.save_thread_context - @staticmethod def _to_listener_functions( kwargs: dict, @@ -1415,7 +1408,7 @@

Classes

CustomListener( app_name=self.name, ack_function=functions.pop(0), - lazy_functions=functions, # type:ignore[arg-type] + lazy_functions=functions, # type: ignore[arg-type] matchers=listener_matchers, middleware=listener_middleware, auto_acknowledgement=auto_acknowledgement, @@ -2203,10 +2196,13 @@

Args

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -2410,6 +2406,8 @@

Args

primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) diff --git a/docs/reference/app/async_app.html b/docs/reference/app/async_app.html index 9cbc801d0..cf4c651cb 100644 --- a/docs/reference/app/async_app.html +++ b/docs/reference/app/async_app.html @@ -48,7 +48,7 @@

Classes

class AsyncApp -(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
client: slack_sdk.web.async_client.AsyncWebClient | None = None,
before_authorize: AsyncMiddleware | Callable[..., Awaitable[Any]] | None = None,
authorize: Callable[..., Awaitable[AuthorizeResult]] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: AsyncOAuthSettings | None = None,
oauth_flow: AsyncOAuthFlow | None = None,
verification_token: str | None = None,
assistant_thread_context_store: AsyncAssistantThreadContextStore | None = None)
+(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
client: slack_sdk.web.async_client.AsyncWebClient | None = None,
before_authorize: AsyncMiddleware | Callable[..., Awaitable[Any]] | None = None,
authorize: Callable[..., Awaitable[AuthorizeResult]] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: AsyncOAuthSettings | None = None,
oauth_flow: AsyncOAuthFlow | None = None,
verification_token: str | None = None,
assistant_thread_context_store: AsyncAssistantThreadContextStore | None = None,
attaching_conversation_kwargs_enabled: bool = True)
@@ -92,6 +92,7 @@

Classes

verification_token: Optional[str] = None, # for AI Agents & Assistants assistant_thread_context_store: Optional[AsyncAssistantThreadContextStore] = None, + attaching_conversation_kwargs_enabled: bool = True, ): """Bolt App that provides functionalities to register middleware/listeners. @@ -312,6 +313,7 @@

Classes

self._async_listeners: List[AsyncListener] = [] self._assistant_thread_context_store = assistant_thread_context_store + self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled self._process_before_response = process_before_response self._async_listener_runner = AsyncioListenerRunner( @@ -565,7 +567,7 @@

Classes

self._framework_logger.debug(debug_checking_listener(listener_name)) if await listener.async_matches(req=req, resp=resp): # type: ignore[arg-type] # run all the middleware attached to this listener first - (middleware_resp, next_was_not_called) = await listener.run_async_middleware( + middleware_resp, next_was_not_called = await listener.run_async_middleware( req=req, resp=resp # type: ignore[arg-type] ) if next_was_not_called: @@ -815,10 +817,13 @@

Classes

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, True, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -879,6 +884,8 @@

Classes

asyncio=True, base_logger=self._base_logger, ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, AsyncMessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -1380,20 +1387,6 @@

Classes

# It is intended for apps that start lazy listeners from their custom global middleware. req.context["listener_runner"] = self.listener_runner - # For AI Agents & Assistants - if is_assistant_event(req.body): - assistant = AsyncAssistantUtilities( - payload=to_event(req.body), # type:ignore[arg-type] - context=req.context, - thread_context_store=self._assistant_thread_context_store, - ) - req.context["say"] = assistant.say - req.context["set_status"] = assistant.set_status - req.context["set_title"] = assistant.set_title - req.context["set_suggested_prompts"] = assistant.set_suggested_prompts - req.context["get_thread_context"] = assistant.get_thread_context - req.context["save_thread_context"] = assistant.save_thread_context - @staticmethod def _to_listener_functions( kwargs: dict, @@ -1444,7 +1437,7 @@

Classes

AsyncCustomListener( app_name=self.name, ack_function=functions.pop(0), - lazy_functions=functions, # type:ignore[arg-type] + lazy_functions=functions, # type: ignore[arg-type] matchers=listener_matchers, middleware=listener_middleware, auto_acknowledgement=auto_acknowledgement, @@ -1794,7 +1787,7 @@

Args

self._framework_logger.debug(debug_checking_listener(listener_name)) if await listener.async_matches(req=req, resp=resp): # type: ignore[arg-type] # run all the middleware attached to this listener first - (middleware_resp, next_was_not_called) = await listener.run_async_middleware( + middleware_resp, next_was_not_called = await listener.run_async_middleware( req=req, resp=resp # type: ignore[arg-type] ) if next_was_not_called: @@ -2243,10 +2236,13 @@

Args

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, True, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -2454,6 +2450,8 @@

Args

asyncio=True, base_logger=self._base_logger, ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, AsyncMessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) diff --git a/docs/reference/app/async_server.html b/docs/reference/app/async_server.html index b95b8a2b3..5eefe90dd 100644 --- a/docs/reference/app/async_server.html +++ b/docs/reference/app/async_server.html @@ -59,14 +59,14 @@

Classes

port: int path: str host: str - bolt_app: "AsyncApp" # type: ignore[name-defined] + bolt_app: "AsyncApp" web_app: web.Application def __init__( self, port: int, path: str, - app: "AsyncApp", # type: ignore[name-defined] + app: "AsyncApp", host: Optional[str] = None, ): """Standalone AIOHTTP Web Server. @@ -81,7 +81,7 @@

Classes

self.port = port self.path = path self.host = host if host is not None else "0.0.0.0" - self.bolt_app: "AsyncApp" = app # type: ignore[name-defined] + self.bolt_app: "AsyncApp" = app self.web_app = web.Application() self._bolt_oauth_flow = self.bolt_app.oauth_flow if self._bolt_oauth_flow: diff --git a/docs/reference/app/index.html b/docs/reference/app/index.html index 8821e5af9..32e006944 100644 --- a/docs/reference/app/index.html +++ b/docs/reference/app/index.html @@ -67,7 +67,7 @@

Classes

class App -(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
token_verification_enabled: bool = True,
client: slack_sdk.web.client.WebClient | None = None,
before_authorize: Middleware | Callable[..., Any] | None = None,
authorize: Callable[..., AuthorizeResult] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: OAuthSettings | None = None,
oauth_flow: OAuthFlow | None = None,
verification_token: str | None = None,
listener_executor: concurrent.futures._base.Executor | None = None,
assistant_thread_context_store: AssistantThreadContextStore | None = None)
+(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
token_verification_enabled: bool = True,
client: slack_sdk.web.client.WebClient | None = None,
before_authorize: Middleware | Callable[..., Any] | None = None,
authorize: Callable[..., AuthorizeResult] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: OAuthSettings | None = None,
oauth_flow: OAuthFlow | None = None,
verification_token: str | None = None,
listener_executor: concurrent.futures._base.Executor | None = None,
assistant_thread_context_store: AssistantThreadContextStore | None = None,
attaching_conversation_kwargs_enabled: bool = True)
@@ -114,6 +114,7 @@

Classes

listener_executor: Optional[Executor] = None, # for AI Agents & Assistants assistant_thread_context_store: Optional[AssistantThreadContextStore] = None, + attaching_conversation_kwargs_enabled: bool = True, ): """Bolt App that provides functionalities to register middleware/listeners. @@ -334,6 +335,7 @@

Classes

listener_executor = ThreadPoolExecutor(max_workers=5) self._assistant_thread_context_store = assistant_thread_context_store + self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled self._process_before_response = process_before_response self._listener_runner = ThreadListenerRunner( @@ -818,10 +820,13 @@

Classes

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -879,6 +884,8 @@

Classes

primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -1375,20 +1382,6 @@

Classes

# It is intended for apps that start lazy listeners from their custom global middleware. req.context["listener_runner"] = self.listener_runner - # For AI Agents & Assistants - if is_assistant_event(req.body): - assistant = AssistantUtilities( - payload=to_event(req.body), # type:ignore[arg-type] - context=req.context, - thread_context_store=self._assistant_thread_context_store, - ) - req.context["say"] = assistant.say - req.context["set_status"] = assistant.set_status - req.context["set_title"] = assistant.set_title - req.context["set_suggested_prompts"] = assistant.set_suggested_prompts - req.context["get_thread_context"] = assistant.get_thread_context - req.context["save_thread_context"] = assistant.save_thread_context - @staticmethod def _to_listener_functions( kwargs: dict, @@ -1434,7 +1427,7 @@

Classes

CustomListener( app_name=self.name, ack_function=functions.pop(0), - lazy_functions=functions, # type:ignore[arg-type] + lazy_functions=functions, # type: ignore[arg-type] matchers=listener_matchers, middleware=listener_middleware, auto_acknowledgement=auto_acknowledgement, @@ -2222,10 +2215,13 @@

Args

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -2429,6 +2425,8 @@

Args

primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) diff --git a/docs/reference/async_app.html b/docs/reference/async_app.html index 8fd975be9..3494ec289 100644 --- a/docs/reference/async_app.html +++ b/docs/reference/async_app.html @@ -139,7 +139,7 @@

Class variables

class AsyncApp -(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
client: slack_sdk.web.async_client.AsyncWebClient | None = None,
before_authorize: AsyncMiddleware | Callable[..., Awaitable[Any]] | None = None,
authorize: Callable[..., Awaitable[AuthorizeResult]] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: AsyncOAuthSettings | None = None,
oauth_flow: AsyncOAuthFlow | None = None,
verification_token: str | None = None,
assistant_thread_context_store: AsyncAssistantThreadContextStore | None = None)
+(*,
logger: logging.Logger | None = None,
name: str | None = None,
process_before_response: bool = False,
raise_error_for_unhandled_request: bool = False,
signing_secret: str | None = None,
token: str | None = None,
client: slack_sdk.web.async_client.AsyncWebClient | None = None,
before_authorize: AsyncMiddleware | Callable[..., Awaitable[Any]] | None = None,
authorize: Callable[..., Awaitable[AuthorizeResult]] | None = None,
user_facing_authorize_error_message: str | None = None,
installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
installation_store_bot_only: bool | None = None,
request_verification_enabled: bool = True,
ignoring_self_events_enabled: bool = True,
ignoring_self_assistant_message_events_enabled: bool = True,
ssl_check_enabled: bool = True,
url_verification_enabled: bool = True,
attaching_function_token_enabled: bool = True,
oauth_settings: AsyncOAuthSettings | None = None,
oauth_flow: AsyncOAuthFlow | None = None,
verification_token: str | None = None,
assistant_thread_context_store: AsyncAssistantThreadContextStore | None = None,
attaching_conversation_kwargs_enabled: bool = True)
@@ -183,6 +183,7 @@

Class variables

verification_token: Optional[str] = None, # for AI Agents & Assistants assistant_thread_context_store: Optional[AsyncAssistantThreadContextStore] = None, + attaching_conversation_kwargs_enabled: bool = True, ): """Bolt App that provides functionalities to register middleware/listeners. @@ -403,6 +404,7 @@

Class variables

self._async_listeners: List[AsyncListener] = [] self._assistant_thread_context_store = assistant_thread_context_store + self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled self._process_before_response = process_before_response self._async_listener_runner = AsyncioListenerRunner( @@ -656,7 +658,7 @@

Class variables

self._framework_logger.debug(debug_checking_listener(listener_name)) if await listener.async_matches(req=req, resp=resp): # type: ignore[arg-type] # run all the middleware attached to this listener first - (middleware_resp, next_was_not_called) = await listener.run_async_middleware( + middleware_resp, next_was_not_called = await listener.run_async_middleware( req=req, resp=resp # type: ignore[arg-type] ) if next_was_not_called: @@ -906,10 +908,13 @@

Class variables

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, True, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -970,6 +975,8 @@

Class variables

asyncio=True, base_logger=self._base_logger, ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, AsyncMessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -1471,20 +1478,6 @@

Class variables

# It is intended for apps that start lazy listeners from their custom global middleware. req.context["listener_runner"] = self.listener_runner - # For AI Agents & Assistants - if is_assistant_event(req.body): - assistant = AsyncAssistantUtilities( - payload=to_event(req.body), # type:ignore[arg-type] - context=req.context, - thread_context_store=self._assistant_thread_context_store, - ) - req.context["say"] = assistant.say - req.context["set_status"] = assistant.set_status - req.context["set_title"] = assistant.set_title - req.context["set_suggested_prompts"] = assistant.set_suggested_prompts - req.context["get_thread_context"] = assistant.get_thread_context - req.context["save_thread_context"] = assistant.save_thread_context - @staticmethod def _to_listener_functions( kwargs: dict, @@ -1535,7 +1528,7 @@

Class variables

AsyncCustomListener( app_name=self.name, ack_function=functions.pop(0), - lazy_functions=functions, # type:ignore[arg-type] + lazy_functions=functions, # type: ignore[arg-type] matchers=listener_matchers, middleware=listener_middleware, auto_acknowledgement=auto_acknowledgement, @@ -1885,7 +1878,7 @@

Args

self._framework_logger.debug(debug_checking_listener(listener_name)) if await listener.async_matches(req=req, resp=resp): # type: ignore[arg-type] # run all the middleware attached to this listener first - (middleware_resp, next_was_not_called) = await listener.run_async_middleware( + middleware_resp, next_was_not_called = await listener.run_async_middleware( req=req, resp=resp # type: ignore[arg-type] ) if next_was_not_called: @@ -2334,10 +2327,13 @@

Args

middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, True, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -2545,6 +2541,8 @@

Args

asyncio=True, base_logger=self._base_logger, ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AsyncAttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, AsyncMessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -3285,7 +3283,7 @@

Args

func=is_assistant_thread_started_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3294,7 +3292,7 @@

Args

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3331,7 +3329,7 @@

Args

func=is_user_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3340,7 +3338,7 @@

Args

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3377,7 +3375,7 @@

Args

func=is_bot_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3386,7 +3384,7 @@

Args

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3423,7 +3421,7 @@

Args

func=is_assistant_thread_context_changed_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3432,7 +3430,7 @@

Args

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3460,14 +3458,14 @@

Args

primary_matcher: Union[Callable[..., bool], AsyncListenerMatcher], custom_matchers: Optional[Union[Callable[..., bool], AsyncListenerMatcher]], ): - return [primary_matcher] + (custom_matchers or []) # type:ignore[operator] + return [primary_matcher] + (custom_matchers or []) # type: ignore[operator] @staticmethod async def default_thread_context_changed(save_thread_context: AsyncSaveThreadContext, payload: dict): new_context: dict = payload["assistant_thread"]["context"] await save_thread_context(new_context) - async def async_process( # type:ignore[return] + async def async_process( # type: ignore[return] self, *, req: AsyncBoltRequest, @@ -3487,6 +3485,15 @@

Args

if listeners is not None: for listener in listeners: if listener is not None and await listener.async_matches(req=req, resp=resp): + middleware_resp, next_was_not_called = await listener.run_async_middleware(req=req, resp=resp) + if next_was_not_called: + if middleware_resp is not None: + return middleware_resp + # The listener middleware didn't call next(). + # Skip this listener and try the next one. + continue + if middleware_resp is not None: + resp = middleware_resp return await listener_runner.run( request=req, response=resp, @@ -3506,13 +3513,14 @@

Args

middleware: Optional[List[AsyncMiddleware]] = None, base_logger: Optional[Logger] = None, ) -> AsyncListener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, AsyncListener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AsyncAttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -3524,7 +3532,7 @@

Args

else: listener_matchers.append( build_listener_matcher( - func=matcher, # type:ignore[arg-type] + func=matcher, # type: ignore[arg-type] asyncio=True, base_logger=base_logger, ) @@ -3599,7 +3607,7 @@

Methods

func=is_bot_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3608,7 +3616,7 @@

Methods

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3648,13 +3656,14 @@

Methods

middleware: Optional[List[AsyncMiddleware]] = None, base_logger: Optional[Logger] = None, ) -> AsyncListener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, AsyncListener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AsyncAttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -3666,7 +3675,7 @@

Methods

else: listener_matchers.append( build_listener_matcher( - func=matcher, # type:ignore[arg-type] + func=matcher, # type: ignore[arg-type] asyncio=True, base_logger=base_logger, ) @@ -3707,7 +3716,7 @@

Methods

func=is_assistant_thread_context_changed_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3716,7 +3725,7 @@

Methods

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3763,7 +3772,7 @@

Methods

func=is_assistant_thread_started_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3772,7 +3781,7 @@

Methods

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3819,7 +3828,7 @@

Methods

func=is_user_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -3828,7 +3837,7 @@

Methods

self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3898,7 +3907,7 @@

Inherited members

# The return type is intentionally string to avoid circular imports @property - def listener_runner(self) -> "AsyncioListenerRunner": # type: ignore[name-defined] + def listener_runner(self) -> "AsyncioListenerRunner": """The properly configured listener_runner that is available for middleware/listeners.""" return self["listener_runner"] @@ -3967,7 +3976,7 @@

Inherited members

Callable `say()` function """ if "say" not in self: - self["say"] = AsyncSay(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = AsyncSay(client=self.client, channel=self.channel_id) return self["say"] @property @@ -4060,6 +4069,10 @@

Inherited members

def get_thread_context(self) -> Optional[AsyncGetThreadContext]: return self.get("get_thread_context") + @property + def say_stream(self) -> Optional[AsyncSayStream]: + return self.get("say_stream") + @property def save_thread_context(self) -> Optional[AsyncSaveThreadContext]: return self.get("save_thread_context") @@ -4275,7 +4288,7 @@

Returns

Expand source code
@property
-def listener_runner(self) -> "AsyncioListenerRunner":  # type: ignore[name-defined]
+def listener_runner(self) -> "AsyncioListenerRunner":
     """The properly configured listener_runner that is available for middleware/listeners."""
     return self["listener_runner"]
@@ -4365,7 +4378,7 @@

Returns

Callable `say()` function """ if "say" not in self: - self["say"] = AsyncSay(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = AsyncSay(client=self.client, channel=self.channel_id) return self["say"]

say() function for this request.

@@ -4383,6 +4396,18 @@

Returns

Returns

Callable say() function

+
prop say_streamAsyncSayStream | None
+
+
+ +Expand source code + +
@property
+def say_stream(self) -> Optional[AsyncSayStream]:
+    return self.get("say_stream")
+
+
+
prop set_statusAsyncSetStatus | None
@@ -4742,14 +4767,10 @@

Inherited members

if self.thread_context_loaded is True: return self._thread_context - if self.payload.get("assistant_thread") is not None: + thread = self.payload.get("assistant_thread") + if isinstance(thread, dict) and thread.get("context", {}).get("channel_id") is not None: # assistant_thread_started - thread = self.payload["assistant_thread"] - self._thread_context = ( - AssistantThreadContext(thread["context"]) - if thread.get("context", {}).get("channel_id") is not None - else None - ) + self._thread_context = AssistantThreadContext(thread["context"]) # for this event, the context will never be changed self.thread_context_loaded = True elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None: @@ -5231,6 +5252,97 @@

Class variables

+
+class AsyncSayStream +(*,
client: slack_sdk.web.async_client.AsyncWebClient,
channel: str | None = None,
recipient_team_id: str | None = None,
recipient_user_id: str | None = None,
thread_ts: str | None = None)
+
+
+
+ +Expand source code + +
class AsyncSayStream:
+    client: AsyncWebClient
+    channel: Optional[str]
+    recipient_team_id: Optional[str]
+    recipient_user_id: Optional[str]
+    thread_ts: Optional[str]
+
+    def __init__(
+        self,
+        *,
+        client: AsyncWebClient,
+        channel: Optional[str] = None,
+        recipient_team_id: Optional[str] = None,
+        recipient_user_id: Optional[str] = None,
+        thread_ts: Optional[str] = None,
+    ):
+        self.client = client
+        self.channel = channel
+        self.recipient_team_id = recipient_team_id
+        self.recipient_user_id = recipient_user_id
+        self.thread_ts = thread_ts
+
+    async def __call__(
+        self,
+        *,
+        buffer_size: Optional[int] = None,
+        channel: Optional[str] = None,
+        recipient_team_id: Optional[str] = None,
+        recipient_user_id: Optional[str] = None,
+        thread_ts: Optional[str] = None,
+        **kwargs,
+    ) -> AsyncChatStream:
+        """Starts a new chat stream with context."""
+        channel = channel or self.channel
+        thread_ts = thread_ts or self.thread_ts
+        if channel is None:
+            raise ValueError("say_stream without channel here is unsupported")
+        if thread_ts is None:
+            raise ValueError("say_stream without thread_ts here is unsupported")
+
+        if buffer_size is not None:
+            return await self.client.chat_stream(
+                buffer_size=buffer_size,
+                channel=channel,
+                recipient_team_id=recipient_team_id or self.recipient_team_id,
+                recipient_user_id=recipient_user_id or self.recipient_user_id,
+                thread_ts=thread_ts,
+                **kwargs,
+            )
+        return await self.client.chat_stream(
+            channel=channel,
+            recipient_team_id=recipient_team_id or self.recipient_team_id,
+            recipient_user_id=recipient_user_id or self.recipient_user_id,
+            thread_ts=thread_ts,
+            **kwargs,
+        )
+
+
+

Class variables

+
+
var channel : str | None
+
+

The type of the None singleton.

+
+
var client : slack_sdk.web.async_client.AsyncWebClient
+
+

The type of the None singleton.

+
+
var recipient_team_id : str | None
+
+

The type of the None singleton.

+
+
var recipient_user_id : str | None
+
+

The type of the None singleton.

+
+
var thread_ts : str | None
+
+

The type of the None singleton.

+
+
+
class AsyncSetStatus (client: slack_sdk.web.async_client.AsyncWebClient,
channel_id: str,
thread_ts: str)
@@ -5485,6 +5597,7 @@

respond
  • save_thread_context
  • say
  • +
  • say_stream
  • set_status
  • set_suggested_prompts
  • set_title
  • @@ -5565,6 +5678,16 @@

    AsyncSayStream

    + + +
  • AsyncSetStatus

    • channel_id
    • diff --git a/docs/reference/authorization/authorize_result.html b/docs/reference/authorization/authorize_result.html index d53c5cd5c..6eac3724d 100644 --- a/docs/reference/authorization/authorize_result.html +++ b/docs/reference/authorization/authorize_result.html @@ -48,7 +48,7 @@

      Classes

      class AuthorizeResult -(*,
      enterprise_id: str | None,
      team_id: str | None,
      team: str | None = None,
      url: str | None = None,
      bot_user_id: str | None = None,
      bot_id: str | None = None,
      bot_token: str | None = None,
      bot_scopes: Sequence[str] | str | None = None,
      user_id: str | None = None,
      user: str | None = None,
      user_token: str | None = None,
      user_scopes: Sequence[str] | str | None = None)
      +(*,
      enterprise_id: str | None,
      team_id: str | None,
      team: str | None = None,
      url: str | None = None,
      bot_user_id: str | None = None,
      bot_id: str | None = None,
      bot_token: str | None = None,
      bot_scopes: str | Sequence[str] | None = None,
      user_id: str | None = None,
      user: str | None = None,
      user_token: str | None = None,
      user_scopes: str | Sequence[str] | None = None)
      @@ -246,7 +246,7 @@

      Class variables

      Static methods

      -def from_auth_test_response(*,
      bot_token: str | None = None,
      user_token: str | None = None,
      bot_scopes: Sequence[str] | str | None = None,
      user_scopes: Sequence[str] | str | None = None,
      auth_test_response: slack_sdk.web.slack_response.SlackResponse | AsyncSlackResponse,
      user_auth_test_response: slack_sdk.web.slack_response.SlackResponse | AsyncSlackResponse | None = None)
      +def from_auth_test_response(*,
      bot_token: str | None = None,
      user_token: str | None = None,
      bot_scopes: str | Sequence[str] | None = None,
      user_scopes: str | Sequence[str] | None = None,
      auth_test_response: slack_sdk.web.slack_response.SlackResponse | ForwardRef('AsyncSlackResponse'),
      user_auth_test_response: slack_sdk.web.slack_response.SlackResponse | ForwardRef('AsyncSlackResponse') | None = None)
      diff --git a/docs/reference/authorization/index.html b/docs/reference/authorization/index.html index 2fdd1f916..19de311df 100644 --- a/docs/reference/authorization/index.html +++ b/docs/reference/authorization/index.html @@ -75,7 +75,7 @@

      Classes

      class AuthorizeResult -(*,
      enterprise_id: str | None,
      team_id: str | None,
      team: str | None = None,
      url: str | None = None,
      bot_user_id: str | None = None,
      bot_id: str | None = None,
      bot_token: str | None = None,
      bot_scopes: Sequence[str] | str | None = None,
      user_id: str | None = None,
      user: str | None = None,
      user_token: str | None = None,
      user_scopes: Sequence[str] | str | None = None)
      +(*,
      enterprise_id: str | None,
      team_id: str | None,
      team: str | None = None,
      url: str | None = None,
      bot_user_id: str | None = None,
      bot_id: str | None = None,
      bot_token: str | None = None,
      bot_scopes: str | Sequence[str] | None = None,
      user_id: str | None = None,
      user: str | None = None,
      user_token: str | None = None,
      user_scopes: str | Sequence[str] | None = None)
      @@ -273,7 +273,7 @@

      Class variables

      Static methods

      -def from_auth_test_response(*,
      bot_token: str | None = None,
      user_token: str | None = None,
      bot_scopes: Sequence[str] | str | None = None,
      user_scopes: Sequence[str] | str | None = None,
      auth_test_response: slack_sdk.web.slack_response.SlackResponse | AsyncSlackResponse,
      user_auth_test_response: slack_sdk.web.slack_response.SlackResponse | AsyncSlackResponse | None = None)
      +def from_auth_test_response(*,
      bot_token: str | None = None,
      user_token: str | None = None,
      bot_scopes: str | Sequence[str] | None = None,
      user_scopes: str | Sequence[str] | None = None,
      auth_test_response: slack_sdk.web.slack_response.SlackResponse | ForwardRef('AsyncSlackResponse'),
      user_auth_test_response: slack_sdk.web.slack_response.SlackResponse | ForwardRef('AsyncSlackResponse') | None = None)
      diff --git a/docs/reference/context/assistant/assistant_utilities.html b/docs/reference/context/assistant/assistant_utilities.html index d446b3c02..40db52284 100644 --- a/docs/reference/context/assistant/assistant_utilities.html +++ b/docs/reference/context/assistant/assistant_utilities.html @@ -91,6 +91,13 @@

      Classes

      @property def set_status(self) -> SetStatus: + warnings.warn( + "AssistantUtilities.set_status is deprecated. " + "Use the set_status argument directly in your listener function " + "or access it via context.set_status instead.", + DeprecationWarning, + stacklevel=2, + ) return SetStatus(self.client, self.channel_id, self.thread_ts) @property @@ -205,6 +212,13 @@

      Instance variables

      @property
       def set_status(self) -> SetStatus:
      +    warnings.warn(
      +        "AssistantUtilities.set_status is deprecated. "
      +        "Use the set_status argument directly in your listener function "
      +        "or access it via context.set_status instead.",
      +        DeprecationWarning,
      +        stacklevel=2,
      +    )
           return SetStatus(self.client, self.channel_id, self.thread_ts)
      diff --git a/docs/reference/context/assistant/async_assistant_utilities.html b/docs/reference/context/assistant/async_assistant_utilities.html index fc3cbbe8b..fc77b80cb 100644 --- a/docs/reference/context/assistant/async_assistant_utilities.html +++ b/docs/reference/context/assistant/async_assistant_utilities.html @@ -91,6 +91,13 @@

      Classes

      @property def set_status(self) -> AsyncSetStatus: + warnings.warn( + "AsyncAssistantUtilities.set_status is deprecated. " + "Use the set_status argument directly in your listener function " + "or access it via context.set_status instead.", + DeprecationWarning, + stacklevel=2, + ) return AsyncSetStatus(self.client, self.channel_id, self.thread_ts) @property @@ -199,6 +206,13 @@

      Instance variables

      @property
       def set_status(self) -> AsyncSetStatus:
      +    warnings.warn(
      +        "AsyncAssistantUtilities.set_status is deprecated. "
      +        "Use the set_status argument directly in your listener function "
      +        "or access it via context.set_status instead.",
      +        DeprecationWarning,
      +        stacklevel=2,
      +    )
           return AsyncSetStatus(self.client, self.channel_id, self.thread_ts)
      diff --git a/docs/reference/context/assistant/thread_context_store/file/index.html b/docs/reference/context/assistant/thread_context_store/file/index.html index 4a5d944e1..cbb4e4db6 100644 --- a/docs/reference/context/assistant/thread_context_store/file/index.html +++ b/docs/reference/context/assistant/thread_context_store/file/index.html @@ -48,7 +48,7 @@

      Classes

      class FileAssistantThreadContextStore -(base_dir: str = '/Users/wbergamin/.bolt-app-assistant-thread-contexts') +(base_dir: str = '/Users/eden.zimbelman/.bolt-app-assistant-thread-contexts')
      diff --git a/docs/reference/context/async_context.html b/docs/reference/context/async_context.html index 9ce4ebd9e..8fc6d36bf 100644 --- a/docs/reference/context/async_context.html +++ b/docs/reference/context/async_context.html @@ -80,7 +80,7 @@

      Classes

      # The return type is intentionally string to avoid circular imports @property - def listener_runner(self) -> "AsyncioListenerRunner": # type: ignore[name-defined] + def listener_runner(self) -> "AsyncioListenerRunner": """The properly configured listener_runner that is available for middleware/listeners.""" return self["listener_runner"] @@ -149,7 +149,7 @@

      Classes

      Callable `say()` function """ if "say" not in self: - self["say"] = AsyncSay(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = AsyncSay(client=self.client, channel=self.channel_id) return self["say"] @property @@ -242,6 +242,10 @@

      Classes

      def get_thread_context(self) -> Optional[AsyncGetThreadContext]: return self.get("get_thread_context") + @property + def say_stream(self) -> Optional[AsyncSayStream]: + return self.get("say_stream") + @property def save_thread_context(self) -> Optional[AsyncSaveThreadContext]: return self.get("save_thread_context")
      @@ -457,7 +461,7 @@

      Returns

      Expand source code
      @property
      -def listener_runner(self) -> "AsyncioListenerRunner":  # type: ignore[name-defined]
      +def listener_runner(self) -> "AsyncioListenerRunner":
           """The properly configured listener_runner that is available for middleware/listeners."""
           return self["listener_runner"]
      @@ -547,7 +551,7 @@

      Returns

      Callable `say()` function """ if "say" not in self: - self["say"] = AsyncSay(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = AsyncSay(client=self.client, channel=self.channel_id) return self["say"]

      say() function for this request.

      @@ -565,6 +569,18 @@

      Returns

      Returns

      Callable say() function

      +
      prop say_streamAsyncSayStream | None
      +
      +
      + +Expand source code + +
      @property
      +def say_stream(self) -> Optional[AsyncSayStream]:
      +    return self.get("say_stream")
      +
      +
      +
      prop set_statusAsyncSetStatus | None
      @@ -694,6 +710,7 @@

      respond
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/context/base_context.html b/docs/reference/context/base_context.html index 4a177f8dc..afe571163 100644 --- a/docs/reference/context/base_context.html +++ b/docs/reference/context/base_context.html @@ -89,6 +89,7 @@

      Classes

      "set_status", "set_title", "set_suggested_prompts", + "say_stream", ] # Note that these items are not copyable, so when you add new items to this list, # you must modify ThreadListenerRunner/AsyncioListenerRunner's _build_lazy_request method to pass the values. diff --git a/docs/reference/context/context.html b/docs/reference/context/context.html index 615432502..a7b531c20 100644 --- a/docs/reference/context/context.html +++ b/docs/reference/context/context.html @@ -81,7 +81,7 @@

      Classes

      # The return type is intentionally string to avoid circular imports @property - def listener_runner(self) -> "ThreadListenerRunner": # type: ignore[name-defined] + def listener_runner(self) -> "ThreadListenerRunner": """The properly configured listener_runner that is available for middleware/listeners.""" return self["listener_runner"] @@ -150,7 +150,7 @@

      Classes

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"] @property @@ -243,6 +243,10 @@

      Classes

      def get_thread_context(self) -> Optional[GetThreadContext]: return self.get("get_thread_context") + @property + def say_stream(self) -> Optional[SayStream]: + return self.get("say_stream") + @property def save_thread_context(self) -> Optional[SaveThreadContext]: return self.get("save_thread_context") @@ -458,7 +462,7 @@

      Returns

      Expand source code
      @property
      -def listener_runner(self) -> "ThreadListenerRunner":  # type: ignore[name-defined]
      +def listener_runner(self) -> "ThreadListenerRunner":
           """The properly configured listener_runner that is available for middleware/listeners."""
           return self["listener_runner"]
      @@ -548,7 +552,7 @@

      Returns

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"]

      say() function for this request.

      @@ -566,6 +570,18 @@

      Returns

      Returns

      Callable say() function

      +
      prop say_streamSayStream | None
      +
      +
      + +Expand source code + +
      @property
      +def say_stream(self) -> Optional[SayStream]:
      +    return self.get("say_stream")
      +
      +
      +
      prop set_statusSetStatus | None
      @@ -696,6 +712,7 @@

      respond
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/context/get_thread_context/async_get_thread_context.html b/docs/reference/context/get_thread_context/async_get_thread_context.html index 1c3fc4d6c..967581b50 100644 --- a/docs/reference/context/get_thread_context/async_get_thread_context.html +++ b/docs/reference/context/get_thread_context/async_get_thread_context.html @@ -82,14 +82,10 @@

      Classes

      if self.thread_context_loaded is True: return self._thread_context - if self.payload.get("assistant_thread") is not None: + thread = self.payload.get("assistant_thread") + if isinstance(thread, dict) and thread.get("context", {}).get("channel_id") is not None: # assistant_thread_started - thread = self.payload["assistant_thread"] - self._thread_context = ( - AssistantThreadContext(thread["context"]) - if thread.get("context", {}).get("channel_id") is not None - else None - ) + self._thread_context = AssistantThreadContext(thread["context"]) # for this event, the context will never be changed self.thread_context_loaded = True elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None: diff --git a/docs/reference/context/get_thread_context/get_thread_context.html b/docs/reference/context/get_thread_context/get_thread_context.html index 4ac274368..cf2e17a86 100644 --- a/docs/reference/context/get_thread_context/get_thread_context.html +++ b/docs/reference/context/get_thread_context/get_thread_context.html @@ -82,14 +82,10 @@

      Classes

      if self.thread_context_loaded is True: return self._thread_context - if self.payload.get("assistant_thread") is not None: + thread = self.payload.get("assistant_thread") + if isinstance(thread, dict) and thread.get("context", {}).get("channel_id") is not None: # assistant_thread_started - thread = self.payload["assistant_thread"] - self._thread_context = ( - AssistantThreadContext(thread["context"]) - if thread.get("context", {}).get("channel_id") is not None - else None - ) + self._thread_context = AssistantThreadContext(thread["context"]) # for this event, the context will never be changed self.thread_context_loaded = True elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None: diff --git a/docs/reference/context/get_thread_context/index.html b/docs/reference/context/get_thread_context/index.html index 13dcd1388..5f9e38e71 100644 --- a/docs/reference/context/get_thread_context/index.html +++ b/docs/reference/context/get_thread_context/index.html @@ -93,14 +93,10 @@

      Classes

      if self.thread_context_loaded is True: return self._thread_context - if self.payload.get("assistant_thread") is not None: + thread = self.payload.get("assistant_thread") + if isinstance(thread, dict) and thread.get("context", {}).get("channel_id") is not None: # assistant_thread_started - thread = self.payload["assistant_thread"] - self._thread_context = ( - AssistantThreadContext(thread["context"]) - if thread.get("context", {}).get("channel_id") is not None - else None - ) + self._thread_context = AssistantThreadContext(thread["context"]) # for this event, the context will never be changed self.thread_context_loaded = True elif self.payload.get("channel") is not None and self.payload.get("thread_ts") is not None: diff --git a/docs/reference/context/index.html b/docs/reference/context/index.html index c761aa47e..ebdfe8aa8 100644 --- a/docs/reference/context/index.html +++ b/docs/reference/context/index.html @@ -89,6 +89,10 @@

      Sub-modules

      +
      slack_bolt.context.say_stream
      +
      +
      +
      slack_bolt.context.set_status
      @@ -145,7 +149,7 @@

      Classes

      # The return type is intentionally string to avoid circular imports @property - def listener_runner(self) -> "ThreadListenerRunner": # type: ignore[name-defined] + def listener_runner(self) -> "ThreadListenerRunner": """The properly configured listener_runner that is available for middleware/listeners.""" return self["listener_runner"] @@ -214,7 +218,7 @@

      Classes

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"] @property @@ -307,6 +311,10 @@

      Classes

      def get_thread_context(self) -> Optional[GetThreadContext]: return self.get("get_thread_context") + @property + def say_stream(self) -> Optional[SayStream]: + return self.get("say_stream") + @property def save_thread_context(self) -> Optional[SaveThreadContext]: return self.get("save_thread_context") @@ -522,7 +530,7 @@

      Returns

      Expand source code
      @property
      -def listener_runner(self) -> "ThreadListenerRunner":  # type: ignore[name-defined]
      +def listener_runner(self) -> "ThreadListenerRunner":
           """The properly configured listener_runner that is available for middleware/listeners."""
           return self["listener_runner"]
      @@ -612,7 +620,7 @@

      Returns

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"]

      slack_bolt.context.say function for this request.

      @@ -630,6 +638,18 @@

      Returns

      Returns

      Callable slack_bolt.context.say function

      +
      prop say_streamSayStream | None
      +
      +
      + +Expand source code + +
      @property
      +def say_stream(self) -> Optional[SayStream]:
      +    return self.get("say_stream")
      +
      +
      +
      prop set_statusSetStatus | None
      @@ -759,6 +779,7 @@

      Inherited members

    • slack_bolt.context.respond
    • slack_bolt.context.save_thread_context
    • slack_bolt.context.say
    • +
    • slack_bolt.context.say_stream
    • slack_bolt.context.set_status
    • slack_bolt.context.set_suggested_prompts
    • slack_bolt.context.set_title
    • @@ -778,6 +799,7 @@

      respond
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/context/say_stream/async_say_stream.html b/docs/reference/context/say_stream/async_say_stream.html new file mode 100644 index 000000000..4010b284d --- /dev/null +++ b/docs/reference/context/say_stream/async_say_stream.html @@ -0,0 +1,174 @@ + + + + + + +slack_bolt.context.say_stream.async_say_stream API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.context.say_stream.async_say_stream

      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class AsyncSayStream +(*,
      client: slack_sdk.web.async_client.AsyncWebClient,
      channel: str | None = None,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      thread_ts: str | None = None)
      +
      +
      +
      + +Expand source code + +
      class AsyncSayStream:
      +    client: AsyncWebClient
      +    channel: Optional[str]
      +    recipient_team_id: Optional[str]
      +    recipient_user_id: Optional[str]
      +    thread_ts: Optional[str]
      +
      +    def __init__(
      +        self,
      +        *,
      +        client: AsyncWebClient,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +    ):
      +        self.client = client
      +        self.channel = channel
      +        self.recipient_team_id = recipient_team_id
      +        self.recipient_user_id = recipient_user_id
      +        self.thread_ts = thread_ts
      +
      +    async def __call__(
      +        self,
      +        *,
      +        buffer_size: Optional[int] = None,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +        **kwargs,
      +    ) -> AsyncChatStream:
      +        """Starts a new chat stream with context."""
      +        channel = channel or self.channel
      +        thread_ts = thread_ts or self.thread_ts
      +        if channel is None:
      +            raise ValueError("say_stream without channel here is unsupported")
      +        if thread_ts is None:
      +            raise ValueError("say_stream without thread_ts here is unsupported")
      +
      +        if buffer_size is not None:
      +            return await self.client.chat_stream(
      +                buffer_size=buffer_size,
      +                channel=channel,
      +                recipient_team_id=recipient_team_id or self.recipient_team_id,
      +                recipient_user_id=recipient_user_id or self.recipient_user_id,
      +                thread_ts=thread_ts,
      +                **kwargs,
      +            )
      +        return await self.client.chat_stream(
      +            channel=channel,
      +            recipient_team_id=recipient_team_id or self.recipient_team_id,
      +            recipient_user_id=recipient_user_id or self.recipient_user_id,
      +            thread_ts=thread_ts,
      +            **kwargs,
      +        )
      +
      +
      +

      Class variables

      +
      +
      var channel : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var client : slack_sdk.web.async_client.AsyncWebClient
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_team_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_user_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var thread_ts : str | None
      +
      +

      The type of the None singleton.

      +
      +
      +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/context/say_stream/index.html b/docs/reference/context/say_stream/index.html new file mode 100644 index 000000000..645942c72 --- /dev/null +++ b/docs/reference/context/say_stream/index.html @@ -0,0 +1,191 @@ + + + + + + +slack_bolt.context.say_stream API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.context.say_stream

      +
      +
      +
      +
      +

      Sub-modules

      +
      +
      slack_bolt.context.say_stream.async_say_stream
      +
      +
      +
      +
      slack_bolt.context.say_stream.say_stream
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class SayStream +(*,
      client: slack_sdk.web.client.WebClient,
      channel: str | None = None,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      thread_ts: str | None = None)
      +
      +
      +
      + +Expand source code + +
      class SayStream:
      +    client: WebClient
      +    channel: Optional[str]
      +    recipient_team_id: Optional[str]
      +    recipient_user_id: Optional[str]
      +    thread_ts: Optional[str]
      +
      +    def __init__(
      +        self,
      +        *,
      +        client: WebClient,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +    ):
      +        self.client = client
      +        self.channel = channel
      +        self.recipient_team_id = recipient_team_id
      +        self.recipient_user_id = recipient_user_id
      +        self.thread_ts = thread_ts
      +
      +    def __call__(
      +        self,
      +        *,
      +        buffer_size: Optional[int] = None,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +        **kwargs,
      +    ) -> ChatStream:
      +        """Starts a new chat stream with context."""
      +        channel = channel or self.channel
      +        thread_ts = thread_ts or self.thread_ts
      +        if channel is None:
      +            raise ValueError("say_stream without channel here is unsupported")
      +        if thread_ts is None:
      +            raise ValueError("say_stream without thread_ts here is unsupported")
      +
      +        if buffer_size is not None:
      +            return self.client.chat_stream(
      +                buffer_size=buffer_size,
      +                channel=channel,
      +                recipient_team_id=recipient_team_id or self.recipient_team_id,
      +                recipient_user_id=recipient_user_id or self.recipient_user_id,
      +                thread_ts=thread_ts,
      +                **kwargs,
      +            )
      +        return self.client.chat_stream(
      +            channel=channel,
      +            recipient_team_id=recipient_team_id or self.recipient_team_id,
      +            recipient_user_id=recipient_user_id or self.recipient_user_id,
      +            thread_ts=thread_ts,
      +            **kwargs,
      +        )
      +
      +
      +

      Class variables

      +
      +
      var channel : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var client : slack_sdk.web.client.WebClient
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_team_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_user_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var thread_ts : str | None
      +
      +

      The type of the None singleton.

      +
      +
      +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/context/say_stream/say_stream.html b/docs/reference/context/say_stream/say_stream.html new file mode 100644 index 000000000..784a58bbe --- /dev/null +++ b/docs/reference/context/say_stream/say_stream.html @@ -0,0 +1,174 @@ + + + + + + +slack_bolt.context.say_stream.say_stream API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.context.say_stream.say_stream

      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class SayStream +(*,
      client: slack_sdk.web.client.WebClient,
      channel: str | None = None,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      thread_ts: str | None = None)
      +
      +
      +
      + +Expand source code + +
      class SayStream:
      +    client: WebClient
      +    channel: Optional[str]
      +    recipient_team_id: Optional[str]
      +    recipient_user_id: Optional[str]
      +    thread_ts: Optional[str]
      +
      +    def __init__(
      +        self,
      +        *,
      +        client: WebClient,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +    ):
      +        self.client = client
      +        self.channel = channel
      +        self.recipient_team_id = recipient_team_id
      +        self.recipient_user_id = recipient_user_id
      +        self.thread_ts = thread_ts
      +
      +    def __call__(
      +        self,
      +        *,
      +        buffer_size: Optional[int] = None,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +        **kwargs,
      +    ) -> ChatStream:
      +        """Starts a new chat stream with context."""
      +        channel = channel or self.channel
      +        thread_ts = thread_ts or self.thread_ts
      +        if channel is None:
      +            raise ValueError("say_stream without channel here is unsupported")
      +        if thread_ts is None:
      +            raise ValueError("say_stream without thread_ts here is unsupported")
      +
      +        if buffer_size is not None:
      +            return self.client.chat_stream(
      +                buffer_size=buffer_size,
      +                channel=channel,
      +                recipient_team_id=recipient_team_id or self.recipient_team_id,
      +                recipient_user_id=recipient_user_id or self.recipient_user_id,
      +                thread_ts=thread_ts,
      +                **kwargs,
      +            )
      +        return self.client.chat_stream(
      +            channel=channel,
      +            recipient_team_id=recipient_team_id or self.recipient_team_id,
      +            recipient_user_id=recipient_user_id or self.recipient_user_id,
      +            thread_ts=thread_ts,
      +            **kwargs,
      +        )
      +
      +
      +

      Class variables

      +
      +
      var channel : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var client : slack_sdk.web.client.WebClient
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_team_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_user_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var thread_ts : str | None
      +
      +

      The type of the None singleton.

      +
      +
      +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/error/index.html b/docs/reference/error/index.html index 9a9998e63..f57d690e9 100644 --- a/docs/reference/error/index.html +++ b/docs/reference/error/index.html @@ -72,7 +72,7 @@

      Subclasses

      class BoltUnhandledRequestError -(*,
      request: BoltRequest | AsyncBoltRequest,
      current_response: BoltResponse | None,
      last_global_middleware_name: str | None = None)
      +(*,
      request: ForwardRef('BoltRequest') | ForwardRef('AsyncBoltRequest'),
      current_response: ForwardRef('BoltResponse') | None,
      last_global_middleware_name: str | None = None)
      diff --git a/docs/reference/index.html b/docs/reference/index.html index 1c02a8aeb..b2d19719d 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -188,7 +188,7 @@

      Class variables

      class App -(*,
      logger: logging.Logger | None = None,
      name: str | None = None,
      process_before_response: bool = False,
      raise_error_for_unhandled_request: bool = False,
      signing_secret: str | None = None,
      token: str | None = None,
      token_verification_enabled: bool = True,
      client: slack_sdk.web.client.WebClient | None = None,
      before_authorize: Middleware | Callable[..., Any] | None = None,
      authorize: Callable[..., AuthorizeResult] | None = None,
      user_facing_authorize_error_message: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
      installation_store_bot_only: bool | None = None,
      request_verification_enabled: bool = True,
      ignoring_self_events_enabled: bool = True,
      ignoring_self_assistant_message_events_enabled: bool = True,
      ssl_check_enabled: bool = True,
      url_verification_enabled: bool = True,
      attaching_function_token_enabled: bool = True,
      oauth_settings: OAuthSettings | None = None,
      oauth_flow: OAuthFlow | None = None,
      verification_token: str | None = None,
      listener_executor: concurrent.futures._base.Executor | None = None,
      assistant_thread_context_store: AssistantThreadContextStore | None = None)
      +(*,
      logger: logging.Logger | None = None,
      name: str | None = None,
      process_before_response: bool = False,
      raise_error_for_unhandled_request: bool = False,
      signing_secret: str | None = None,
      token: str | None = None,
      token_verification_enabled: bool = True,
      client: slack_sdk.web.client.WebClient | None = None,
      before_authorize: Middleware | Callable[..., Any] | None = None,
      authorize: Callable[..., AuthorizeResult] | None = None,
      user_facing_authorize_error_message: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
      installation_store_bot_only: bool | None = None,
      request_verification_enabled: bool = True,
      ignoring_self_events_enabled: bool = True,
      ignoring_self_assistant_message_events_enabled: bool = True,
      ssl_check_enabled: bool = True,
      url_verification_enabled: bool = True,
      attaching_function_token_enabled: bool = True,
      oauth_settings: OAuthSettings | None = None,
      oauth_flow: OAuthFlow | None = None,
      verification_token: str | None = None,
      listener_executor: concurrent.futures._base.Executor | None = None,
      assistant_thread_context_store: AssistantThreadContextStore | None = None,
      attaching_conversation_kwargs_enabled: bool = True)
      @@ -235,6 +235,7 @@

      Class variables

      listener_executor: Optional[Executor] = None, # for AI Agents & Assistants assistant_thread_context_store: Optional[AssistantThreadContextStore] = None, + attaching_conversation_kwargs_enabled: bool = True, ): """Bolt App that provides functionalities to register middleware/listeners. @@ -455,6 +456,7 @@

      Class variables

      listener_executor = ThreadPoolExecutor(max_workers=5) self._assistant_thread_context_store = assistant_thread_context_store + self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled self._process_before_response = process_before_response self._listener_runner = ThreadListenerRunner( @@ -939,10 +941,13 @@

      Class variables

      middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -1000,6 +1005,8 @@

      Class variables

      primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -1496,20 +1503,6 @@

      Class variables

      # It is intended for apps that start lazy listeners from their custom global middleware. req.context["listener_runner"] = self.listener_runner - # For AI Agents & Assistants - if is_assistant_event(req.body): - assistant = AssistantUtilities( - payload=to_event(req.body), # type:ignore[arg-type] - context=req.context, - thread_context_store=self._assistant_thread_context_store, - ) - req.context["say"] = assistant.say - req.context["set_status"] = assistant.set_status - req.context["set_title"] = assistant.set_title - req.context["set_suggested_prompts"] = assistant.set_suggested_prompts - req.context["get_thread_context"] = assistant.get_thread_context - req.context["save_thread_context"] = assistant.save_thread_context - @staticmethod def _to_listener_functions( kwargs: dict, @@ -1555,7 +1548,7 @@

      Class variables

      CustomListener( app_name=self.name, ack_function=functions.pop(0), - lazy_functions=functions, # type:ignore[arg-type] + lazy_functions=functions, # type: ignore[arg-type] matchers=listener_matchers, middleware=listener_middleware, auto_acknowledgement=auto_acknowledgement, @@ -2343,10 +2336,13 @@

      Args

      middleware: A list of lister middleware functions. Only when all the middleware call `next()` method, the listener function can be invoked. """ + middleware = list(middleware) if middleware else [] def __call__(*args, **kwargs): functions = self._to_listener_functions(kwargs) if kwargs else list(args) primary_matcher = builtin_matchers.event(event, base_logger=self._base_logger) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) return __call__ @@ -2550,6 +2546,8 @@

      Args

      primary_matcher = builtin_matchers.message_event( keyword=keyword, constraints=constraints, base_logger=self._base_logger ) + if self._attaching_conversation_kwargs_enabled: + middleware.insert(0, AttachingConversationKwargs(self._assistant_thread_context_store)) middleware.insert(0, MessageListenerMatches(keyword)) return self._register_listener(list(functions), primary_matcher, matchers, middleware, True) @@ -3179,7 +3177,7 @@

      Args

      class Args -(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      next: Callable[[], None],
      **kwargs)
      +(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      say_stream: SayStream | None = None,
      next: Callable[[], None],
      **kwargs)
      @@ -3270,6 +3268,8 @@

      Args

      """`get_thread_context()` utility function for AI Agents & Assistants""" save_thread_context: Optional[SaveThreadContext] """`save_thread_context()` utility function for AI Agents & Assistants""" + say_stream: Optional[SayStream] + """`say_stream()` utility function for conversations, AI Agents & Assistants""" # middleware next: Callable[[], None] """`next()` utility function, which tells the middleware chain that it can continue with the next one""" @@ -3303,6 +3303,7 @@

      Args

      set_suggested_prompts: Optional[SetSuggestedPrompts] = None, get_thread_context: Optional[GetThreadContext] = None, save_thread_context: Optional[SaveThreadContext] = None, + say_stream: Optional[SayStream] = None, # As this method is not supposed to be invoked by bolt-python users, # the naming conflict with the built-in one affects # only the internals of this method @@ -3336,6 +3337,7 @@

      Args

      self.set_suggested_prompts = set_suggested_prompts self.get_thread_context = get_thread_context self.save_thread_context = save_thread_context + self.say_stream = say_stream self.next: Callable[[], None] = next self.next_: Callable[[], None] = next @@ -3459,6 +3461,10 @@

      Class variables

      say() utility function, which calls chat.postMessage API with the associated channel ID

      +
      var say_streamSayStream | None
      +
      +

      say_stream() utility function for conversations, AI Agents & Assistants

      +
      var set_statusSetStatus | None

      set_status() utility function for AI Agents & Assistants

      @@ -3531,7 +3537,7 @@

      Class variables

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3570,7 +3576,7 @@

      Class variables

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3609,7 +3615,7 @@

      Class variables

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3648,7 +3654,7 @@

      Class variables

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3678,13 +3684,13 @@

      Class variables

      ): return [CustomListenerMatcher(app_name=self.app_name, func=primary_matcher)] + ( custom_matchers or [] - ) # type:ignore[operator] + ) # type: ignore[operator] @staticmethod def default_thread_context_changed(save_thread_context: SaveThreadContext, payload: dict): save_thread_context(payload["assistant_thread"]["context"]) - def process( # type:ignore[return] + def process( # type: ignore[return] self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse] ) -> Optional[BoltResponse]: if self._thread_context_changed_listeners is None: @@ -3700,6 +3706,15 @@

      Class variables

      if listeners is not None: for listener in listeners: if listener.matches(req=req, resp=resp): + middleware_resp, next_was_not_called = listener.run_middleware(req=req, resp=resp) + if next_was_not_called: + if middleware_resp is not None: + return middleware_resp + # The listener middleware didn't call next(). + # Skip this listener and try the next one. + continue + if middleware_resp is not None: + resp = middleware_resp return listener_runner.run( request=req, response=resp, @@ -3719,13 +3734,14 @@

      Class variables

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -3734,7 +3750,7 @@

      Class variables

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -3813,7 +3829,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3853,13 +3869,14 @@

      Methods

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -3868,7 +3885,7 @@

      Methods

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -3914,7 +3931,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -3963,7 +3980,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -4012,7 +4029,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -4185,7 +4202,7 @@

      Methods

      # The return type is intentionally string to avoid circular imports @property - def listener_runner(self) -> "ThreadListenerRunner": # type: ignore[name-defined] + def listener_runner(self) -> "ThreadListenerRunner": """The properly configured listener_runner that is available for middleware/listeners.""" return self["listener_runner"] @@ -4254,7 +4271,7 @@

      Methods

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"] @property @@ -4347,6 +4364,10 @@

      Methods

      def get_thread_context(self) -> Optional[GetThreadContext]: return self.get("get_thread_context") + @property + def say_stream(self) -> Optional[SayStream]: + return self.get("say_stream") + @property def save_thread_context(self) -> Optional[SaveThreadContext]: return self.get("save_thread_context") @@ -4562,7 +4583,7 @@

      Returns

      Expand source code
      @property
      -def listener_runner(self) -> "ThreadListenerRunner":  # type: ignore[name-defined]
      +def listener_runner(self) -> "ThreadListenerRunner":
           """The properly configured listener_runner that is available for middleware/listeners."""
           return self["listener_runner"]
      @@ -4652,7 +4673,7 @@

      Returns

      Callable `say()` function """ if "say" not in self: - self["say"] = Say(client=self.client, channel=self.channel_id, thread_ts=self.thread_ts) + self["say"] = Say(client=self.client, channel=self.channel_id) return self["say"]

      say() function for this request.

      @@ -4670,6 +4691,18 @@

      Returns

      Returns

      Callable say() function

      +
      prop say_streamSayStream | None
      +
      +
      + +Expand source code + +
      @property
      +def say_stream(self) -> Optional[SayStream]:
      +    return self.get("say_stream")
      +
      +
      +
      prop set_statusSetStatus | None
      @@ -5304,7 +5337,7 @@

      Returns

      class FileAssistantThreadContextStore -(base_dir: str = '/Users/wbergamin/.bolt-app-assistant-thread-contexts') +(base_dir: str = '/Users/eden.zimbelman/.bolt-app-assistant-thread-contexts')
      @@ -5843,6 +5876,97 @@

      Class variables

      +
      +class SayStream +(*,
      client: slack_sdk.web.client.WebClient,
      channel: str | None = None,
      recipient_team_id: str | None = None,
      recipient_user_id: str | None = None,
      thread_ts: str | None = None)
      +
      +
      +
      + +Expand source code + +
      class SayStream:
      +    client: WebClient
      +    channel: Optional[str]
      +    recipient_team_id: Optional[str]
      +    recipient_user_id: Optional[str]
      +    thread_ts: Optional[str]
      +
      +    def __init__(
      +        self,
      +        *,
      +        client: WebClient,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +    ):
      +        self.client = client
      +        self.channel = channel
      +        self.recipient_team_id = recipient_team_id
      +        self.recipient_user_id = recipient_user_id
      +        self.thread_ts = thread_ts
      +
      +    def __call__(
      +        self,
      +        *,
      +        buffer_size: Optional[int] = None,
      +        channel: Optional[str] = None,
      +        recipient_team_id: Optional[str] = None,
      +        recipient_user_id: Optional[str] = None,
      +        thread_ts: Optional[str] = None,
      +        **kwargs,
      +    ) -> ChatStream:
      +        """Starts a new chat stream with context."""
      +        channel = channel or self.channel
      +        thread_ts = thread_ts or self.thread_ts
      +        if channel is None:
      +            raise ValueError("say_stream without channel here is unsupported")
      +        if thread_ts is None:
      +            raise ValueError("say_stream without thread_ts here is unsupported")
      +
      +        if buffer_size is not None:
      +            return self.client.chat_stream(
      +                buffer_size=buffer_size,
      +                channel=channel,
      +                recipient_team_id=recipient_team_id or self.recipient_team_id,
      +                recipient_user_id=recipient_user_id or self.recipient_user_id,
      +                thread_ts=thread_ts,
      +                **kwargs,
      +            )
      +        return self.client.chat_stream(
      +            channel=channel,
      +            recipient_team_id=recipient_team_id or self.recipient_team_id,
      +            recipient_user_id=recipient_user_id or self.recipient_user_id,
      +            thread_ts=thread_ts,
      +            **kwargs,
      +        )
      +
      +
      +

      Class variables

      +
      +
      var channel : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var client : slack_sdk.web.client.WebClient
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_team_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var recipient_user_id : str | None
      +
      +

      The type of the None singleton.

      +
      +
      var thread_ts : str | None
      +
      +

      The type of the None singleton.

      +
      +
      +
      class SetStatus (client: slack_sdk.web.client.WebClient, channel_id: str, thread_ts: str) @@ -6110,6 +6234,7 @@

      Args

      response
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • @@ -6157,6 +6282,7 @@

      BoltC
    • respond
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • @@ -6262,6 +6388,16 @@

      Say

  • +

    SayStream

    + +
  • +
  • SetStatus

    • channel_id
    • diff --git a/docs/reference/kwargs_injection/args.html b/docs/reference/kwargs_injection/args.html index 4d03687d1..bbba71eb8 100644 --- a/docs/reference/kwargs_injection/args.html +++ b/docs/reference/kwargs_injection/args.html @@ -48,7 +48,7 @@

      Classes

      class Args -(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      next: Callable[[], None],
      **kwargs)
      +(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      say_stream: SayStream | None = None,
      next: Callable[[], None],
      **kwargs)
      @@ -139,6 +139,8 @@

      Classes

      """`get_thread_context()` utility function for AI Agents & Assistants""" save_thread_context: Optional[SaveThreadContext] """`save_thread_context()` utility function for AI Agents & Assistants""" + say_stream: Optional[SayStream] + """`say_stream()` utility function for conversations, AI Agents & Assistants""" # middleware next: Callable[[], None] """`next()` utility function, which tells the middleware chain that it can continue with the next one""" @@ -172,6 +174,7 @@

      Classes

      set_suggested_prompts: Optional[SetSuggestedPrompts] = None, get_thread_context: Optional[GetThreadContext] = None, save_thread_context: Optional[SaveThreadContext] = None, + say_stream: Optional[SayStream] = None, # As this method is not supposed to be invoked by bolt-python users, # the naming conflict with the built-in one affects # only the internals of this method @@ -205,6 +208,7 @@

      Classes

      self.set_suggested_prompts = set_suggested_prompts self.get_thread_context = get_thread_context self.save_thread_context = save_thread_context + self.say_stream = say_stream self.next: Callable[[], None] = next self.next_: Callable[[], None] = next
      @@ -328,6 +332,10 @@

      Class variables

      say() utility function, which calls chat.postMessage API with the associated channel ID

      +
      var say_streamSayStream | None
      +
      +

      say_stream() utility function for conversations, AI Agents & Assistants

      +
      var set_statusSetStatus | None

      set_status() utility function for AI Agents & Assistants

      @@ -391,6 +399,7 @@

      response
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/kwargs_injection/async_args.html b/docs/reference/kwargs_injection/async_args.html index 959f35a43..5b0e7b70e 100644 --- a/docs/reference/kwargs_injection/async_args.html +++ b/docs/reference/kwargs_injection/async_args.html @@ -48,7 +48,7 @@

      Classes

      class AsyncArgs -(*,
      logger: logging.Logger,
      client: slack_sdk.web.async_client.AsyncWebClient,
      req: AsyncBoltRequest,
      resp: BoltResponse,
      context: AsyncBoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: AsyncAck,
      say: AsyncSay,
      respond: AsyncRespond,
      complete: AsyncComplete,
      fail: AsyncFail,
      set_status: AsyncSetStatus | None = None,
      set_title: AsyncSetTitle | None = None,
      set_suggested_prompts: AsyncSetSuggestedPrompts | None = None,
      get_thread_context: AsyncGetThreadContext | None = None,
      save_thread_context: AsyncSaveThreadContext | None = None,
      next: Callable[[], Awaitable[None]],
      **kwargs)
      +(*,
      logger: logging.Logger,
      client: slack_sdk.web.async_client.AsyncWebClient,
      req: AsyncBoltRequest,
      resp: BoltResponse,
      context: AsyncBoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: AsyncAck,
      say: AsyncSay,
      respond: AsyncRespond,
      complete: AsyncComplete,
      fail: AsyncFail,
      set_status: AsyncSetStatus | None = None,
      set_title: AsyncSetTitle | None = None,
      set_suggested_prompts: AsyncSetSuggestedPrompts | None = None,
      get_thread_context: AsyncGetThreadContext | None = None,
      save_thread_context: AsyncSaveThreadContext | None = None,
      say_stream: AsyncSayStream | None = None,
      next: Callable[[], Awaitable[None]],
      **kwargs)
      @@ -139,6 +139,8 @@

      Classes

      """`get_thread_context()` utility function for AI Agents & Assistants""" save_thread_context: Optional[AsyncSaveThreadContext] """`save_thread_context()` utility function for AI Agents & Assistants""" + say_stream: Optional[AsyncSayStream] + """`say_stream()` utility function for AI Agents & Assistants""" # middleware next: Callable[[], Awaitable[None]] """`next()` utility function, which tells the middleware chain that it can continue with the next one""" @@ -172,6 +174,7 @@

      Classes

      set_suggested_prompts: Optional[AsyncSetSuggestedPrompts] = None, get_thread_context: Optional[AsyncGetThreadContext] = None, save_thread_context: Optional[AsyncSaveThreadContext] = None, + say_stream: Optional[AsyncSayStream] = None, next: Callable[[], Awaitable[None]], **kwargs, # noqa ): @@ -202,6 +205,7 @@

      Classes

      self.set_suggested_prompts = set_suggested_prompts self.get_thread_context = get_thread_context self.save_thread_context = save_thread_context + self.say_stream = say_stream self.next: Callable[[], Awaitable[None]] = next self.next_: Callable[[], Awaitable[None]] = next @@ -325,6 +329,10 @@

      Class variables

      say() utility function, which calls chat.postMessage API with the associated channel ID

      +
      var say_streamAsyncSayStream | None
      +
      +

      say_stream() utility function for AI Agents & Assistants

      +
      var set_statusAsyncSetStatus | None

      set_status() utility function for AI Agents & Assistants

      @@ -388,6 +396,7 @@

      response
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/kwargs_injection/async_utils.html b/docs/reference/kwargs_injection/async_utils.html index 80952518d..7af3a7679 100644 --- a/docs/reference/kwargs_injection/async_utils.html +++ b/docs/reference/kwargs_injection/async_utils.html @@ -63,7 +63,7 @@

      Functions

      error: Optional[Exception] = None, # for error handlers next_keys_required: bool = True, # False for listeners / middleware / error handlers ) -> Dict[str, Any]: - all_available_args = { + all_available_args: Dict[str, Any] = { "logger": logger, "client": request.context.client, "req": request, @@ -92,6 +92,7 @@

      Functions

      "set_suggested_prompts": request.context.set_suggested_prompts, "get_thread_context": request.context.get_thread_context, "save_thread_context": request.context.save_thread_context, + "say_stream": request.context.say_stream, # middleware "next": next_func, "next_": next_func, # for the middleware using Python's built-in `next()` function @@ -136,7 +137,7 @@

      Functions

      for name in required_arg_names: if name == "args": if isinstance(request, AsyncBoltRequest): - kwargs[name] = AsyncArgs(**all_available_args) # type: ignore[arg-type] + kwargs[name] = AsyncArgs(**all_available_args) else: logger.warning(f"Unknown Request object type detected ({type(request)})") diff --git a/docs/reference/kwargs_injection/index.html b/docs/reference/kwargs_injection/index.html index de7ef4a0a..cb17cea5d 100644 --- a/docs/reference/kwargs_injection/index.html +++ b/docs/reference/kwargs_injection/index.html @@ -85,7 +85,7 @@

      Functions

      error: Optional[Exception] = None, # for error handlers next_keys_required: bool = True, # False for listeners / middleware / error handlers ) -> Dict[str, Any]: - all_available_args = { + all_available_args: Dict[str, Any] = { "logger": logger, "client": request.context.client, "req": request, @@ -113,6 +113,7 @@

      Functions

      "set_title": request.context.set_title, "set_suggested_prompts": request.context.set_suggested_prompts, "save_thread_context": request.context.save_thread_context, + "say_stream": request.context.say_stream, # middleware "next": next_func, "next_": next_func, # for the middleware using Python's built-in `next()` function @@ -157,7 +158,7 @@

      Functions

      for name in required_arg_names: if name == "args": if isinstance(request, BoltRequest): - kwargs[name] = Args(**all_available_args) # type: ignore[arg-type] + kwargs[name] = Args(**all_available_args) else: logger.warning(f"Unknown Request object type detected ({type(request)})") @@ -175,7 +176,7 @@

      Classes

      class Args -(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      next: Callable[[], None],
      **kwargs)
      +(*,
      logger: logging.Logger,
      client: slack_sdk.web.client.WebClient,
      req: BoltRequest,
      resp: BoltResponse,
      context: BoltContext,
      body: Dict[str, Any],
      payload: Dict[str, Any],
      options: Dict[str, Any] | None = None,
      shortcut: Dict[str, Any] | None = None,
      action: Dict[str, Any] | None = None,
      view: Dict[str, Any] | None = None,
      command: Dict[str, Any] | None = None,
      event: Dict[str, Any] | None = None,
      message: Dict[str, Any] | None = None,
      ack: Ack,
      say: Say,
      respond: Respond,
      complete: Complete,
      fail: Fail,
      set_status: SetStatus | None = None,
      set_title: SetTitle | None = None,
      set_suggested_prompts: SetSuggestedPrompts | None = None,
      get_thread_context: GetThreadContext | None = None,
      save_thread_context: SaveThreadContext | None = None,
      say_stream: SayStream | None = None,
      next: Callable[[], None],
      **kwargs)
      @@ -266,6 +267,8 @@

      Classes

      """`get_thread_context()` utility function for AI Agents & Assistants""" save_thread_context: Optional[SaveThreadContext] """`save_thread_context()` utility function for AI Agents & Assistants""" + say_stream: Optional[SayStream] + """`say_stream()` utility function for conversations, AI Agents & Assistants""" # middleware next: Callable[[], None] """`next()` utility function, which tells the middleware chain that it can continue with the next one""" @@ -299,6 +302,7 @@

      Classes

      set_suggested_prompts: Optional[SetSuggestedPrompts] = None, get_thread_context: Optional[GetThreadContext] = None, save_thread_context: Optional[SaveThreadContext] = None, + say_stream: Optional[SayStream] = None, # As this method is not supposed to be invoked by bolt-python users, # the naming conflict with the built-in one affects # only the internals of this method @@ -332,6 +336,7 @@

      Classes

      self.set_suggested_prompts = set_suggested_prompts self.get_thread_context = get_thread_context self.save_thread_context = save_thread_context + self.say_stream = say_stream self.next: Callable[[], None] = next self.next_: Callable[[], None] = next
      @@ -455,6 +460,10 @@

      Class variables

      say() utility function, which calls chat.postMessage API with the associated channel ID

      +
      var say_streamSayStream | None
      +
      +

      say_stream() utility function for conversations, AI Agents & Assistants

      +
      var set_statusSetStatus | None

      set_status() utility function for AI Agents & Assistants

      @@ -531,6 +540,7 @@

      response
    • save_thread_context
    • say
    • +
    • say_stream
    • set_status
    • set_suggested_prompts
    • set_title
    • diff --git a/docs/reference/kwargs_injection/utils.html b/docs/reference/kwargs_injection/utils.html index 2e6ecd001..0289fd410 100644 --- a/docs/reference/kwargs_injection/utils.html +++ b/docs/reference/kwargs_injection/utils.html @@ -63,7 +63,7 @@

      Functions

      error: Optional[Exception] = None, # for error handlers next_keys_required: bool = True, # False for listeners / middleware / error handlers ) -> Dict[str, Any]: - all_available_args = { + all_available_args: Dict[str, Any] = { "logger": logger, "client": request.context.client, "req": request, @@ -91,6 +91,7 @@

      Functions

      "set_title": request.context.set_title, "set_suggested_prompts": request.context.set_suggested_prompts, "save_thread_context": request.context.save_thread_context, + "say_stream": request.context.say_stream, # middleware "next": next_func, "next_": next_func, # for the middleware using Python's built-in `next()` function @@ -135,7 +136,7 @@

      Functions

      for name in required_arg_names: if name == "args": if isinstance(request, BoltRequest): - kwargs[name] = Args(**all_available_args) # type: ignore[arg-type] + kwargs[name] = Args(**all_available_args) else: logger.warning(f"Unknown Request object type detected ({type(request)})") diff --git a/docs/reference/listener/async_listener_error_handler.html b/docs/reference/listener/async_listener_error_handler.html index 1f3789c40..ebee4441a 100644 --- a/docs/reference/listener/async_listener_error_handler.html +++ b/docs/reference/listener/async_listener_error_handler.html @@ -77,9 +77,10 @@

      Classes

      ) returned_response = await self.func(**kwargs) if returned_response is not None and isinstance(returned_response, BoltResponse): - response.status = returned_response.status # type: ignore[union-attr] - response.headers = returned_response.headers # type: ignore[union-attr] - response.body = returned_response.body # type: ignore[union-attr] + assert response is not None, "response must be provided when returning a BoltResponse from an error handler" + response.status = returned_response.status + response.headers = returned_response.headers + response.body = returned_response.body

      Ancestors

      diff --git a/docs/reference/listener/listener_error_handler.html b/docs/reference/listener/listener_error_handler.html index c9f7c2ccd..e344b15cb 100644 --- a/docs/reference/listener/listener_error_handler.html +++ b/docs/reference/listener/listener_error_handler.html @@ -77,9 +77,10 @@

      Classes

      ) returned_response = self.func(**kwargs) if returned_response is not None and isinstance(returned_response, BoltResponse): - response.status = returned_response.status # type: ignore[union-attr] - response.headers = returned_response.headers # type: ignore[union-attr] - response.body = returned_response.body # type: ignore[union-attr] + assert response is not None, "response must be provided when returning a BoltResponse from an error handler" + response.status = returned_response.status + response.headers = returned_response.headers + response.body = returned_response.body

      Ancestors

      diff --git a/docs/reference/logger/messages.html b/docs/reference/logger/messages.html index e69b45fc9..1072e6479 100644 --- a/docs/reference/logger/messages.html +++ b/docs/reference/logger/messages.html @@ -409,7 +409,7 @@

      Functions

      -def warning_unhandled_by_global_middleware(name: str,
      req: BoltRequest | AsyncBoltRequest) ‑> str
      +def warning_unhandled_by_global_middleware(name: str,
      req: BoltRequest | ForwardRef('AsyncBoltRequest')) ‑> str
      @@ -427,7 +427,7 @@

      Functions

      -def warning_unhandled_request(req: BoltRequest | AsyncBoltRequest) ‑> str +def warning_unhandled_request(req: BoltRequest | ForwardRef('AsyncBoltRequest')) ‑> str
      diff --git a/docs/reference/middleware/assistant/assistant.html b/docs/reference/middleware/assistant/assistant.html index d1184c407..946416d62 100644 --- a/docs/reference/middleware/assistant/assistant.html +++ b/docs/reference/middleware/assistant/assistant.html @@ -96,7 +96,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -135,7 +135,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -174,7 +174,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -213,7 +213,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -243,13 +243,13 @@

      Classes

      ): return [CustomListenerMatcher(app_name=self.app_name, func=primary_matcher)] + ( custom_matchers or [] - ) # type:ignore[operator] + ) # type: ignore[operator] @staticmethod def default_thread_context_changed(save_thread_context: SaveThreadContext, payload: dict): save_thread_context(payload["assistant_thread"]["context"]) - def process( # type:ignore[return] + def process( # type: ignore[return] self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse] ) -> Optional[BoltResponse]: if self._thread_context_changed_listeners is None: @@ -265,6 +265,15 @@

      Classes

      if listeners is not None: for listener in listeners: if listener.matches(req=req, resp=resp): + middleware_resp, next_was_not_called = listener.run_middleware(req=req, resp=resp) + if next_was_not_called: + if middleware_resp is not None: + return middleware_resp + # The listener middleware didn't call next(). + # Skip this listener and try the next one. + continue + if middleware_resp is not None: + resp = middleware_resp return listener_runner.run( request=req, response=resp, @@ -284,13 +293,14 @@

      Classes

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -299,7 +309,7 @@

      Classes

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -378,7 +388,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -418,13 +428,14 @@

      Methods

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -433,7 +444,7 @@

      Methods

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -479,7 +490,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -528,7 +539,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -577,7 +588,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func diff --git a/docs/reference/middleware/assistant/async_assistant.html b/docs/reference/middleware/assistant/async_assistant.html index 2faf0e34b..748be2cbf 100644 --- a/docs/reference/middleware/assistant/async_assistant.html +++ b/docs/reference/middleware/assistant/async_assistant.html @@ -94,7 +94,7 @@

      Classes

      func=is_assistant_thread_started_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -103,7 +103,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -140,7 +140,7 @@

      Classes

      func=is_user_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -149,7 +149,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -186,7 +186,7 @@

      Classes

      func=is_bot_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -195,7 +195,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -232,7 +232,7 @@

      Classes

      func=is_assistant_thread_context_changed_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -241,7 +241,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -269,14 +269,14 @@

      Classes

      primary_matcher: Union[Callable[..., bool], AsyncListenerMatcher], custom_matchers: Optional[Union[Callable[..., bool], AsyncListenerMatcher]], ): - return [primary_matcher] + (custom_matchers or []) # type:ignore[operator] + return [primary_matcher] + (custom_matchers or []) # type: ignore[operator] @staticmethod async def default_thread_context_changed(save_thread_context: AsyncSaveThreadContext, payload: dict): new_context: dict = payload["assistant_thread"]["context"] await save_thread_context(new_context) - async def async_process( # type:ignore[return] + async def async_process( # type: ignore[return] self, *, req: AsyncBoltRequest, @@ -296,6 +296,15 @@

      Classes

      if listeners is not None: for listener in listeners: if listener is not None and await listener.async_matches(req=req, resp=resp): + middleware_resp, next_was_not_called = await listener.run_async_middleware(req=req, resp=resp) + if next_was_not_called: + if middleware_resp is not None: + return middleware_resp + # The listener middleware didn't call next(). + # Skip this listener and try the next one. + continue + if middleware_resp is not None: + resp = middleware_resp return await listener_runner.run( request=req, response=resp, @@ -315,13 +324,14 @@

      Classes

      middleware: Optional[List[AsyncMiddleware]] = None, base_logger: Optional[Logger] = None, ) -> AsyncListener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, AsyncListener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AsyncAttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -333,7 +343,7 @@

      Classes

      else: listener_matchers.append( build_listener_matcher( - func=matcher, # type:ignore[arg-type] + func=matcher, # type: ignore[arg-type] asyncio=True, base_logger=base_logger, ) @@ -408,7 +418,7 @@

      Methods

      func=is_bot_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -417,7 +427,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -457,13 +467,14 @@

      Methods

      middleware: Optional[List[AsyncMiddleware]] = None, base_logger: Optional[Logger] = None, ) -> AsyncListener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, AsyncListener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AsyncAttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -475,7 +486,7 @@

      Methods

      else: listener_matchers.append( build_listener_matcher( - func=matcher, # type:ignore[arg-type] + func=matcher, # type: ignore[arg-type] asyncio=True, base_logger=base_logger, ) @@ -516,7 +527,7 @@

      Methods

      func=is_assistant_thread_context_changed_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -525,7 +536,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -572,7 +583,7 @@

      Methods

      func=is_assistant_thread_started_event, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -581,7 +592,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -628,7 +639,7 @@

      Methods

      func=is_user_message_event_in_assistant_thread, asyncio=True, base_logger=self.base_logger, - ), # type:ignore[arg-type] + ), # type: ignore[arg-type] matchers, ) if is_used_without_argument(args): @@ -637,7 +648,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func diff --git a/docs/reference/middleware/assistant/index.html b/docs/reference/middleware/assistant/index.html index 92f405cad..e9fce8d64 100644 --- a/docs/reference/middleware/assistant/index.html +++ b/docs/reference/middleware/assistant/index.html @@ -107,7 +107,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -146,7 +146,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -185,7 +185,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -224,7 +224,7 @@

      Classes

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -254,13 +254,13 @@

      Classes

      ): return [CustomListenerMatcher(app_name=self.app_name, func=primary_matcher)] + ( custom_matchers or [] - ) # type:ignore[operator] + ) # type: ignore[operator] @staticmethod def default_thread_context_changed(save_thread_context: SaveThreadContext, payload: dict): save_thread_context(payload["assistant_thread"]["context"]) - def process( # type:ignore[return] + def process( # type: ignore[return] self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse] ) -> Optional[BoltResponse]: if self._thread_context_changed_listeners is None: @@ -276,6 +276,15 @@

      Classes

      if listeners is not None: for listener in listeners: if listener.matches(req=req, resp=resp): + middleware_resp, next_was_not_called = listener.run_middleware(req=req, resp=resp) + if next_was_not_called: + if middleware_resp is not None: + return middleware_resp + # The listener middleware didn't call next(). + # Skip this listener and try the next one. + continue + if middleware_resp is not None: + resp = middleware_resp return listener_runner.run( request=req, response=resp, @@ -295,13 +304,14 @@

      Classes

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -310,7 +320,7 @@

      Classes

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -389,7 +399,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -429,13 +439,14 @@

      Methods

      middleware: Optional[List[Middleware]] = None, base_logger: Optional[Logger] = None, ) -> Listener: - if isinstance(listener_or_functions, Callable): # type:ignore[arg-type] - listener_or_functions = [listener_or_functions] # type:ignore[list-item] + if isinstance(listener_or_functions, Callable): # type: ignore[arg-type] + listener_or_functions = [listener_or_functions] # type: ignore[list-item] if isinstance(listener_or_functions, Listener): return listener_or_functions elif isinstance(listener_or_functions, list): middleware = middleware if middleware else [] + middleware.insert(0, AttachingConversationKwargs(self.thread_context_store)) functions = listener_or_functions ack_function = functions.pop(0) @@ -444,7 +455,7 @@

      Methods

      for matcher in matchers: if isinstance(matcher, ListenerMatcher): listener_matchers.append(matcher) - elif isinstance(matcher, Callable): # type:ignore[arg-type] + elif isinstance(matcher, Callable): # type: ignore[arg-type] listener_matchers.append( build_listener_matcher( func=matcher, @@ -490,7 +501,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -539,7 +550,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func @@ -588,7 +599,7 @@

      Methods

      self.build_listener( listener_or_functions=func, matchers=all_matchers, - middleware=middleware, # type:ignore[arg-type] + middleware=middleware, # type: ignore[arg-type] ) ) return func diff --git a/docs/reference/middleware/async_builtins.html b/docs/reference/middleware/async_builtins.html index d32deff15..1ddea9222 100644 --- a/docs/reference/middleware/async_builtins.html +++ b/docs/reference/middleware/async_builtins.html @@ -46,6 +46,82 @@

      Module slack_bolt.middleware.async_builtins

      Classes

      +
      +class AsyncAttachingConversationKwargs +(thread_context_store: AsyncAssistantThreadContextStore | None = None) +
      +
      +
      + +Expand source code + +
      class AsyncAttachingConversationKwargs(AsyncMiddleware):
      +
      +    thread_context_store: Optional[AsyncAssistantThreadContextStore]
      +
      +    def __init__(self, thread_context_store: Optional[AsyncAssistantThreadContextStore] = None):
      +        self.thread_context_store = thread_context_store
      +
      +    async def async_process(
      +        self,
      +        *,
      +        req: AsyncBoltRequest,
      +        resp: BoltResponse,
      +        next: Callable[[], Awaitable[BoltResponse]],
      +    ) -> Optional[BoltResponse]:
      +        event = to_event(req.body)
      +        if event is not None:
      +            if is_assistant_event(req.body):
      +                assistant = AsyncAssistantUtilities(
      +                    payload=event,
      +                    context=req.context,
      +                    thread_context_store=self.thread_context_store,
      +                )
      +                req.context["say"] = assistant.say
      +                req.context["set_title"] = assistant.set_title
      +                req.context["set_suggested_prompts"] = assistant.set_suggested_prompts
      +                req.context["get_thread_context"] = assistant.get_thread_context
      +                req.context["save_thread_context"] = assistant.save_thread_context
      +
      +            # TODO: in the future we might want to introduce a "proper" extract_ts utility
      +            thread_ts = req.context.thread_ts or event.get("ts")
      +            if req.context.channel_id and thread_ts:
      +                req.context["set_status"] = AsyncSetStatus(
      +                    client=req.context.client,
      +                    channel_id=req.context.channel_id,
      +                    thread_ts=thread_ts,
      +                )
      +                req.context["say_stream"] = AsyncSayStream(
      +                    client=req.context.client,
      +                    channel=req.context.channel_id,
      +                    recipient_team_id=req.context.team_id or req.context.enterprise_id,
      +                    recipient_user_id=req.context.user_id,
      +                    thread_ts=thread_ts,
      +                )
      +        return await next()
      +
      +

      A middleware can process request data before other middleware and listener functions.

      +

      Ancestors

      + +

      Class variables

      +
      +
      var thread_context_storeAsyncAssistantThreadContextStore | None
      +
      +

      The type of the None singleton.

      +
      +
      +

      Inherited members

      + +
      class AsyncAttachingFunctionToken
      @@ -395,6 +471,12 @@

      Inherited members

    • Classes

      • +

        AsyncAttachingConversationKwargs

        + +
      • +
      • AsyncAttachingFunctionToken

      • diff --git a/docs/reference/middleware/async_middleware.html b/docs/reference/middleware/async_middleware.html index 33b4273e7..f7713b881 100644 --- a/docs/reference/middleware/async_middleware.html +++ b/docs/reference/middleware/async_middleware.html @@ -104,6 +104,7 @@

        Subclasses

        • AsyncAssistant
        • AsyncCustomMiddleware
        • +
        • AsyncAttachingConversationKwargs
        • AsyncAttachingFunctionToken
        • AsyncAuthorization
        • AsyncIgnoringSelfEvents
        • diff --git a/docs/reference/middleware/async_middleware_error_handler.html b/docs/reference/middleware/async_middleware_error_handler.html index e7cd8bb32..bf5b101f6 100644 --- a/docs/reference/middleware/async_middleware_error_handler.html +++ b/docs/reference/middleware/async_middleware_error_handler.html @@ -77,9 +77,10 @@

          Classes

          ) returned_response = await self.func(**kwargs) if returned_response is not None and isinstance(returned_response, BoltResponse): - response.status = returned_response.status # type: ignore[union-attr] - response.headers = returned_response.headers # type: ignore[union-attr] - response.body = returned_response.body # type: ignore[union-attr] + assert response is not None, "response must be provided when returning a BoltResponse from an error handler" + response.status = returned_response.status + response.headers = returned_response.headers + response.body = returned_response.body
    • Ancestors

      diff --git a/docs/reference/middleware/attaching_conversation_kwargs/async_attaching_conversation_kwargs.html b/docs/reference/middleware/attaching_conversation_kwargs/async_attaching_conversation_kwargs.html new file mode 100644 index 000000000..a0f5bdf85 --- /dev/null +++ b/docs/reference/middleware/attaching_conversation_kwargs/async_attaching_conversation_kwargs.html @@ -0,0 +1,155 @@ + + + + + + +slack_bolt.middleware.attaching_conversation_kwargs.async_attaching_conversation_kwargs API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.middleware.attaching_conversation_kwargs.async_attaching_conversation_kwargs

      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class AsyncAttachingConversationKwargs +(thread_context_store: AsyncAssistantThreadContextStore | None = None) +
      +
      +
      + +Expand source code + +
      class AsyncAttachingConversationKwargs(AsyncMiddleware):
      +
      +    thread_context_store: Optional[AsyncAssistantThreadContextStore]
      +
      +    def __init__(self, thread_context_store: Optional[AsyncAssistantThreadContextStore] = None):
      +        self.thread_context_store = thread_context_store
      +
      +    async def async_process(
      +        self,
      +        *,
      +        req: AsyncBoltRequest,
      +        resp: BoltResponse,
      +        next: Callable[[], Awaitable[BoltResponse]],
      +    ) -> Optional[BoltResponse]:
      +        event = to_event(req.body)
      +        if event is not None:
      +            if is_assistant_event(req.body):
      +                assistant = AsyncAssistantUtilities(
      +                    payload=event,
      +                    context=req.context,
      +                    thread_context_store=self.thread_context_store,
      +                )
      +                req.context["say"] = assistant.say
      +                req.context["set_title"] = assistant.set_title
      +                req.context["set_suggested_prompts"] = assistant.set_suggested_prompts
      +                req.context["get_thread_context"] = assistant.get_thread_context
      +                req.context["save_thread_context"] = assistant.save_thread_context
      +
      +            # TODO: in the future we might want to introduce a "proper" extract_ts utility
      +            thread_ts = req.context.thread_ts or event.get("ts")
      +            if req.context.channel_id and thread_ts:
      +                req.context["set_status"] = AsyncSetStatus(
      +                    client=req.context.client,
      +                    channel_id=req.context.channel_id,
      +                    thread_ts=thread_ts,
      +                )
      +                req.context["say_stream"] = AsyncSayStream(
      +                    client=req.context.client,
      +                    channel=req.context.channel_id,
      +                    recipient_team_id=req.context.team_id or req.context.enterprise_id,
      +                    recipient_user_id=req.context.user_id,
      +                    thread_ts=thread_ts,
      +                )
      +        return await next()
      +
      +

      A middleware can process request data before other middleware and listener functions.

      +

      Ancestors

      + +

      Class variables

      +
      +
      var thread_context_storeAsyncAssistantThreadContextStore | None
      +
      +

      The type of the None singleton.

      +
      +
      +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/middleware/attaching_conversation_kwargs/attaching_conversation_kwargs.html b/docs/reference/middleware/attaching_conversation_kwargs/attaching_conversation_kwargs.html new file mode 100644 index 000000000..8a1911323 --- /dev/null +++ b/docs/reference/middleware/attaching_conversation_kwargs/attaching_conversation_kwargs.html @@ -0,0 +1,149 @@ + + + + + + +slack_bolt.middleware.attaching_conversation_kwargs.attaching_conversation_kwargs API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.middleware.attaching_conversation_kwargs.attaching_conversation_kwargs

      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class AttachingConversationKwargs +(thread_context_store: AssistantThreadContextStore | None = None) +
      +
      +
      + +Expand source code + +
      class AttachingConversationKwargs(Middleware):
      +
      +    thread_context_store: Optional[AssistantThreadContextStore]
      +
      +    def __init__(self, thread_context_store: Optional[AssistantThreadContextStore] = None):
      +        self.thread_context_store = thread_context_store
      +
      +    def process(self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse]) -> Optional[BoltResponse]:
      +        event = to_event(req.body)
      +        if event is not None:
      +            if is_assistant_event(req.body):
      +                assistant = AssistantUtilities(
      +                    payload=event,
      +                    context=req.context,
      +                    thread_context_store=self.thread_context_store,
      +                )
      +                req.context["say"] = assistant.say
      +                req.context["set_title"] = assistant.set_title
      +                req.context["set_suggested_prompts"] = assistant.set_suggested_prompts
      +                req.context["get_thread_context"] = assistant.get_thread_context
      +                req.context["save_thread_context"] = assistant.save_thread_context
      +
      +            # TODO: in the future we might want to introduce a "proper" extract_ts utility
      +            thread_ts = req.context.thread_ts or event.get("ts")
      +            if req.context.channel_id and thread_ts:
      +                req.context["set_status"] = SetStatus(
      +                    client=req.context.client,
      +                    channel_id=req.context.channel_id,
      +                    thread_ts=thread_ts,
      +                )
      +                req.context["say_stream"] = SayStream(
      +                    client=req.context.client,
      +                    channel=req.context.channel_id,
      +                    recipient_team_id=req.context.team_id or req.context.enterprise_id,
      +                    recipient_user_id=req.context.user_id,
      +                    thread_ts=thread_ts,
      +                )
      +        return next()
      +
      +

      A middleware can process request data before other middleware and listener functions.

      +

      Ancestors

      + +

      Class variables

      +
      +
      var thread_context_storeAssistantThreadContextStore | None
      +
      +

      The type of the None singleton.

      +
      +
      +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/middleware/attaching_conversation_kwargs/index.html b/docs/reference/middleware/attaching_conversation_kwargs/index.html new file mode 100644 index 000000000..308a52712 --- /dev/null +++ b/docs/reference/middleware/attaching_conversation_kwargs/index.html @@ -0,0 +1,166 @@ + + + + + + +slack_bolt.middleware.attaching_conversation_kwargs API documentation + + + + + + + + + + + +
      +
      +
      +

      Module slack_bolt.middleware.attaching_conversation_kwargs

      +
      +
      +
      +
      +

      Sub-modules

      +
      +
      slack_bolt.middleware.attaching_conversation_kwargs.async_attaching_conversation_kwargs
      +
      +
      +
      +
      slack_bolt.middleware.attaching_conversation_kwargs.attaching_conversation_kwargs
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +
      +

      Classes

      +
      +
      +class AttachingConversationKwargs +(thread_context_store: AssistantThreadContextStore | None = None) +
      +
      +
      + +Expand source code + +
      class AttachingConversationKwargs(Middleware):
      +
      +    thread_context_store: Optional[AssistantThreadContextStore]
      +
      +    def __init__(self, thread_context_store: Optional[AssistantThreadContextStore] = None):
      +        self.thread_context_store = thread_context_store
      +
      +    def process(self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse]) -> Optional[BoltResponse]:
      +        event = to_event(req.body)
      +        if event is not None:
      +            if is_assistant_event(req.body):
      +                assistant = AssistantUtilities(
      +                    payload=event,
      +                    context=req.context,
      +                    thread_context_store=self.thread_context_store,
      +                )
      +                req.context["say"] = assistant.say
      +                req.context["set_title"] = assistant.set_title
      +                req.context["set_suggested_prompts"] = assistant.set_suggested_prompts
      +                req.context["get_thread_context"] = assistant.get_thread_context
      +                req.context["save_thread_context"] = assistant.save_thread_context
      +
      +            # TODO: in the future we might want to introduce a "proper" extract_ts utility
      +            thread_ts = req.context.thread_ts or event.get("ts")
      +            if req.context.channel_id and thread_ts:
      +                req.context["set_status"] = SetStatus(
      +                    client=req.context.client,
      +                    channel_id=req.context.channel_id,
      +                    thread_ts=thread_ts,
      +                )
      +                req.context["say_stream"] = SayStream(
      +                    client=req.context.client,
      +                    channel=req.context.channel_id,
      +                    recipient_team_id=req.context.team_id or req.context.enterprise_id,
      +                    recipient_user_id=req.context.user_id,
      +                    thread_ts=thread_ts,
      +                )
      +        return next()
      +
      +

      A middleware can process request data before other middleware and listener functions.

      +

      Ancestors

      + +

      Class variables

      +
      +
      var thread_context_storeAssistantThreadContextStore | None
      +
      +

      The type of the None singleton.

      +
      +
      +

      Inherited members

      + +
      +
      +
      +
      + +
      + + + diff --git a/docs/reference/middleware/index.html b/docs/reference/middleware/index.html index 05d773415..ce2629224 100644 --- a/docs/reference/middleware/index.html +++ b/docs/reference/middleware/index.html @@ -65,6 +65,10 @@

      Sub-modules

      +
      slack_bolt.middleware.attaching_conversation_kwargs
      +
      +
      +
      slack_bolt.middleware.attaching_function_token
      @@ -114,6 +118,76 @@

      Sub-modules

      Classes

      +
      +class AttachingConversationKwargs +(thread_context_store: AssistantThreadContextStore | None = None) +
      +
      +
      + +Expand source code + +
      class AttachingConversationKwargs(Middleware):
      +
      +    thread_context_store: Optional[AssistantThreadContextStore]
      +
      +    def __init__(self, thread_context_store: Optional[AssistantThreadContextStore] = None):
      +        self.thread_context_store = thread_context_store
      +
      +    def process(self, *, req: BoltRequest, resp: BoltResponse, next: Callable[[], BoltResponse]) -> Optional[BoltResponse]:
      +        event = to_event(req.body)
      +        if event is not None:
      +            if is_assistant_event(req.body):
      +                assistant = AssistantUtilities(
      +                    payload=event,
      +                    context=req.context,
      +                    thread_context_store=self.thread_context_store,
      +                )
      +                req.context["say"] = assistant.say
      +                req.context["set_title"] = assistant.set_title
      +                req.context["set_suggested_prompts"] = assistant.set_suggested_prompts
      +                req.context["get_thread_context"] = assistant.get_thread_context
      +                req.context["save_thread_context"] = assistant.save_thread_context
      +
      +            # TODO: in the future we might want to introduce a "proper" extract_ts utility
      +            thread_ts = req.context.thread_ts or event.get("ts")
      +            if req.context.channel_id and thread_ts:
      +                req.context["set_status"] = SetStatus(
      +                    client=req.context.client,
      +                    channel_id=req.context.channel_id,
      +                    thread_ts=thread_ts,
      +                )
      +                req.context["say_stream"] = SayStream(
      +                    client=req.context.client,
      +                    channel=req.context.channel_id,
      +                    recipient_team_id=req.context.team_id or req.context.enterprise_id,
      +                    recipient_user_id=req.context.user_id,
      +                    thread_ts=thread_ts,
      +                )
      +        return next()
      +
      +

      A middleware can process request data before other middleware and listener functions.

      +

      Ancestors

      + +

      Class variables

      +
      +
      var thread_context_storeAssistantThreadContextStore | None
      +
      +

      The type of the None singleton.

      +
      +
      +

      Inherited members

      + +
      class AttachingFunctionToken
      @@ -385,6 +459,7 @@

      Inherited members

      Subclasses

      Ancestors

      diff --git a/docs/reference/oauth/async_callback_options.html b/docs/reference/oauth/async_callback_options.html index 822867ea8..d07f1aee5 100644 --- a/docs/reference/oauth/async_callback_options.html +++ b/docs/reference/oauth/async_callback_options.html @@ -101,7 +101,7 @@

      Class variables

      reason: str, error: Optional[Exception] = None, suggested_status_code: int, - settings: "AsyncOAuthSettings", # type: ignore[name-defined] + settings: "AsyncOAuthSettings", default: "AsyncCallbackOptions", ): """The arguments for a failure function. @@ -153,7 +153,7 @@

      Args

      *, request: AsyncBoltRequest, installation: Installation, - settings: "AsyncOAuthSettings", # type: ignore[name-defined] + settings: "AsyncOAuthSettings", default: "AsyncCallbackOptions", ): """The arguments for a success function. diff --git a/docs/reference/oauth/async_oauth_settings.html b/docs/reference/oauth/async_oauth_settings.html index 3b8c04edb..5e6a543c4 100644 --- a/docs/reference/oauth/async_oauth_settings.html +++ b/docs/reference/oauth/async_oauth_settings.html @@ -48,7 +48,7 @@

      Classes

      class AsyncOAuthSettings -(*,
      client_id: str | None = None,
      client_secret: str | None = None,
      scopes: Sequence[str] | str | None = None,
      user_scopes: Sequence[str] | str | None = None,
      redirect_uri: str | None = None,
      install_path: str = '/slack/install',
      install_page_rendering_enabled: bool = True,
      redirect_uri_path: str = '/slack/oauth_redirect',
      callback_options: AsyncCallbackOptions | None = None,
      success_url: str | None = None,
      failure_url: str | None = None,
      authorization_url: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
      installation_store_bot_only: bool = False,
      token_rotation_expiration_minutes: int = 120,
      user_token_resolution: str = 'authed_user',
      state_validation_enabled: bool = True,
      state_store: slack_sdk.oauth.state_store.async_state_store.AsyncOAuthStateStore | None = None,
      state_cookie_name: str = 'slack-app-oauth-state',
      state_expiration_seconds: int = 600,
      logger: logging.Logger = <Logger slack_bolt.oauth.async_oauth_settings (WARNING)>)
      +(*,
      client_id: str | None = None,
      client_secret: str | None = None,
      scopes: str | Sequence[str] | None = None,
      user_scopes: str | Sequence[str] | None = None,
      redirect_uri: str | None = None,
      install_path: str = '/slack/install',
      install_page_rendering_enabled: bool = True,
      redirect_uri_path: str = '/slack/oauth_redirect',
      callback_options: AsyncCallbackOptions | None = None,
      success_url: str | None = None,
      failure_url: str | None = None,
      authorization_url: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.async_installation_store.AsyncInstallationStore | None = None,
      installation_store_bot_only: bool = False,
      token_rotation_expiration_minutes: int = 120,
      user_token_resolution: str = 'authed_user',
      state_validation_enabled: bool = True,
      state_store: slack_sdk.oauth.state_store.async_state_store.AsyncOAuthStateStore | None = None,
      state_cookie_name: str = 'slack-app-oauth-state',
      state_expiration_seconds: int = 600,
      logger: logging.Logger = <Logger slack_bolt.oauth.async_oauth_settings (WARNING)>)
      diff --git a/docs/reference/oauth/callback_options.html b/docs/reference/oauth/callback_options.html index 7ad3734b3..c6fc81286 100644 --- a/docs/reference/oauth/callback_options.html +++ b/docs/reference/oauth/callback_options.html @@ -181,7 +181,7 @@

      Inherited members

      reason: str, error: Optional[Exception] = None, suggested_status_code: int, - settings: "OAuthSettings", # type: ignore[name-defined] + settings: "OAuthSettings", default: "CallbackOptions", ): """The arguments for a failure function. @@ -233,7 +233,7 @@

      Args

      *, request: BoltRequest, installation: Installation, - settings: "OAuthSettings", # type: ignore[name-defined] + settings: "OAuthSettings", default: "CallbackOptions", ): """The arguments for a success function. diff --git a/docs/reference/oauth/oauth_settings.html b/docs/reference/oauth/oauth_settings.html index cd8def497..1eb2ab7dd 100644 --- a/docs/reference/oauth/oauth_settings.html +++ b/docs/reference/oauth/oauth_settings.html @@ -48,7 +48,7 @@

      Classes

      class OAuthSettings -(*,
      client_id: str | None = None,
      client_secret: str | None = None,
      scopes: Sequence[str] | str | None = None,
      user_scopes: Sequence[str] | str | None = None,
      redirect_uri: str | None = None,
      install_path: str = '/slack/install',
      install_page_rendering_enabled: bool = True,
      redirect_uri_path: str = '/slack/oauth_redirect',
      callback_options: CallbackOptions | None = None,
      success_url: str | None = None,
      failure_url: str | None = None,
      authorization_url: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
      installation_store_bot_only: bool = False,
      token_rotation_expiration_minutes: int = 120,
      user_token_resolution: str = 'authed_user',
      state_validation_enabled: bool = True,
      state_store: slack_sdk.oauth.state_store.state_store.OAuthStateStore | None = None,
      state_cookie_name: str = 'slack-app-oauth-state',
      state_expiration_seconds: int = 600,
      logger: logging.Logger = <Logger slack_bolt.oauth.oauth_settings (WARNING)>)
      +(*,
      client_id: str | None = None,
      client_secret: str | None = None,
      scopes: str | Sequence[str] | None = None,
      user_scopes: str | Sequence[str] | None = None,
      redirect_uri: str | None = None,
      install_path: str = '/slack/install',
      install_page_rendering_enabled: bool = True,
      redirect_uri_path: str = '/slack/oauth_redirect',
      callback_options: CallbackOptions | None = None,
      success_url: str | None = None,
      failure_url: str | None = None,
      authorization_url: str | None = None,
      installation_store: slack_sdk.oauth.installation_store.installation_store.InstallationStore | None = None,
      installation_store_bot_only: bool = False,
      token_rotation_expiration_minutes: int = 120,
      user_token_resolution: str = 'authed_user',
      state_validation_enabled: bool = True,
      state_store: slack_sdk.oauth.state_store.state_store.OAuthStateStore | None = None,
      state_cookie_name: str = 'slack-app-oauth-state',
      state_expiration_seconds: int = 600,
      logger: logging.Logger = <Logger slack_bolt.oauth.oauth_settings (WARNING)>)
      diff --git a/docs/reference/request/internals.html b/docs/reference/request/internals.html index bc13932ec..bd8319183 100644 --- a/docs/reference/request/internals.html +++ b/docs/reference/request/internals.html @@ -268,12 +268,12 @@

      Functions

      return channel.get("id") if "channel_id" in payload: return payload.get("channel_id") - if payload.get("event") is not None: + if isinstance(payload.get("event"), dict): return extract_channel_id(payload["event"]) - if payload.get("item") is not None: + if isinstance(payload.get("item"), dict): # reaction_added: body["event"]["item"] return extract_channel_id(payload["item"]) - if payload.get("assistant_thread") is not None: + if isinstance(payload.get("assistant_thread"), dict): # assistant_thread_started return extract_channel_id(payload["assistant_thread"]) return None @@ -317,10 +317,10 @@

      Functions

      return extract_enterprise_id(payload["authorizations"][0]) if "enterprise_id" in payload: return payload.get("enterprise_id") - if payload.get("team") is not None and "enterprise_id" in payload["team"]: + if isinstance(payload.get("team"), dict) and "enterprise_id" in payload["team"]: # In the case where the type is view_submission return payload["team"].get("enterprise_id") - if payload.get("event") is not None: + if isinstance(payload.get("event"), dict): return extract_enterprise_id(payload["event"]) return None
      @@ -337,7 +337,7 @@

      Functions

      def extract_function_bot_access_token(payload: Dict[str, Any]) -> Optional[str]:
           if payload.get("bot_access_token") is not None:
               return payload.get("bot_access_token")
      -    if payload.get("event") is not None:
      +    if isinstance(payload.get("event"), dict):
               return payload["event"].get("bot_access_token")
           return None
      @@ -354,9 +354,9 @@

      Functions

      def extract_function_execution_id(payload: Dict[str, Any]) -> Optional[str]:
           if payload.get("function_execution_id") is not None:
               return payload.get("function_execution_id")
      -    if payload.get("event") is not None:
      +    if isinstance(payload.get("event"), dict):
               return extract_function_execution_id(payload["event"])
      -    if payload.get("function_data") is not None:
      +    if isinstance(payload.get("function_data"), dict):
               return payload["function_data"].get("execution_id")
           return None
      @@ -371,9 +371,9 @@

      Functions

      Expand source code
      def extract_function_inputs(payload: Dict[str, Any]) -> Optional[Dict[str, Any]]:
      -    if payload.get("event") is not None:
      +    if isinstance(payload.get("event"), dict):
               return payload["event"].get("inputs")
      -    if payload.get("function_data") is not None:
      +    if isinstance(payload.get("function_data"), dict):
               return payload["function_data"].get("inputs")
           return None
      @@ -408,13 +408,13 @@

      Functions

      Expand source code
      def extract_team_id(payload: Dict[str, Any]) -> Optional[str]:
      -    app_installed_team_id = payload.get("view", {}).get("app_installed_team_id")
      -    if app_installed_team_id is not None:
      +    view = payload.get("view")
      +    if isinstance(view, dict) and view.get("app_installed_team_id") is not None:
               # view_submission payloads can have `view.app_installed_team_id` when a modal view that was opened
               # in a different workspace via some operations inside a Slack Connect channel.
               # Note that the same for enterprise_id does not exist. When you need to know the enterprise_id as well,
               # you have to run some query toward your InstallationStore to know the org where the team_id belongs to.
      -        return app_installed_team_id
      +        return view["app_installed_team_id"]
           if payload.get("team") is not None:
               # With org-wide installations, payload.team in interactivity payloads can be None
               # You need to extract either payload.user.team_id or payload.view.team_id as below
      @@ -429,12 +429,12 @@ 

      Functions

      return extract_team_id(payload["authorizations"][0]) if "team_id" in payload: return payload.get("team_id") - if payload.get("event") is not None: + if isinstance(payload.get("event"), dict): return extract_team_id(payload["event"]) - if payload.get("user") is not None: + if isinstance(payload.get("user"), dict): return payload["user"]["team_id"] - if payload.get("view") is not None: - return payload.get("view", {})["team_id"] + if isinstance(payload.get("view"), dict): + return payload["view"]["team_id"] return None
      @@ -448,30 +448,17 @@

      Functions

      Expand source code
      def extract_thread_ts(payload: Dict[str, Any]) -> Optional[str]:
      -    # This utility initially supports only the use cases for AI assistants, but it may be fine to add more patterns.
      -    # That said, note that thread_ts is always required for assistant threads, but it's not for channels.
      -    # Thus, blindly setting this thread_ts to say utility can break existing apps' behaviors.
      -    if is_assistant_event(payload):
      -        event = payload["event"]
      -        if (
      -            event.get("assistant_thread") is not None
      -            and event["assistant_thread"].get("channel_id") is not None
      -            and event["assistant_thread"].get("thread_ts") is not None
      -        ):
      -            # assistant_thread_started, assistant_thread_context_changed
      -            # "assistant_thread" property can exist for message event without channel_id and thread_ts
      -            # Thus, the above if check verifies these properties exist
      -            return event["assistant_thread"]["thread_ts"]
      -        elif event.get("channel") is not None:
      -            if event.get("thread_ts") is not None:
      -                # message in an assistant thread
      -                return event["thread_ts"]
      -            elif event.get("message", {}).get("thread_ts") is not None:
      -                # message_changed
      -                return event["message"]["thread_ts"]
      -            elif event.get("previous_message", {}).get("thread_ts") is not None:
      -                # message_deleted
      -                return event["previous_message"]["thread_ts"]
      +    thread_ts = payload.get("thread_ts")
      +    if thread_ts is not None:
      +        return thread_ts
      +    if isinstance(payload.get("event"), dict):
      +        return extract_thread_ts(payload["event"])
      +    if isinstance(payload.get("assistant_thread"), dict):
      +        return extract_thread_ts(payload["assistant_thread"])
      +    if isinstance(payload.get("message"), dict):
      +        return extract_thread_ts(payload["message"])
      +    if isinstance(payload.get("previous_message"), dict):
      +        return extract_thread_ts(payload["previous_message"])
           return None
      @@ -493,12 +480,12 @@

      Functions

      return user.get("id") if "user_id" in payload: return payload.get("user_id") - if payload.get("event") is not None: + if isinstance(payload.get("event"), dict): return extract_user_id(payload["event"]) - if payload.get("message") is not None: + if isinstance(payload.get("message"), dict): # message_changed: body["event"]["message"] return extract_user_id(payload["message"]) - if payload.get("previous_message") is not None: + if isinstance(payload.get("previous_message"), dict): # message_deleted: body["event"]["previous_message"] return extract_user_id(payload["previous_message"]) return None diff --git a/slack_bolt/version.py b/slack_bolt/version.py index 9b1349aea..ebda7dafb 100644 --- a/slack_bolt/version.py +++ b/slack_bolt/version.py @@ -1,3 +1,3 @@ """Check the latest version at https://pypi.org/project/slack-bolt/""" -__version__ = "1.27.0" +__version__ = "1.28.0"