Skip to content

Slack: use json= to send a message using webhooks #11536

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 14, 2024
Merged
Changes from all 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
20 changes: 8 additions & 12 deletions readthedocs/subscriptions/event_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ def subscription_canceled(event):
except SSOIntegration.DoesNotExist:
sso_integration = "Read the Docs Auth"

# https://api.slack.com/surfaces/messages#payloads
slack_message = {
"blocks": [
{
Expand All @@ -241,19 +242,11 @@ def subscription_canceled(event):
"fields": [
{
"type": "mrkdwn",
"text": f":office: *Name:* {organization.name}",
"text": f":office: *Name:* <{settings.ADMIN_URL}/organizations/organization/{organization.pk}/change/|{organization.name}>",
},
{
"type": "mrkdwn",
"text": f":dollar: *Plan:* {stripe_subscription.plan.id}",
},
{
"type": "mrkdwn",
"text": f":hash: *Slug:* {organization.slug}",
},
{
"type": "mrkdwn",
"text": f":person_frowning: *Stripe customer:* <https://dashboard.stripe.com/customers/{stripe_subscription.customer_id}|{stripe_subscription.customer_id}>",
"text": f":dollar: *Plan:* <https://dashboard.stripe.com/customers/{stripe_subscription.customer_id}|{stripe_subscription.plan.product.name}> (${str(total_spent)})",
},
{
"type": "mrkdwn",
Expand Down Expand Up @@ -286,11 +279,14 @@ def subscription_canceled(event):
]
}
try:
requests.post(
response = requests.post(
settings.SLACK_WEBHOOK_SALES_CHANNEL,
data=slack_message,
json=slack_message,
timeout=3,
)
if not response.ok:
log.error("There was an issue when sending a message to Slack webhook")

except requests.Timeout:
log.warning("Timeout sending a message to Slack webhook")

Expand Down