Browse Source

feat(slack): add `/sentry support` and `/sentry docs` commands (#73963)

Cathy Teng 8 months ago
parent
commit
8f155aa109

+ 39 - 0
fixtures/slack.py

@@ -161,3 +161,42 @@ HELP_COMMAND = {
         },
     ]
 }
+
+SUPPORT_COMMAND = {
+    "blocks": [
+        {
+            "type": "section",
+            "text": {
+                "type": "mrkdwn",
+                "text": "Need support? Check out these resources:",
+            },
+        },
+        {
+            "type": "section",
+            "text": {
+                "type": "mrkdwn",
+                "text": "• Want help for your particular case? <https://docs.sentry.io/support|File a ticket in Zendesk>. \n• Want to report an issue, request a feature, or get support? <https://github.com/getsentry/sentry/issues/new/choose|File a GitHub issue>. \n• Have feedback? Email ecosystem-feedback@sentry.io.",
+            },
+        },
+    ]
+}
+
+
+DOCS_COMMAND = {
+    "blocks": [
+        {
+            "type": "section",
+            "text": {
+                "type": "mrkdwn",
+                "text": "Want to view documentation? Check out these resources:",
+            },
+        },
+        {
+            "type": "section",
+            "text": {
+                "type": "mrkdwn",
+                "text": "• <https://docs.sentry.io/organization/integrations/|General Sentry integration docs> \n• <https://docs.sentry.io/organization/integrations/notification-incidents/slack/|Sentry Slack integration docs> \n• <https://sentry.slack.com/apps/A011MFBJEUU-sentry|Sentry Slack app>",
+            },
+        },
+    ]
+}

+ 0 - 1
src/sentry/integrations/slack/__init__.py

@@ -10,7 +10,6 @@ from .message_builder.base.base import *  # noqa: F401,F403
 from .message_builder.base.block import *  # noqa: F401,F403
 from .message_builder.disconnected import *  # noqa: F401,F403
 from .message_builder.discover import *  # noqa: F401,F403
-from .message_builder.event import *  # noqa: F401,F403
 from .message_builder.help import *  # noqa: F401,F403
 from .message_builder.incidents import *  # noqa: F401,F403
 from .message_builder.issues import *  # noqa: F401,F403

+ 14 - 7
src/sentry/integrations/slack/message_builder/disconnected.py

@@ -1,17 +1,24 @@
-from sentry.integrations.slack.message_builder import SlackBody
-from sentry.integrations.slack.message_builder.help import SlackHelpMessageBuilder
+from sentry.integrations.slack.message_builder import SlackBlock
+from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
 
 DISCONNECTED_MESSAGE = (
     "Slack has been uninstalled from your Sentry organization, re-install it to continue."
 )
 
 
-class SlackDisconnectedMessageBuilder(SlackHelpMessageBuilder):
-    def __init__(self) -> None:
-        """Override parent constructor."""
-        super().__init__()
+class SlackDisconnectedMessageBuilder(BlockSlackMessageBuilder):
+    def get_docs_block(self) -> SlackBlock:
+        return self.get_action_block(
+            [
+                (
+                    "Sentry Docs",
+                    "https://docs.sentry.io/product/alerts-notifications/alerts/",
+                    "sentry_docs_link_clicked",
+                )
+            ]
+        )
 
