feat(webhook): add event picker

This commit is contained in:
Gergő Móricz 2025-01-30 18:43:37 +01:00
parent 7c0b3ad098
commit a6722d4a95
3 changed files with 9 additions and 0 deletions

View File

@ -317,6 +317,7 @@ export const webhookSchema = z.preprocess(
url: z.string().url(),
headers: z.record(z.string(), z.string()).default({}),
metadata: z.record(z.string(), z.string()).default({}),
events: z.array(z.enum(["completed", "failed", "page", "started"])).default(["completed", "failed", "page", "started"]),
})
.strict(strictMessage),
);

View File

@ -16,6 +16,13 @@ export const callWebhook = async (
eventType: WebhookEventType = "crawl.page",
awaitWebhook: boolean = false,
) => {
if (specified) {
let subType = eventType.split(".")[1];
if (!specified.events.includes(subType as any)) {
return false;
}
}
try {
const selfHostedUrl = process.env.SELF_HOSTED_WEBHOOK_URL?.replace(
"{{JOB_ID}}",

View File

@ -168,6 +168,7 @@ export interface CrawlParams {
url: string;
headers?: Record<string, string>;
metadata?: Record<string, string>;
events?: ["completed", "failed", "page", "started"][number][];
};
deduplicateSimilarURLs?: boolean;
ignoreQueryParameters?: boolean;