Skip to content

Commit

Permalink
feat(webhook): add event picker
Browse files Browse the repository at this point in the history
  • Loading branch information
mogery committed Jan 30, 2025
1 parent 7c0b3ad commit a6722d4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions apps/api/src/controllers/v1/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
Expand Down
7 changes: 7 additions & 0 deletions apps/api/src/services/webhook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}}",
Expand Down
1 change: 1 addition & 0 deletions apps/js-sdk/firecrawl/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a6722d4

Please sign in to comment.