Skip to content

Commit edadfa8

Browse files
authored
feat(slack): Debug function to generate slack block kit preview URLs (#69471)
Make it easier to generate Slack block kit preview URLs for debugging/development: <img width="1920" alt="Screenshot 2024-04-22 at 7 26 23 PM" src="https://github.com/getsentry/sentry/assets/139499/9f749310-16f3-4adc-bfc2-8ef8501d0d5c"> This was inspired by: https://github.com/raycharius/slack-block-builder/blob/fac1baf4054ebfa5241d6065db54858f1522fe7d/src/internal/methods/other-methods.ts#L68-L83 For example: https://app.slack.com/block-kit-builder/T024ZCV9U#%7B%22blocks%22:%5B%7B%22type%22:%22section%22,%22text%22:%7B%22type%22:%22mrkdwn%22,%22text%22:%22*You've%20reached%2080%25%20of%20your%20performance%20unit%20quota%20limit*%20%20%5CnYour%20organization%20*baz*%20has%20consumed%2080%25%20of%20its%20%3Chttps://docs.sentry.io/product/performance/transaction-summary/%7Cperformance%20unit%3E%20capacity.%20We'll%20drop%20performance%20units%20when%20you%20exceed%20your%20quota.%22%7D%7D,%7B%22type%22:%22context%22,%22elements%22:%5B%7B%22type%22:%22mrkdwn%22,%22text%22:%22You%20are%20receiving%20this%20notification%20because%20you%20have%20the%20scope%20org:billing%20%7C%20%3Chttp://baz.testserver/settings/account/notifications/quota/?referrer=reserved_quota_threshold-slack-user&notification_uuid=fc0f0579-6133-400a-8c3b-7002c27749f7%7CNotification%20Settings%3E%22%7D%5D%7D,%7B%22type%22:%22actions%22,%22elements%22:%5B%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22Increase%20budget%22%7D,%22url%22:%22http://baz.testserver/settings/billing/checkout/?referrer=reserved_quota_threshold-slack-user&notification_uuid=fc0f0579-6133-400a-8c3b-7002c27749f7#step2%22,%22value%22:%22link_clicked%22%7D,%7B%22type%22:%22button%22,%22text%22:%7B%22type%22:%22plain_text%22,%22text%22:%22View%20Consumption%22%7D,%22url%22:%22http://baz.testserver/settings/billing/overview/?referrer=reserved_quota_threshold-slack-user&notification_uuid=fc0f0579-6133-400a-8c3b-7002c27749f7&category=transactions%22,%22value%22:%22link_clicked%22%7D%5D%7D%5D%7D
1 parent 78ed463 commit edadfa8

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/sentry/testutils/helpers/slack.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from urllib.parse import parse_qs
1+
from urllib.parse import parse_qs, quote
22

33
import responses
44

@@ -130,6 +130,23 @@ def get_blocks_and_fallback_text(index=0):
130130
return blocks, fallback_text
131131

132132

133+
def get_block_kit_preview_url(index=0) -> str:
134+
assert len(responses.calls) >= 1
135+
data = parse_qs(responses.calls[index].request.body)
136+
assert "blocks" in data
137+
assert data["blocks"][0]
138+
139+
stringified_blocks = data["blocks"][0]
140+
blocks = json.loads(data["blocks"][0])
141+
stringified_blocks = json.dumps({"blocks": blocks})
142+
143+
encoded_blocks = quote(stringified_blocks)
144+
base_url = "https://app.slack.com/block-kit-builder/#"
145+
146+
preview_url = f"{base_url}{encoded_blocks}"
147+
return preview_url
148+
149+
133150
def setup_slack_with_identities(organization, user):
134151
integration = install_slack(organization)
135152
idp = IdentityProvider.objects.create(type="slack", external_id="TXXXXXXX1", config={})

0 commit comments

Comments
 (0)