Fix Slack bug when sending msg to a private channel (#313)
This commit is contained in:
parent
ab735eb442
commit
81b2624c1a
3 changed files with 4 additions and 24 deletions
|
|
@ -25,7 +25,6 @@ from arcade_slack.utils import (
|
||||||
convert_relative_datetime_to_unix_timestamp,
|
convert_relative_datetime_to_unix_timestamp,
|
||||||
enrich_message_datetime,
|
enrich_message_datetime,
|
||||||
extract_conversation_metadata,
|
extract_conversation_metadata,
|
||||||
format_conversations_as_csv,
|
|
||||||
format_users,
|
format_users,
|
||||||
get_user_by_username,
|
get_user_by_username,
|
||||||
retrieve_conversations_by_user_ids,
|
retrieve_conversations_by_user_ids,
|
||||||
|
|
@ -120,28 +119,9 @@ async def send_message_to_channel(
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
# Step 1: Retrieve the list of channels
|
channel = await get_channel_metadata_by_name(context=context, channel_name=channel_name)
|
||||||
channels_response = await slackClient.conversations_list()
|
channel_id = channel["id"]
|
||||||
channel_id = None
|
|
||||||
for channel in channels_response["channels"]:
|
|
||||||
response_channel_name = (
|
|
||||||
"" if not isinstance(channel.get("name"), str) else channel["name"].lower()
|
|
||||||
)
|
|
||||||
if response_channel_name == channel_name.lower():
|
|
||||||
channel_id = channel["id"]
|
|
||||||
break
|
|
||||||
|
|
||||||
if not channel_id:
|
|
||||||
raise RetryableToolError(
|
|
||||||
"Channel not found",
|
|
||||||
developer_message=f"Channel with name '{channel_name}' not found.",
|
|
||||||
additional_prompt_content=format_conversations_as_csv({
|
|
||||||
"channels": channels_response["channels"],
|
|
||||||
}),
|
|
||||||
retry_after_ms=500, # Play nice with Slack API rate limits
|
|
||||||
)
|
|
||||||
|
|
||||||
# Step 2: Send the message to the channel
|
|
||||||
response = await slackClient.chat_postMessage(channel=channel_id, text=message)
|
response = await slackClient.chat_postMessage(channel=channel_id, text=message)
|
||||||
|
|
||||||
except SlackApiError as e:
|
except SlackApiError as e:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "arcade_slack"
|
name = "arcade_slack"
|
||||||
version = "0.4.0"
|
version = "0.4.1"
|
||||||
description = "Slack tools for LLMs"
|
description = "Slack tools for LLMs"
|
||||||
authors = ["Arcade <dev@arcade.dev>"]
|
authors = ["Arcade <dev@arcade.dev>"]
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,7 +82,7 @@ async def test_send_dm_to_inexistent_user(mock_context, mock_chat_slack_client):
|
||||||
async def test_send_message_to_channel(mock_context, mock_chat_slack_client):
|
async def test_send_message_to_channel(mock_context, mock_chat_slack_client):
|
||||||
mock_chat_slack_client.conversations_list.return_value = {
|
mock_chat_slack_client.conversations_list.return_value = {
|
||||||
"ok": True,
|
"ok": True,
|
||||||
"channels": [{"id": "C12345", "name": "general"}],
|
"channels": [{"id": "C12345", "name": "general", "is_member": True, "is_group": True}],
|
||||||
}
|
}
|
||||||
mock_slack_response = Mock(spec=AsyncSlackResponse)
|
mock_slack_response = Mock(spec=AsyncSlackResponse)
|
||||||
mock_slack_response.data = {"ok": True}
|
mock_slack_response.data = {"ok": True}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue