A self-hostable bookmark-everything app (links, notes and images) with AI-based automatic tagging and full text search
feat: Add support for 'ai tagged' as a webhook trigger. Fixes #1092
Mohamed Bassem33293178db71
diff --git a/apps/workers/openaiWorker.ts b/apps/workers/openaiWorker.tsindex f8a775e6..64e36b82 100644--- a/apps/workers/openaiWorker.ts+++ b/apps/workers/openaiWorker.ts@@ -20,6 +20,7 @@ import { buildImagePrompt, buildTextPrompt } from "@hoarder/shared/prompts";import {OpenAIQueue,triggerSearchReindex,+ triggerWebhook,zOpenAIRequestSchema,} from "@hoarder/shared/queues";@@ -440,6 +441,9 @@ async function runOpenAI(job: DequeuedJob<ZOpenAIRequest>) {await connectTags(bookmarkId, tags, bookmark.userId);+ // Trigger a webhook+ await triggerWebhook(bookmarkId, "ai tagged");+// Update the search indexawait triggerSearchReindex(bookmarkId);}diff --git a/packages/db/schema.ts b/packages/db/schema.tsindex 111081b8..ae694fc8 100644--- a/packages/db/schema.ts+++ b/packages/db/schema.ts@@ -404,7 +404,7 @@ export const webhooksTable = sqliteTable(.references(() => users.id, { onDelete: "cascade" }),events: text("events", { mode: "json" }).notNull()- .$type<("created" | "edited" | "crawled")[]>(),+ .$type<("created" | "edited" | "crawled" | "ai tagged")[]>(),token: text("token"),},(bl) => [index("webhooks_userId_idx").on(bl.userId)],@@ -536,7 +536,6 @@ export const bookmarksInListsRelations = relations(}),);-export const webhooksRelations = relations(webhooksTable, ({ one }) => ({user: one(users, {fields: [webhooksTable.userId],diff --git a/packages/shared/queues.ts b/packages/shared/queues.tsindex 5484ffb2..624f2bca 100644--- a/packages/shared/queues.ts+++ b/packages/shared/queues.ts@@ -170,7 +170,7 @@ export const AssetPreprocessingQueue =// Webhook workerexport const zWebhookRequestSchema = z.object({bookmarkId: z.string(),- operation: z.enum(["crawled", "created", "edited"]),+ operation: z.enum(["crawled", "created", "edited", "ai tagged"]),});export type ZWebhookRequest = z.infer<typeof zWebhookRequestSchema>;export const WebhookQueue = new SqliteQueue<ZWebhookRequest>(diff --git a/packages/shared/types/webhooks.ts b/packages/shared/types/webhooks.tsindex 8d425ad9..819951ce 100644--- a/packages/shared/types/webhooks.ts+++ b/packages/shared/types/webhooks.ts@@ -3,7 +3,12 @@ import { z } from "zod";const MAX_WEBHOOK_URL_LENGTH = 500;const MAX_WEBHOOK_TOKEN_LENGTH = 100;-export const zWebhookEventSchema = z.enum(["created", "edited", "crawled"]);+export const zWebhookEventSchema = z.enum([+ "created",+ "edited",+ "crawled",+ "ai tagged",+]);export type ZWebhookEvent = z.infer<typeof zWebhookEventSchema>;export const zWebhookSchema = z.object({