We provide a utility function to parse webhooks received from ContentMod and make them Type safe.

To parse a webhook, you can use the parseWebhook function.

index.ts
import { ContentMod, WebhookEvent } from "@contentmod/sdk";

const body = req.body; // JSON body of the POST request.

const contentMod = new ContentMod({
  publicKey: "<YOUR_PUBLIC_KEY>",
  secretKey: "<YOUR_SECRET_KEY>",
});

const webhook = contentMod.parseWebhook(body);

switch (webhook.event) {
  case WebhookEvent.ModerationCompleted:
    console.log("moderation.completed", webhook);
    break;
  case WebhookEvent.QueueReviewCompleted:
    console.log("queue.review.completed", webhook.data.status);
    break;
}

console.log(webhook);