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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions slack_bolt/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
IgnoringSelfEvents,
CustomMiddleware,
AttachingFunctionToken,
AttachingAgentKwargs,
AttachingConversationKwargs,
)
from slack_bolt.middleware.assistant import Assistant
from slack_bolt.middleware.message_listener_matches import MessageListenerMatches
Expand Down Expand Up @@ -133,7 +133,7 @@ def __init__(
listener_executor: Optional[Executor] = None,
# for AI Agents & Assistants
assistant_thread_context_store: Optional[AssistantThreadContextStore] = None,
attaching_agent_kwargs_enabled: bool = True,
attaching_conversation_kwargs_enabled: bool = True,
):
"""Bolt App that provides functionalities to register middleware/listeners.

Expand Down Expand Up @@ -354,7 +354,7 @@ def message_hello(message, say):
listener_executor = ThreadPoolExecutor(max_workers=5)

self._assistant_thread_context_store = assistant_thread_context_store
self._attaching_agent_kwargs_enabled = attaching_agent_kwargs_enabled
self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled

self._process_before_response = process_before_response
self._listener_runner = ThreadListenerRunner(
Expand Down Expand Up @@ -844,8 +844,8 @@ def ask_for_introduction(event, say):
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_agent_kwargs_enabled:
middleware.insert(0, AttachingAgentKwargs(self._assistant_thread_context_store))
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__
Expand Down Expand Up @@ -903,8 +903,8 @@ def __call__(*args, **kwargs):
primary_matcher = builtin_matchers.message_event(
keyword=keyword, constraints=constraints, base_logger=self._base_logger
)
if self._attaching_agent_kwargs_enabled:
middleware.insert(0, AttachingAgentKwargs(self._assistant_thread_context_store))
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)

Expand Down
14 changes: 7 additions & 7 deletions slack_bolt/app/async_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
AsyncIgnoringSelfEvents,
AsyncUrlVerification,
AsyncAttachingFunctionToken,
AsyncAttachingAgentKwargs,
AsyncAttachingConversationKwargs,
)
from slack_bolt.middleware.async_custom_middleware import (
AsyncMiddleware,
Expand Down Expand Up @@ -142,7 +142,7 @@ def __init__(
verification_token: Optional[str] = None,
# for AI Agents & Assistants
assistant_thread_context_store: Optional[AsyncAssistantThreadContextStore] = None,
attaching_agent_kwargs_enabled: bool = True,
attaching_conversation_kwargs_enabled: bool = True,
):
"""Bolt App that provides functionalities to register middleware/listeners.

Expand Down Expand Up @@ -363,7 +363,7 @@ async def message_hello(message, say): # async function
self._async_listeners: List[AsyncListener] = []

self._assistant_thread_context_store = assistant_thread_context_store
self._attaching_agent_kwargs_enabled = attaching_agent_kwargs_enabled
self._attaching_conversation_kwargs_enabled = attaching_conversation_kwargs_enabled

self._process_before_response = process_before_response
self._async_listener_runner = AsyncioListenerRunner(
Expand Down Expand Up @@ -872,8 +872,8 @@ async def ask_for_introduction(event, say):
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_agent_kwargs_enabled:
middleware.insert(0, AsyncAttachingAgentKwargs(self._assistant_thread_context_store))
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__
Expand Down Expand Up @@ -934,8 +934,8 @@ def __call__(*args, **kwargs):
asyncio=True,
base_logger=self._base_logger,
)
if self._attaching_agent_kwargs_enabled:
middleware.insert(0, AsyncAttachingAgentKwargs(self._assistant_thread_context_store))
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)

Expand Down
2 changes: 1 addition & 1 deletion slack_bolt/kwargs_injection/args.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def handle_buttons(args):
save_thread_context: Optional[SaveThreadContext]
"""`save_thread_context()` utility function for AI Agents & Assistants"""
say_stream: Optional[SayStream]
"""`say_stream()` utility function for AI Agents & Assistants"""
"""`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"""
Expand Down
4 changes: 2 additions & 2 deletions slack_bolt/middleware/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .ssl_check import SslCheck
from .url_verification import UrlVerification
from .attaching_function_token import AttachingFunctionToken
from .attaching_agent_kwargs import AttachingAgentKwargs
from .attaching_conversation_kwargs import AttachingConversationKwargs

builtin_middleware_classes = [
SslCheck,
Expand All @@ -42,6 +42,6 @@
"SslCheck",
"UrlVerification",
"AttachingFunctionToken",
"AttachingAgentKwargs",
"AttachingConversationKwargs",
"builtin_middleware_classes",
]
4 changes: 2 additions & 2 deletions slack_bolt/middleware/assistant/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from slack_bolt.context.assistant.thread_context_store.store import AssistantThreadContextStore
from slack_bolt.listener_matcher.builtins import build_listener_matcher

