agentleFS
agentsdanceagentsdance/agentskills/skills/webhook-handler/SKILL.md

webhook-handler

Skill3 starsChanged 11 months agoApache-2.0View on GitHub

Implement webhook receivers and handlers. Use when the user needs to receive webhooks from external services, validate signatures, or process webhook events.

  • Reads credentials

2 other projects use a version of this.

Adopted by

Most recently taken up by

The file

Files
SKILL.md

Webhook Handler

Receive and process webhooks from external services.

Webhook Architecture

External Service → Your Server → Process Event → Respond 2xx
                       ↓
              Signature Validation
                       ↓
                 Event Routing
                       ↓
               Background Processing

Express Webhook Handler

import express from 'express';
import crypto from 'crypto';

const app = express();

// Raw body needed for signature verification
app.post('/webhooks/stripe',
  express.raw({ type: 'application/json' }),
  async (req, res) => {
    const signature = req.headers['stripe-signature'];

    try {
      const event = verifyStripeSignature(req.body, signature);
      await processEvent(event);
      res.status(200).json({ received: true });
    } catch (error) {
      console.error('Webhook error:', error);
      res.status(400).json({ error: error.message });
    }
  }
);

Signature Verification

Stripe

import Stripe from 'stripe';
const stripe = new Stripe(process.env.STRIPE_SECRET_KEY);

function verifyStripeSignature(payload, signature) {
  return stripe.webhooks.constructEvent(
    payload,
    signature,
    process.env.STRIPE_WEBHOOK_SECRET
  );
}

GitHub

function verifyGitHubSignature(payload, signature) {
  const hmac = crypto.createHmac('sha256', process.env.GITHUB_WEBHOOK_SECRET);
  const digest = 'sha256=' + hmac.update(payload).digest('hex');
  return crypto.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(digest)
  );
}

Event Processing

const handlers = {
  'payment_intent.succeeded': handlePaymentSuccess,
  'customer.subscription.created': handleNewSubscription,
  'customer.subscription.deleted': handleCancellation,
};

async function processEvent(event) {
  const handler = handlers[event.type];
  if (handler) {
    await handler(event.data.object);
  }
}

Best Practices

PracticeDescription
Respond quicklyReturn 2xx before processing
IdempotencyHandle duplicate events
Retry handlingEvents may be sent multiple times
LoggingLog all webhook events
Queue processingUse background jobs

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.