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
-
Python CSV Data-Quality Validator Prompt
Build a Python CLI that validates and cleans CSV/tabular data against declarative quality rules — types, ranges, required fields, uniqueness, referential checks — and emits a structured report of every violation
-
Python Environment Config Drift Detector Prompt
Build a Python tool that compares configuration or environment-variable sets across environments (dev/staging/prod) and reports missing, extra, and mismatched keys while masking secret values
-
Python Multi-Log Merge and Timeline Correlator Prompt
Build a Python tool that merges several log files with different timestamp formats into one time-ordered timeline, tags each line with its source, and correlates events across services for incident analysis
-
Python Prometheus Pushgateway Batch-Job Metrics Reporter Prompt
Build a Python module that reports batch-job and cron metrics (success, duration, records processed, last-success timestamp) to a Prometheus Pushgateway with correct grouping keys and failure-safe pushing
More Bash & Python Automation prompts & error guides
Browse every Bash & Python Automation prompt and troubleshooting guide in one place.
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.