Skip to content
CloudOps
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.
Newsletter

Free: the DevOps AI Incident-Triage Cheat Sheet

Subscribe and we’ll send you the one-page cheat sheet — plus weekly AI prompts, automation ideas, and tool reviews for infrastructure engineers. One email a week. No spam, unsubscribe anytime.

  • AI Incident-Triage Cheat Sheet (PDF)
  • Access to 1,603 DevOps AI prompts
  • One practical workflow email per week