|
7 | 7 | from django.core.exceptions import ValidationError |
8 | 8 | from slack_sdk.errors import SlackApiError |
9 | 9 |
|
10 | | -from sentry import features, options |
| 10 | +from sentry import features |
11 | 11 | from sentry.integrations.services.integration import RpcIntegration |
12 | 12 | from sentry.integrations.slack.client import SlackClient |
13 | 13 | from sentry.integrations.slack.sdk_client import SlackSdkClient |
@@ -96,36 +96,21 @@ def validate_channel_id(name: str, integration_id: int | None, input_channel_id: |
96 | 96 | In the case that the user is creating an alert via the API and providing the channel ID and name |
97 | 97 | themselves, we want to make sure both values are correct. |
98 | 98 | """ |
99 | | - # The empty string should be converted to None |
100 | | - payload = {"channel": input_channel_id or None} |
101 | | - |
102 | | - if options.get("slack-sdk.valid_channel_id") or integration_id in options.get( |
103 | | - "slack-sdk.valid_channel_id_la_integration_ids" |
104 | | - ): |
105 | | - client = SlackSdkClient(integration_id=integration_id) |
106 | | - try: |
107 | | - results = client.conversations_info(channel=input_channel_id).data |
108 | | - except SlackApiError as e: |
109 | | - if e.response["error"] == "channel_not_found": |
110 | | - raise ValidationError("Channel not found. Invalid ID provided.") from e |
111 | | - _logger.exception( |
112 | | - "rule.slack.conversation_info_failed", |
113 | | - extra={ |
114 | | - "integration_id": integration_id, |
115 | | - "channel_name": name, |
116 | | - "input_channel_id": input_channel_id, |
117 | | - }, |
118 | | - ) |
119 | | - raise IntegrationError("Could not retrieve Slack channel information.") from e |
120 | | - else: |
121 | | - client = SlackClient(integration_id=integration_id) |
122 | | - try: |
123 | | - results = client.get("/conversations.info", params=payload) |
124 | | - except ApiError as e: |
125 | | - if e.text == "channel_not_found": |
126 | | - raise ValidationError("Channel not found. Invalid ID provided.") from e |
127 | | - _logger.info("rule.slack.conversation_info_failed", extra={"error": str(e)}) |
128 | | - raise IntegrationError("Could not retrieve Slack channel information.") from e |
| 99 | + |
| 100 | + client = SlackSdkClient(integration_id=integration_id) |
| 101 | + try: |
| 102 | + results = client.conversations_info(channel=input_channel_id).data |
| 103 | + except SlackApiError as e: |
| 104 | + if "channel_not_found" in str(e): |
| 105 | + raise ValidationError("Channel not found. Invalid ID provided.") from e |
| 106 | + _logger.exception( |
| 107 | + "rule.slack.conversation_info_failed", |
| 108 | + extra={ |
| 109 | + "integration_id": integration_id, |
| 110 | + "channel_name": name, |
| 111 | + "input_channel_id": input_channel_id, |
| 112 | + }, |
| 113 | + ) |
129 | 114 |
|
130 | 115 | if not isinstance(results, dict): |
131 | 116 | raise IntegrationError("Bad slack channel list response.") |
|
0 commit comments