From cb1fff151be84bc99d7209a722de08e9f1753309 Mon Sep 17 00:00:00 2001 From: Renato Byrro Date: Tue, 1 Apr 2025 17:01:25 -0300 Subject: [PATCH] Fix issue in `get_channel_metadata_by_name`: missing scope for private channels and conversation types filter (#338) --- toolkits/slack/arcade_slack/tools/chat.py | 11 ++++- toolkits/slack/pyproject.toml | 2 +- toolkits/slack/tests/test_chat.py | 54 +++++++++++++++++++---- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/toolkits/slack/arcade_slack/tools/chat.py b/toolkits/slack/arcade_slack/tools/chat.py index bd1a446f..f2c40581 100644 --- a/toolkits/slack/arcade_slack/tools/chat.py +++ b/toolkits/slack/arcade_slack/tools/chat.py @@ -624,7 +624,7 @@ async def get_conversation_metadata_by_id( return dict(**extract_conversation_metadata(response["channel"])) -@tool(requires_auth=Slack(scopes=["channels:read"])) +@tool(requires_auth=Slack(scopes=["channels:read", "groups:read"])) async def get_channel_metadata_by_name( context: ToolContext, channel_name: Annotated[str, "The name of the channel to get metadata for"], @@ -644,7 +644,14 @@ async def get_channel_metadata_by_name( should_continue = True while should_continue: - response = await list_conversations_metadata(context, next_cursor=next_cursor) + response = await list_conversations_metadata( + context=context, + conversation_types=[ + ConversationType.PUBLIC_CHANNEL, + ConversationType.PRIVATE_CHANNEL, + ], + next_cursor=next_cursor, + ) next_cursor = response.get("next_cursor") for channel in response["conversations"]: diff --git a/toolkits/slack/pyproject.toml b/toolkits/slack/pyproject.toml index ee624f25..db718dc5 100644 --- a/toolkits/slack/pyproject.toml +++ b/toolkits/slack/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "arcade_slack" -version = "0.4.1" +version = "0.4.2" description = "Slack tools for LLMs" authors = ["Arcade "] diff --git a/toolkits/slack/tests/test_chat.py b/toolkits/slack/tests/test_chat.py index afb0a53f..d8d2c5e2 100644 --- a/toolkits/slack/tests/test_chat.py +++ b/toolkits/slack/tests/test_chat.py @@ -322,7 +322,14 @@ async def test_get_conversation_metadata_by_name( response = await get_channel_metadata_by_name(mock_context, sample_conversation["name"]) assert response == sample_conversation - mock_list_conversations_metadata.assert_called_once_with(mock_context, next_cursor=None) + mock_list_conversations_metadata.assert_called_once_with( + context=mock_context, + conversation_types=[ + ConversationType.PUBLIC_CHANNEL, + ConversationType.PRIVATE_CHANNEL, + ], + next_cursor=None, + ) @pytest.mark.asyncio @@ -349,8 +356,16 @@ async def test_get_channel_metadata_by_name_triggering_pagination( assert response == target_channel assert mock_list_conversations_metadata.call_count == 2 mock_list_conversations_metadata.assert_has_calls([ - call(mock_context, next_cursor=None), - call(mock_context, next_cursor="123"), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor=None, + ), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor="123", + ), ]) @@ -378,8 +393,16 @@ async def test_get_channel_metadata_by_name_not_found( assert mock_list_conversations_metadata.call_count == 2 mock_list_conversations_metadata.assert_has_calls([ - call(mock_context, next_cursor=None), - call(mock_context, next_cursor="123"), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor=None, + ), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor="123", + ), ]) @@ -479,7 +502,14 @@ async def test_get_members_in_channel_by_name( ) assert response == mock_get_members_in_conversation_by_id.return_value - mock_list_conversations_metadata.assert_called_once_with(mock_context, next_cursor=None) + mock_list_conversations_metadata.assert_called_once_with( + context=mock_context, + conversation_types=[ + ConversationType.PUBLIC_CHANNEL, + ConversationType.PRIVATE_CHANNEL, + ], + next_cursor=None, + ) mock_get_members_in_conversation_by_id.assert_called_once_with( context=mock_context, conversation_id="C12345", @@ -517,8 +547,16 @@ async def test_get_members_in_channel_by_name_triggering_pagination( assert response == mock_get_members_in_conversation_by_id.return_value mock_list_conversations_metadata.assert_has_calls([ - call(mock_context, next_cursor=None), - call(mock_context, next_cursor="123"), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor=None, + ), + call( + context=mock_context, + conversation_types=[ConversationType.PUBLIC_CHANNEL, ConversationType.PRIVATE_CHANNEL], + next_cursor="123", + ), ]) mock_get_members_in_conversation_by_id.assert_called_once_with( context=mock_context,