-    def build(self) -> SlackBody:
+    def build(self) -> SlackBlock:
         return self._build_blocks(
             self.get_markdown_block(DISCONNECTED_MESSAGE),
             self.get_docs_block(),

+ 0 - 19
src/sentry/integrations/slack/message_builder/event.py

@@ -1,19 +0,0 @@
-from collections.abc import Sequence
-
-from sentry.integrations.slack.message_builder import SlackBlock
-from sentry.integrations.slack.message_builder.help import SlackHelpMessageBuilder
-
-from ..utils import logger
-from .help import UNKNOWN_COMMAND_MESSAGE
-
-
-class SlackEventMessageBuilder(SlackHelpMessageBuilder):
-    def get_header_blocks(self) -> Sequence[SlackBlock]:
-        blocks = []
-        if self.command and self.command != "help":
-            logger.info("slack.event.unknown-command", extra={"command": self.command})
-            blocks.append(
-                self.get_markdown_block(UNKNOWN_COMMAND_MESSAGE.format(command=self.command))
-            )
-
-        return blocks

+ 29 - 13
src/sentry/integrations/slack/message_builder/help.py

@@ -1,6 +1,6 @@
 from collections.abc import Mapping, Sequence
 
-from sentry.integrations.slack.message_builder import SlackBlock, SlackBody
+from sentry.integrations.slack.message_builder import SlackBlock
 from sentry.integrations.slack.message_builder.base.block import BlockSlackMessageBuilder
 
 from ..utils import logger
@@ -24,6 +24,13 @@ CHANNEL_COMMANDS = {
 CONTACT_MESSAGE = "Let us know if you have feedback: ecosystem-feedback@sentry.io"
 
 
+SUPPORT_HEADER_MESSAGE = "Need support? Check out these resources:"
+SUPPORT_OPTIONS_MESSAGE = "• Want help for your particular case? <https://docs.sentry.io/support|File a ticket in Zendesk>. \n• Want to report an issue, request a feature, or get support? <https://github.com/getsentry/sentry/issues/new/choose|File a GitHub issue>. \n• Have feedback? Email feedback-ecosystem@sentry.io."
+
+DOCS_HEADER_MESSAGE = "Want to view documentation? Check out these resources:"
+DOCS_OPTIONS_MESSAGE = "• <https://docs.sentry.io/organization/integrations/|General Sentry integration docs> \n• <https://docs.sentry.io/organization/integrations/notification-incidents/slack/|Sentry Slack integration docs> \n• <https://sentry.slack.com/apps/A011MFBJEUU-sentry|Sentry Slack app>"
+
+
 def list_commands(commands: Mapping[str, str]) -> str:
     return "\n".join(
         (
@@ -42,17 +49,6 @@ class SlackHelpMessageBuilder(BlockSlackMessageBuilder):
         super().__init__()
         self.command = command
 
-    def get_docs_block(self) -> SlackBlock:
-        return self.get_action_block(
-            [
-                (
-                    "Sentry Docs",
-                    "https://docs.sentry.io/product/alerts-notifications/alerts/",
-                    "sentry_docs_link_clicked",
-                )
-            ]
-        )
-
     def get_header_blocks(self) -> Sequence[SlackBlock]:
         blocks = []
         if self.command and self.command != "help":
@@ -64,7 +60,7 @@ class SlackHelpMessageBuilder(BlockSlackMessageBuilder):
         blocks.append(self.get_markdown_block(HEADER_MESSAGE))
         return blocks
 
-    def build(self) -> SlackBody:
+    def get_help_message(self) -> SlackBlock:
         return self._build_blocks(
             *self.get_header_blocks(),
             self.get_markdown_block(DM_COMMAND_HEADER),
@@ -76,3 +72,23 @@ class SlackHelpMessageBuilder(BlockSlackMessageBuilder):
             self.get_divider(),
             self.get_markdown_block(GENERAL_MESSAGE),
         )
+
+    def get_support_message(self) -> SlackBlock:
+        return self._build_blocks(
+            self.get_markdown_block(SUPPORT_HEADER_MESSAGE),
+            self.get_markdown_block(SUPPORT_OPTIONS_MESSAGE),
+        )
+
+    def get_docs_message(self) -> SlackBlock:
+        return self._build_blocks(
+            self.get_markdown_block(DOCS_HEADER_MESSAGE),
+            self.get_markdown_block(DOCS_OPTIONS_MESSAGE),
+        )
+
+    def build(self) -> SlackBlock:
+        if self.command == "support":
+            return self.get_support_message()
+        elif self.command == "docs":
+            return self.get_docs_message()
+        else:
+            return self.get_help_message()

+ 2 - 2
src/sentry/integrations/slack/webhooks/base.py

@@ -46,8 +46,8 @@ class SlackDMEndpoint(Endpoint, abc.ABC):
         """
         command, args = request.get_command_and_args()
 
-        if command in ["help", ""]:
-            return self.respond(SlackHelpMessageBuilder().build())
+        if command in ["help", "", "support", "docs"]:
+            return self.respond(SlackHelpMessageBuilder(command=command).build())
 
         if command == "link":
             if not args:

+ 40 - 4
tests/sentry/integrations/slack/webhooks/commands/test_help.py

@@ -1,6 +1,12 @@
 import responses
 
-from fixtures.slack import HELP_COMMAND, INVALID_COMMAND, MISSING_COMMAND
+from fixtures.slack import (
+    DOCS_COMMAND,
+    HELP_COMMAND,
+    INVALID_COMMAND,
+    MISSING_COMMAND,
+    SUPPORT_COMMAND,
+)
 from sentry.integrations.slack.message_builder import SlackBody
 from sentry.silo.base import SiloMode
 from sentry.testutils.helpers import get_response_text
@@ -9,11 +15,19 @@ from sentry.types.region import Region, RegionCategory
 from tests.sentry.integrations.slack.webhooks.commands import SlackCommandsTest
 
 
-def assert_is_help_text(data: SlackBody, expected_command: str | None = None) -> None:
+def assert_is_help_text(data: SlackBody) -> None:
     text = get_response_text(data)
     assert "Here are the commands you can use" in text
-    if expected_command:
-        assert expected_command in text
+
+
+def assert_is_support_text(data: SlackBody) -> None:
+    text = get_response_text(data)
+    assert "Need support? Check out these resources:" in text
+
+
+def assert_is_docs_text(data: SlackBody) -> None:
+    text = get_response_text(data)
+    assert "Want to view documentation? Check out these resources:" in text
 
 
 def assert_unknown_command_text(data: SlackBody, unknown_command: str | None = None) -> None:
@@ -56,3 +70,25 @@ class SlackCommandsHelpTest(SlackCommandsTest):
             )
         data = self.send_slack_message("help")
         assert_is_help_text(data)
+
+    @responses.activate
+    def test_support_command(self):
+        if SiloMode.get_current_mode() == SiloMode.CONTROL:
+            responses.add(
+                method=responses.POST,
+                url="http://us.testserver/extensions/slack/commands/",
+                json=SUPPORT_COMMAND,
+            )
+        data = self.send_slack_message("support")
+        assert_is_support_text(data)
+
+    @responses.activate
+    def test_docs_command(self):
+        if SiloMode.get_current_mode() == SiloMode.CONTROL:
+            responses.add(
+                method=responses.POST,
+                url="http://us.testserver/extensions/slack/commands/",
+                json=DOCS_COMMAND,
+            )
+        data = self.send_slack_message("docs")
+        assert_is_docs_text(data)