Skip to content
🎉 Launch sale:50% off everything over $22 — automatically applied at checkout· ends Aug 2Shop the sale →
DevOps AI ToolKit
Newsletter
All prompts
AI for Bash & Python Automation Difficulty: Intermediate ClaudeChatGPT

Python Slack, Teams, and Webhook Notifier Module Prompt

Build a reusable Python notification module that sends messages to Slack, Teams, or generic webhooks with a unified interface, retries, rate limiting, and safe failure handling.

Target user
Engineers adding alerting/notifications to scripts and services
Difficulty
Intermediate
Tools
Claude, ChatGPT

The prompt

You are a senior Python engineer who builds notification plumbing that never crashes the job it is supposed to be reporting on.

I will provide:
- Which destinations I need (Slack, Microsoft Teams, generic webhook, email later)
- Where credentials/webhook URLs live (env, secret manager)
- Message types (info, success, warning, error) and any formatting needs

Build a small library that:

1. **Exposes a unified interface** — a `Notifier` abstraction with `send(message, level, *, title, fields, link)` so callers don't care about the backend. Concrete adapters: `SlackNotifier`, `TeamsNotifier`, `WebhookNotifier`. Allow fan-out to multiple destinations.

2. **Formats per platform** — Slack Block Kit / attachments with severity colors; Teams MessageCard/Adaptive Card; generic JSON payload for webhooks. Map the abstract `level` to the right color/emoji per platform.

3. **Loads config safely** — webhook URLs/tokens from env or a secret manager, never hardcoded. Validate they exist at construction with a clear error.

4. **Retries transient failures** — exponential backoff with jitter on 429/5xx/network errors; honor `Retry-After`; cap attempts. Do not retry 4xx (bad payload/auth).

5. **Never raises into the caller by default** — notification failure should log loudly and return a result object, not crash the automation. Offer a strict mode for when a notification is mission-critical.

6. **Respects rate limits** — simple throttle so a loop firing 1000 alerts doesn't get the workspace rate-limited; optionally coalesce/batch.

7. **Redacts secrets** — never log the webhook URL or token; mask in any debug output.

8. **Is testable** — inject the HTTP client; provide tests that assert payload shape per platform using a mock transport.

Output: (a) the base interface + adapters, (b) the retry/throttle helper, (c) config loading with validation, (d) `pytest` tests with mocked HTTP, (e) a usage example wiring it into a script's try/finally.

Bias toward: a clean abstract interface, swallow-by-default-but-log errors, redacted secrets, and platform-correct formatting.

Run this prompt with AI

Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.

Related prompts

More Bash & Python Automation prompts & error guides

Browse every Bash & Python Automation prompt and troubleshooting guide in one place.

Free download · 368-page PDF

Reading prompts? Get all 500 in one free PDF

500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.

  • 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
  • Instant PDF download — yours free, forever
  • Plus one practical AI-workflow email a week (no spam)

Single opt-in · unsubscribe anytime · no spam.