Browse Source

feat(msteams): update installation flow (#20485)

Stephen Cefali 4 years ago
parent
commit
eb938293f7

+ 56 - 6
src/sentry/integrations/msteams/card_builder.py

@@ -7,6 +7,7 @@ from sentry.models import (
     GroupAssignee,
     Team,
 )
+from sentry.utils.assets import get_asset_url
 from sentry.utils.compat import map
 from sentry.utils.http import absolute_uri
 
@@ -51,10 +52,9 @@ def get_assignee_string(group):
 
 def build_welcome_card(signed_params):
     url = u"%s?signed_params=%s" % (absolute_uri("/extensions/msteams/configure/"), signed_params,)
-    # TODO: Refactor message creation
     logo = {
         "type": "Image",
-        "url": "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png",
+        "url": absolute_uri(get_asset_url("sentry", "images/sentry-glyph-black.png")),
         "size": "Medium",
     }
     welcome = {
@@ -66,12 +66,15 @@ def build_welcome_card(signed_params):
     }
     description = {
         "type": "TextBlock",
-        "text": "You can use the Sentry app for Microsoft Teams to get notifications that allow you to assign, ignore, or resolve directly in your chat.",
+        "text": "You can use Sentry for Microsoft Teams to get notifications that allow you to assign, ignore, or resolve directly in your chat.",
         "wrap": True,
     }
     instruction = {
         "type": "TextBlock",
-        "text": "If that sounds good to you, finish the setup process.",
+        "text": (
+            "Please click **Complete Setup** to finish the setup process."
+            " Don't have a Sentry account? [Sign Up](https://sentry.io/signup/)."
+        ),
         "wrap": True,
     }
     button = {
@@ -103,6 +106,53 @@ def build_welcome_card(signed_params):
     }
 
 
+def build_installation_confirmation_message(organization):
+    logo = {
+        "type": "Image",
+        "url": absolute_uri(get_asset_url("sentry", "images/sentry-glyph-black.png")),
+        "size": "Medium",
+    }
+    welcome = {
+        "type": "TextBlock",
+        "weight": "Bolder",
+        "size": "Large",
+        "text": u"Installation for {} is successful".format(organization.name),
+        "wrap": True,
+    }
+    alert_rule_instructions = {
+        "type": "TextBlock",
+        "text": "Now that setup is complete, you can continue by configuring alerts.",
+        "wrap": True,
+    }
+    alert_rule_url = absolute_uri("organizations/{}/rules/".format(organization.slug))
+    alert_rule_button = {
+        "type": "Action.OpenUrl",
+        "title": "Add Alert Rules",
+        "url": alert_rule_url,
+    }
+    return {
+        "type": "AdaptiveCard",
+        "body": [
+            {
+                "type": "ColumnSet",
+                "columns": [
+                    {"type": "Column", "items": [logo], "width": "auto"},
+                    {
+                        "type": "Column",
+                        "items": [welcome],
+                        "width": "stretch",
+                        "verticalContentAlignment": "Center",
+                    },
+                ],
+            },
+            alert_rule_instructions,
+        ],
+        "actions": [alert_rule_button],
+        "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
+        "version": "1.2",
+    }
+
+
 def build_group_title(group):
     # TODO: implement with event as well
     ev_metadata = group.get_event_metadata()
@@ -144,7 +194,7 @@ def build_group_footer(group, rules, project, event):
         "items": [
             {
                 "type": "Image",
-                "url": "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png",
+                "url": absolute_uri(get_asset_url("sentry", "images/sentry-glyph-black.png")),
                 "height": "20px",
             }
         ],
@@ -482,7 +532,7 @@ def build_linking_card(url):
 def build_linked_card():
     image = {
         "type": "Image",
-        "url": "https://sentry-brand.storage.googleapis.com/sentry-glyph-black.png",
+        "url": absolute_uri(get_asset_url("sentry", "images/sentry-glyph-black.png")),
         "size": "Large",
     }
     desc = {

+ 9 - 1
src/sentry/integrations/msteams/integration.py

@@ -14,7 +14,9 @@ from sentry.integrations import (
     FeatureDescription,
 )
 from sentry.pipeline import PipelineView
-from .client import get_token_data
+
+from .card_builder import build_installation_confirmation_message
+from .client import get_token_data, MsTeamsClient
 
 logger = logging.getLogger("sentry.integrations.msteams")
 
@@ -99,6 +101,12 @@ class MsTeamsIntegrationProvider(IntegrationProvider):
         }
         return integration
 
+    def post_install(self, integration, organization, extra=None):
+        client = MsTeamsClient(integration)
+        card = build_installation_confirmation_message(organization)
+        conversation_id = integration.external_id
+        client.send_card(conversation_id, card)
+
 
 class MsTeamsPipelineView(PipelineView):
     def dispatch(self, request, pipeline):

+ 1 - 1
src/sentry/integrations/slack/integration.py

@@ -215,7 +215,7 @@ class SlackIntegrationProvider(IntegrationProvider):
             return
 
     def post_install(self, integration, organization, extra=None):
-        # normal installtions don't have extra, quit immediately
+        # normal installations don't have extra, quit immediately
         if extra is None:
             return
 

BIN
src/sentry/static/sentry/images/sentry-glyph-black.png


+ 10 - 0
tests/sentry/integrations/msteams/test_integration.py

@@ -31,6 +31,12 @@ class MsTeamsIntegrationTest(IntegrationTestCase):
     def assert_setup_flow(self):
         responses.reset()
 
+        responses.add(
+            responses.POST,
+            u"https://smba.trafficmanager.net/amer/v3/conversations/%s/activities" % team_id,
+            json={},
+        )
+
         with patch("time.time") as mock_time:
             mock_time.return_value = self.start_time
             # token mock
@@ -72,6 +78,10 @@ class MsTeamsIntegrationTest(IntegrationTestCase):
                 integration=integration, organization=self.organization
             )
 
+            integration_url = "organizations/{}/rules/".format(self.organization.slug)
+            assert integration_url in responses.calls[1].request.body
+            assert self.organization.name in responses.calls[1].request.body
+
     @responses.activate
     def test_installation(self):
         self.assert_setup_flow()