Telegram alerts for failed Stripe payments

By General Input

Get an instant Telegram ping the moment a Stripe charge or invoice payment fails, so revenue issues never sit unseen in an email inbox.

Integrations

  • Stripe
  • Telegram

Type

Deterministic Code

Categories

  • Finance
  • Operations

Build me a code workflow that sends an instant Telegram alert every time a Stripe payment fails, so I notice revenue problems in real time instead of finding them in an email digest the next morning.

Trigger: a Stripe webhook. Register the workflow as a Stripe webhook endpoint and subscribe to two event types: charge.failed (covers one-off payments and direct charges) and invoice.payment_failed (covers subscription renewals). Both event types should route into the same workflow and produce the same alert format. Verify the Stripe-Signature header on incoming requests so we ignore anything that isn't really from Stripe.

Extract these fields from the event payload, handling both event shapes:

- Customer email (from charge.billing_details.email, charge.receipt_email, or the customer record on the invoice, whichever is present) - Amount and currency (amount in the smallest currency unit, formatted back to a human-readable string like "$49.00 USD") - Failure reason: prefer failure_message, fall back to failure_code, then outcome.seller_message. For invoice.payment_failed, use the latest charge's failure_message or attempt_count + next_payment_attempt context. - Customer name or Stripe customer id, whichever is available - A direct deeplink to the charge or invoice in the Stripe dashboard (https://dashboard.stripe.com/payments/{charge_id} for charges, https://dashboard.stripe.com/invoices/{invoice_id} for invoices). Use the test-mode subdomain if livemode is false.

Format the alert as a short, scannable Telegram message using this template:

🚨 Stripe payment failed Customer: {name or email} Amount: {formatted_amount} {currency} Reason: {failure_reason} Type: {one-off charge | subscription renewal} → Open in Stripe: {dashboard_url}

Send the message via Telegram's Send Message operation. Default the destination to "me" so it lands in the operator's own Saved Messages, but expose the peer as a single configurable input so it can be retargeted to any chat, group, or channel without editing code. Use plain text formatting (not HTML or Markdown parse modes) so the template is robust against customer names containing special characters.

Respond to the webhook with HTTP 200 immediately after the Telegram send succeeds. If the Telegram send fails (FloodWaitError or network error), log it but still return 200 so Stripe doesn't retry the webhook and double-alert. This is a deterministic pipeline with no agent reasoning: webhook in, template render, message out.

Related prompts

Explore more prompts
Let support send one-off Loops emails without an engineerCustomer lifecycle inspector for Loops, Stripe and PostHogMonth-end Stripe finance pack, stored and shared in SlackRank your Intercom queue by what each customer pays youCatch the trials quietly dying before the card gets chargedWork every open Stripe dispute from one chargeback war roomLook up any customer's support, billing and CRM in one pageInvestor update studio that builds your board deck monthlySell and invoice Ghost newsletter sponsor slots in one boardSupport console that pairs Gladly chats with orders and refunds