Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
26 changes: 17 additions & 9 deletions Packs/Slack/Integrations/SlackV3/SlackV3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3491,7 +3491,11 @@ def resolve_conversation_id_from_name(channel_name):
channel_id = conversation_info.get("id")

if not channel_id:
raise DemistoException(f"Channel '{channel_name}' does not exist.")
raise CortexResourceNotFoundError(
resource_type="Slack channel",
identifier=channel_name,
override_message=f"Channel '{channel_name}' does not exist.",
)

return channel_id

Expand All @@ -3513,7 +3517,11 @@ def conversation_history() -> None:
thread_id = args.get("thread_id")

if not conversation_id and not conversation_name:
raise ValueError("Either conversation_id or conversation_name must be provided.")
raise CortexMissingArgError(
["conversation_id", "conversation_name"],
require_one=True,
override_message="Either conversation_id or conversation_name must be provided.",
)

if not conversation_id:
conversation_id = resolve_conversation_id_from_name(conversation_name)
Expand All @@ -3530,11 +3538,11 @@ def conversation_history() -> None:
if page_token:
body["cursor"] = page_token

raw_response = send_slack_request_sync(CLIENT, "conversations.history", http_verb="GET", body=body)

if not raw_response.get("ok"):
raise DemistoException(
f'An error occurred while listing conversation history: {raw_response.get("error")}', res=raw_response
try:
raw_response = send_slack_request_sync(CLIENT, "conversations.history", http_verb="GET", body=body)
except SlackApiError as e:
raise CortexExternalApiError(
override_message=f"An error occurred while listing conversation history: {e.response.get('error')}"
)
Comment thread
hyaffe839 marked this conversation as resolved.

messages: Any = raw_response.get("messages", [])
Expand All @@ -3545,8 +3553,8 @@ def conversation_history() -> None:
if isinstance(messages, dict):
messages = [messages]
if not isinstance(messages, list):
raise DemistoException(
f'An error occurred while listing conversation history: {raw_response.get("error")}', res=raw_response
raise CortexExternalApiError(
override_message=f"An error occurred while listing conversation history: {raw_response.get('error')}"
)

context: List[Dict[str, Any]] = []
Expand Down
9 changes: 5 additions & 4 deletions Packs/Slack/Integrations/SlackV3/SlackV3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from pytest_mock.plugin import MockerFixture
import slack_sdk
from CommonServerPython import *
from CommonServerPython import CortexMissingArgError, CortexResourceNotFoundError
from slack_sdk.errors import SlackApiError
from slack_sdk.web.async_slack_response import AsyncSlackResponse
from slack_sdk.web.slack_response import SlackResponse
Expand Down Expand Up @@ -5459,14 +5460,14 @@ def test_conversation_history_no_channel_provided_error(mocker):

Given: A conversation_history command is configured and no channel parameters are provided
When: The conversation_history command is called with args missing both conversation_id and conversation_name
Then: The command raises ValueError with appropriate error message
Then: The command raises CortexMissingArgError with appropriate error message
"""

args = {"limit": "10"}

mocker.patch.object(demisto, "args", return_value=args)

with pytest.raises(ValueError, match="Either conversation_id or conversation_name must be provided."):
with pytest.raises(CortexMissingArgError, match="Either conversation_id or conversation_name must be provided."):
conversation_history()


Expand Down Expand Up @@ -5508,12 +5509,12 @@ def test_resolve_conversation_id_from_name_no_channel_found(mocker):

Given: The resolve_conversation_id_from_name function is called with a channel name that doesn't exist.
When: No private conversation or channel exists for the specified name and channel id is not provided.
Then: The function raises ValueError with appropriate error message indicating the channel was not found.
Then: The function raises CortexResourceNotFoundError with appropriate error message indicating the channel was not found.
"""
mocker.patch("SlackV3.get_direct_message_channel_id_by_username", return_value=None)
mocker.patch("SlackV3.get_conversation_by_name", return_value={})

with pytest.raises(DemistoException, match="Channel 'nonexistent' does not exist."):
with pytest.raises(CortexResourceNotFoundError, match="Channel 'nonexistent' does not exist."):
resolve_conversation_id_from_name("nonexistent")


Expand Down
9 changes: 9 additions & 0 deletions Packs/Slack/ReleaseNotes/3_8_18.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

#### Integrations

##### Slack v3

- Documentation and metadata improvements.
<!--
- Improved implementation by migrating error messages across the ***slack-get-conversation-history*** command to the CortexError format to provide structured, machine-readable error metadata for Agentix callers.
-->
2 changes: 1 addition & 1 deletion Packs/Slack/pack_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "Slack",
"description": "Interact with Slack API - collect logs, send messages and notifications to your Slack team.",
"support": "xsoar",
"currentVersion": "3.8.17",
"currentVersion": "3.8.18",
"author": "Cortex XSOAR",
"url": "https://www.paloaltonetworks.com/cortex",
"email": "",
Expand Down
Loading