Index of every page on this site: llms.txt
All skills
masheev avatar

/masheev-webhooks

@21d3a39
by masheevmasheev/skills1 stars
Run it yourself

Use when setting up, verifying, or handling Masheev webhook events in your backend. Covers creating webhook subscriptions, HMAC-SHA256 signature verification with timingSafeEqual, raw body preservation before JSON parsing, idempotent event handling, retry logic, and all 11 event types (conversation.created, message.received, contact.updated, etc.). Use this skill whenever someone asks to "handle Masheev events", "set up webhooks", "verify webhook signatures", or wants real-time notifications from Masheev. Also use when debugging webhook delivery failures or missed events.

Use this Skill: https://skilld.dev/gh/masheev/skills/masheev-webhooks

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesframeworks.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Webhook Handlers by Framework

Express

import express from "express";
import crypto from "node:crypto";

const app = express();

// Raw body is required for signature verification
app.post(
  "/webhooks/masheev",
  express.raw({ type: "application/json" }),
  (req, res) => {
    const rawBody = req.body.toString();
    const signature = req.headers["x-webhook-signature"] as string;

    const expected = crypto
      .createHmac("sha256", process.env.MASHEEV_WEBHOOK_SECRET!)
      .update(rawBody)
      .digest("hex");

    if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
      return res.status(401).send("Invalid signature");
    }

    const event = JSON.parse(rawBody);
    console.log(`Received ${event.type}:`, event.payload);

    res.sendStatus(200);
  },
);

Hono

import { Hono } from "hono";
import crypto from "node:crypto";

const app = new Hono();

app.post("/webhooks/masheev", async (c) => {
  const rawBody = await c.req.text();
  const signature = c.req.header("x-webhook-signature");

  if (!signature) return c.text("Missing signature", 401);

  const expected = crypto
    .createHmac("sha256", process.env.MASHEEV_WEBHOOK_SECRET!)
    .update(rawBody)
    .digest("hex");

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return c.text("Invalid signature", 401);
  }

  const event = JSON.parse(rawBody);
  console.log(`Received ${event.type}:`, event.payload);

  return c.text("OK");
});

Next.js App Router

// app/api/webhooks/masheev/route.ts
import crypto from "node:crypto";

export async function POST(request: Request) {
  const rawBody = await request.text();
  const signature = request.headers.get("x-webhook-signature");

  if (!signature) {
    return new Response("Missing signature", { status: 401 });
  }

  const expected = crypto
    .createHmac("sha256", process.env.MASHEEV_WEBHOOK_SECRET!)
    .update(rawBody)
    .digest("hex");

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return new Response("Invalid signature", { status: 401 });
  }

  const event = JSON.parse(rawBody);
  console.log(`Received ${event.type}:`, event.payload);

  return new Response("OK", { status: 200 });
}

Next.js Pages Router

// pages/api/webhooks/masheev.ts
import type { NextApiRequest, NextApiResponse } from "next";
import crypto from "node:crypto";

// Disable body parsing to get raw body
export const config = { api: { bodyParser: false } };

function getRawBody(req: NextApiRequest): Promise<string> {
  return new Promise((resolve, reject) => {
    const chunks: Buffer[] = [];
    req.on("data", (chunk) => chunks.push(chunk));
    req.on("end", () => resolve(Buffer.concat(chunks).toString()));
    req.on("error", reject);
  });
}

export default async function handler(req: NextApiRequest, res: NextApiResponse) {
  if (req.method !== "POST") return res.status(405).end();

  const rawBody = await getRawBody(req);
  const signature = req.headers["x-webhook-signature"] as string;

  if (!signature) return res.status(401).send("Missing signature");

  const expected = crypto
    .createHmac("sha256", process.env.MASHEEV_WEBHOOK_SECRET!)
    .update(rawBody)
    .digest("hex");

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return res.status(401).send("Invalid signature");
  }

  const event = JSON.parse(rawBody);
  console.log(`Received ${event.type}:`, event.payload);

  res.status(200).send("OK");
}

Fastify

import Fastify from "fastify";
import crypto from "node:crypto";

const fastify = Fastify();

// Parse JSON as string to preserve raw body
fastify.addContentTypeParser(
  "application/json",
  { parseAs: "string" },
  (req, body, done) => done(null, body),
);

fastify.post("/webhooks/masheev", async (request, reply) => {
  const rawBody = request.body as string;
  const signature = request.headers["x-webhook-signature"] as string;

  if (!signature) return reply.code(401).send("Missing signature");

  const expected = crypto
    .createHmac("sha256", process.env.MASHEEV_WEBHOOK_SECRET!)
    .update(rawBody)
    .digest("hex");

  if (!crypto.timingSafeEqual(Buffer.from(signature), Buffer.from(expected))) {
    return reply.code(401).send("Invalid signature");
  }

  const event = JSON.parse(rawBody);
  console.log(`Received ${event.type}:`, event.payload);

  return reply.code(200).send("OK");
});

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

1 warning7mo3 checks · Risk SAFE
  • Gen Agent Trust Hub7mo

    The skill provides comprehensive and secure instructions for implementing and verifying Masheev webhooks. It correctly emphasizes security best practices, such as using timing-safe comparisons for HMAC signatures and preserving raw request bodies.

  • Socket7mo

    No alerts

  • Snyk7mo

    Risk: MEDIUM · 1 issue

Signed by skilld at 21d3a39. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated 7 months ago
metadata
{
  "author": "masheev",
  "version": "0.1.0"
}

README badge

README badge for masheev/skills/masheev-webhooks