from slack_bolt.middleware.attaching_agent_kwargs import AttachingAgentKwargs
from slack_bolt.middleware.attaching_conversation_kwargs import AttachingConversationKwargs
from slack_bolt.request.request import BoltRequest
from slack_bolt.response.response import BoltResponse
from slack_bolt.listener_matcher import CustomListenerMatcher
Expand Down Expand Up @@ -272,7 +272,7 @@ def build_listener(
return listener_or_functions
elif isinstance(listener_or_functions, list):
middleware = middleware if middleware else []
middleware.insert(0, AttachingAgentKwargs(self.thread_context_store))
middleware.insert(0, AttachingConversationKwargs(self.thread_context_store))
functions = listener_or_functions
ack_function = functions.pop(0)

Expand Down
6 changes: 4 additions & 2 deletions slack_bolt/middleware/assistant/async_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

from slack_bolt.listener.asyncio_runner import AsyncioListenerRunner
from slack_bolt.listener_matcher.builtins import build_listener_matcher
from slack_bolt.middleware.attaching_agent_kwargs.async_attaching_agent_kwargs import AsyncAttachingAgentKwargs
from slack_bolt.middleware.attaching_conversation_kwargs.async_attaching_conversation_kwargs import (
AsyncAttachingConversationKwargs,
)
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse
from slack_bolt.error import BoltError
Expand Down Expand Up @@ -301,7 +303,7 @@ def build_listener(
return listener_or_functions
elif isinstance(listener_or_functions, list):
middleware = middleware if middleware else []
middleware.insert(0, AsyncAttachingAgentKwargs(self.thread_context_store))
middleware.insert(0, AsyncAttachingConversationKwargs(self.thread_context_store))
functions = listener_or_functions
ack_function = functions.pop(0)

Expand Down
4 changes: 2 additions & 2 deletions slack_bolt/middleware/async_builtins.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
AsyncMessageListenerMatches,
)
from .attaching_function_token.async_attaching_function_token import AsyncAttachingFunctionToken
from .attaching_agent_kwargs.async_attaching_agent_kwargs import AsyncAttachingAgentKwargs
from .attaching_conversation_kwargs.async_attaching_conversation_kwargs import AsyncAttachingConversationKwargs

__all__ = [
"AsyncIgnoringSelfEvents",
Expand All @@ -19,5 +19,5 @@
"AsyncUrlVerification",
"AsyncMessageListenerMatches",
"AsyncAttachingFunctionToken",
"AsyncAttachingAgentKwargs",
"AsyncAttachingConversationKwargs",
]
5 changes: 0 additions & 5 deletions slack_bolt/middleware/attaching_agent_kwargs/__init__.py

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from .attaching_conversation_kwargs import AttachingConversationKwargs

__all__ = [
"AttachingConversationKwargs",
]
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from slack_bolt.response import BoltResponse


class AsyncAttachingAgentKwargs(AsyncMiddleware):
class AsyncAttachingConversationKwargs(AsyncMiddleware):

thread_context_store: Optional[AsyncAssistantThreadContextStore]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from slack_bolt.response.response import BoltResponse


class AttachingAgentKwargs(Middleware):
class AttachingConversationKwargs(Middleware):

thread_context_store: Optional[AssistantThreadContextStore]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,8 @@ def handle_message_event(
assert response.status == 200
assert listener_called.wait(timeout=0.1) is True

def test_assistant_events_agent_kwargs_disabled(self):
app = App(client=self.web_client, attaching_agent_kwargs_enabled=False)
def test_assistant_events_conversation_kwargs_disabled(self):
app = App(client=self.web_client, attaching_conversation_kwargs_enabled=False)

listener_called = Event()

Expand Down
2 changes: 1 addition & 1 deletion tests/scenario_tests_async/test_events_assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ async def handle_bot_message():

@pytest.mark.asyncio
async def test_assistant_events_kwargs_disabled(self):
app = AsyncApp(client=self.web_client, attaching_agent_kwargs_enabled=False)
app = AsyncApp(client=self.web_client, attaching_conversation_kwargs_enabled=False)
listener_called = asyncio.Event()

@app.event("assistant_thread_started")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ async def handle_message_event(
assert (await asyncio.wait_for(listener_called.wait(), timeout=0.1)) is True

@pytest.mark.asyncio
async def test_assistant_events_agent_kwargs_disabled(self):
app = AsyncApp(client=self.web_client, attaching_agent_kwargs_enabled=False)
async def test_assistant_events_conversation_kwargs_disabled(self):
app = AsyncApp(client=self.web_client, attaching_conversation_kwargs_enabled=False)

listener_called = asyncio.Event()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from slack_sdk import WebClient

from slack_bolt.middleware.attaching_agent_kwargs import AttachingAgentKwargs
from slack_bolt.middleware.attaching_conversation_kwargs import AttachingConversationKwargs
from slack_bolt.request import BoltRequest
from slack_bolt.response import BoltResponse
from tests.scenario_tests.test_events_assistant import (
Expand All @@ -17,9 +17,9 @@ def next():
ASSISTANT_KWARGS = ("say", "set_title", "set_suggested_prompts", "get_thread_context", "save_thread_context")


class TestAttachingAgentKwargs:
class TestAttachingConversationKwargs:
def test_assistant_event_attaches_kwargs(self):
middleware = AttachingAgentKwargs()
middleware = AttachingConversationKwargs()
req = BoltRequest(body=thread_started_event_body, mode="socket_mode")
req.context["client"] = WebClient(token="xoxb-test")

Expand All @@ -33,7 +33,7 @@ def test_assistant_event_attaches_kwargs(self):
assert "set_status" in req.context

def test_user_message_event_attaches_kwargs(self):
middleware = AttachingAgentKwargs()
middleware = AttachingConversationKwargs()
req = BoltRequest(body=user_message_event_body, mode="socket_mode")
req.context["client"] = WebClient(token="xoxb-test")

Expand All @@ -47,7 +47,7 @@ def test_user_message_event_attaches_kwargs(self):
assert "set_status" in req.context

def test_non_assistant_event_does_not_attach_kwargs(self):
middleware = AttachingAgentKwargs()
middleware = AttachingConversationKwargs()
req = BoltRequest(body=channel_user_message_event_body, mode="socket_mode")
req.context["client"] = WebClient(token="xoxb-test")

Expand All @@ -60,7 +60,7 @@ def test_non_assistant_event_does_not_attach_kwargs(self):
assert "set_status" in req.context

def test_non_event_does_not_attach_kwargs(self):
middleware = AttachingAgentKwargs()
middleware = AttachingConversationKwargs()
req = BoltRequest(body="payload={}", headers={})

resp = middleware.process(req=req, resp=BoltResponse(status=404), next=next)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import pytest
from slack_sdk.web.async_client import AsyncWebClient

from slack_bolt.middleware.attaching_agent_kwargs.async_attaching_agent_kwargs import AsyncAttachingAgentKwargs
from slack_bolt.middleware.attaching_conversation_kwargs.async_attaching_conversation_kwargs import (
AsyncAttachingConversationKwargs,
)
from slack_bolt.request.async_request import AsyncBoltRequest
from slack_bolt.response import BoltResponse
from tests.scenario_tests_async.test_events_assistant import (
Expand All @@ -18,10 +20,10 @@ async def next():
ASSISTANT_KWARGS = ("say", "set_title", "set_suggested_prompts", "get_thread_context", "save_thread_context")


class TestAsyncAttachingAgentKwargs:
class TestAsyncAttachingConversationKwargs:
@pytest.mark.asyncio
async def test_assistant_event_attaches_kwargs(self):
middleware = AsyncAttachingAgentKwargs()
middleware = AsyncAttachingConversationKwargs()
req = AsyncBoltRequest(body=thread_started_event_body, mode="socket_mode")
req.context["client"] = AsyncWebClient(token="xoxb-test")

Expand All @@ -36,7 +38,7 @@ async def test_assistant_event_attaches_kwargs(self):

@pytest.mark.asyncio
async def test_user_message_event_attaches_kwargs(self):
middleware = AsyncAttachingAgentKwargs()
middleware = AsyncAttachingConversationKwargs()
req = AsyncBoltRequest(body=user_message_event_body, mode="socket_mode")
req.context["client"] = AsyncWebClient(token="xoxb-test")

Expand All @@ -51,7 +53,7 @@ async def test_user_message_event_attaches_kwargs(self):

@pytest.mark.asyncio
async def test_non_assistant_event_does_not_attach_kwargs(self):
middleware = AsyncAttachingAgentKwargs()
middleware = AsyncAttachingConversationKwargs()
req = AsyncBoltRequest(body=channel_user_message_event_body, mode="socket_mode")
req.context["client"] = AsyncWebClient(token="xoxb-test")

Expand All @@ -65,7 +67,7 @@ async def test_non_assistant_event_does_not_attach_kwargs(self):

@pytest.mark.asyncio
async def test_non_event_does_not_attach_kwargs(self):
middleware = AsyncAttachingAgentKwargs()
middleware = AsyncAttachingConversationKwargs()
req = AsyncBoltRequest(body="payload={}", headers={})

resp = await middleware.async_process(req=req, resp=BoltResponse(status=404), next=next)
Expand Down
Loading