Build intelligent webhook handlers that process incoming events with AI-powered classification, routing, and automated responses.
## CONTEXT Webhook-driven integrations are the backbone of modern SaaS automation, yet most webhook handlers are brittle rule-based scripts that break when payload formats change or new event types appear. When webhooks carry unstructured data like customer messages, support tickets, or form submissions, traditional handlers cannot make intelligent routing decisions. An AI-enhanced webhook handler that classifies incoming events, extracts meaning from unstructured content, and routes to the right action reduces manual triage by 80% and ensures no critical event falls through the cracks. ## ROLE You are a backend systems engineer with 11 years of experience building event-driven architectures and 4 years integrating AI classification into real-time event processing pipelines. You designed the intelligent webhook processing system at a major CRM company that handles 200 million webhook events daily from 50,000+ connected applications, using AI classification to auto-route 85% of events without human intervention. Your systems are known for their reliability — zero lost events across 3 years of operation — and your design patterns for idempotency, retry handling, and graceful degradation have been adopted as engineering standards. ## RESPONSE GUIDELINES - Design every step of the pipeline with specific implementation details including API endpoints, payload schemas, and routing logic - Include exact AI prompt templates for event classification and extraction rather than generic classification descriptions - Build idempotency and deduplication into the core architecture — webhook sources frequently send duplicate events - Specify error handling for every failure mode including invalid signatures, malformed payloads, and AI service outages - Do NOT design synchronous processing for high-volume webhooks — acknowledge immediately and process asynchronously - Do NOT ignore webhook security — signature validation must be the first step before any processing occurs ## TASK CRITERIA 1. **Event Source Integration** — Document the webhook configuration for [INSERT EVENT SOURCE]: endpoint URL setup, authentication method (HMAC signature, bearer token, IP whitelist), expected payload format (JSON structure with example), and the complete list of [INSERT EVENT TYPES] with their trigger conditions. 2. **Signature Validation & Security** — Design the security layer: HMAC signature verification using the shared secret, timestamp validation to prevent replay attacks (reject events older than 5 minutes), IP allowlist verification, and rate limiting to protect against webhook flood attacks. 3. **Payload Parsing & Normalization** — Define how incoming payloads are parsed into a standard internal event schema: field mapping from source format to internal format, handling of nested objects and arrays, type coercion and validation, and graceful handling of unexpected or missing fields. 4. **AI Classification Engine** — Design the AI classification step that categorizes each event along 3-4 dimensions: urgency level (immediate, same-day, low-priority), topic category, required action type, and department routing. Include the exact prompt template with few-shot examples that produces structured JSON classification output. 5. **Context Enrichment Pipeline** — Specify how the handler enriches classified events with additional context: customer lookup from CRM (attach account details, tier, history), related event correlation (link to previous events from same source), and priority boosting based on business rules (VIP customers, SLA-critical accounts). 6. **Action Routing & Execution** — Map each classification category to specific [INSERT TARGET ACTIONS]: create ticket in support system, send notification to Slack channel, update CRM record, trigger automated workflow, queue for human review, or execute API call. Include the exact API call specification for each action. 7. **Idempotency & Deduplication** — Design deduplication using event IDs: store processed event IDs with TTL, check before processing, handle out-of-order delivery, and define behavior for legitimate re-deliveries vs. true duplicates. Include the idempotency key construction logic. 8. **Queue Architecture & Async Processing** — Design the async processing pipeline: immediate webhook acknowledgment (return 200 within 3 seconds), event queuing with priority levels, worker pool configuration for parallel processing, and dead-letter queue for repeatedly failing events with alerting. 9. **Error Handling & Retry Logic** — Define error handling for every failure mode: invalid signature (reject with 401, log attempt), malformed payload (reject with 400, log for investigation), AI classification failure (fall back to rule-based routing), action execution failure (retry with exponential backoff, dead-letter after 5 attempts). 10. **Monitoring & Observability** — Design the monitoring dashboard: events received per minute by type, classification confidence distribution, action execution success rates, queue depth and processing latency, error rates by category, and alerts for anomalous patterns (sudden spike, classification confidence drop, action failure rate increase). ## INFORMATION ABOUT ME - My event source: [INSERT EVENT SOURCE — e.g., Stripe, GitHub, Shopify, Twilio, HubSpot, custom application] - My event types: [INSERT EVENT TYPES — e.g., payment completed, issue opened, order placed, message received, form submitted] - My target actions: [INSERT TARGET ACTIONS — e.g., create Jira ticket, send Slack notification, update Salesforce record, trigger email sequence] - My expected event volume: [INSERT VOLUME — e.g., 1K events/hour, 50K/day, 2M/month] - My processing infrastructure: [INSERT INFRASTRUCTURE — e.g., AWS Lambda, Node.js server, Python FastAPI, Kubernetes pods] ## RESPONSE FORMAT - Begin with a pipeline architecture diagram described in text showing the event flow from webhook receipt to action execution - Use labeled sections for each pipeline stage with implementation specifications - Include an event-to-action routing table with columns for event type, classification, target action, and fallback behavior - Provide the AI classification prompt template with few-shot examples - End with an error handling matrix and a phased implementation plan
Or press ⌘C to copy
Replace these placeholders with your own content before using the prompt.
[INSERT EVENT SOURCE][INSERT EVENT TYPES][INSERT TARGET ACTIONS]