Files
calendar/packages/features/tasker/tasks/sendWebook.ts
T
Syed Ali ShahbazandGitHub 8b7497b8cd chore: Return webhook version in the header (#26139)
* init

* add tests

* fix type

* type fix

* fix

* fix tests

* fix test
2025-12-27 00:31:20 +00:00

31 lines
914 B
TypeScript

import { z } from "zod";
import { WebhookVersion } from "@calcom/features/webhooks/lib/interface/IWebhookRepository";
import sendPayload from "@calcom/features/webhooks/lib/sendPayload";
const sendWebhookPayloadSchema = z.object({
secretKey: z.string().nullable(),
triggerEvent: z.string(),
createdAt: z.string(),
webhook: z.object({
subscriberUrl: z.string().url(),
appId: z.string().nullable(),
payloadTemplate: z.string().nullable(),
version: z.nativeEnum(WebhookVersion),
}),
// TODO: Define the data schema
data: z.any(),
});
export async function sendWebhook(payload: string): Promise<void> {
try {
const { secretKey, triggerEvent, createdAt, webhook, data } = sendWebhookPayloadSchema.parse(
JSON.parse(payload)
);
await sendPayload(secretKey, triggerEvent, createdAt, webhook, data);
} catch (error) {
console.error(error);
throw error;
}
}