diff --git a/backend/src/controllers/global-preferences/webhook-preferences.controller.ts b/backend/src/controllers/global-preferences/webhook-preferences.controller.ts index 21c02dc..5c768a1 100644 --- a/backend/src/controllers/global-preferences/webhook-preferences.controller.ts +++ b/backend/src/controllers/global-preferences/webhook-preferences.controller.ts @@ -8,12 +8,17 @@ export const updateWebhookPreferences = async (req: Request, res: Response) => { const logger = container.get(LoggerService); const globalPrefService = container.get(MeetStorageService); - logger.verbose(`Updating webhooks preferences: ${JSON.stringify(req.body)}`); + logger.info(`Updating webhooks preferences: ${JSON.stringify(req.body)}`); const webhookPreferences = req.body as WebhookPreferences; try { const globalPreferences = await globalPrefService.getGlobalPreferences(); - globalPreferences.webhooksPreferences = webhookPreferences; + globalPreferences.webhooksPreferences.enabled = webhookPreferences.enabled; + + if (webhookPreferences.url) { + globalPreferences.webhooksPreferences.url = webhookPreferences.url; + } + await globalPrefService.saveGlobalPreferences(globalPreferences); return res.status(200).json({ message: 'Webhooks preferences updated successfully' }); diff --git a/backend/src/middlewares/request-validators/preferences-validator.middleware.ts b/backend/src/middlewares/request-validators/preferences-validator.middleware.ts index 3bc8fa7..e853d3e 100644 --- a/backend/src/middlewares/request-validators/preferences-validator.middleware.ts +++ b/backend/src/middlewares/request-validators/preferences-validator.middleware.ts @@ -12,10 +12,21 @@ import { NextFunction, Request, Response } from 'express'; import { z } from 'zod'; import { rejectUnprocessableRequest } from '../../models/error.model.js'; -const WebhookPreferencesSchema: z.ZodType = z.object({ - enabled: z.boolean(), - url: z.string().url() -}); +const WebhookPreferencesSchema: z.ZodType = z + .object({ + enabled: z.boolean(), + url: z.string().url().optional() + }) + .refine( + (data) => { + // If webhooks are enabled, URL must be provided + return !data.enabled || Boolean(data.url); + }, + { + message: 'URL is required when webhooks are enabled', + path: ['url'] + } + ); const AuthModeSchema: z.ZodType = z.enum([AuthMode.NONE, AuthMode.MODERATORS_ONLY, AuthMode.ALL_USERS]); diff --git a/backend/src/services/openvidu-webhook.service.ts b/backend/src/services/openvidu-webhook.service.ts index a66e859..b5ad544 100644 --- a/backend/src/services/openvidu-webhook.service.ts +++ b/backend/src/services/openvidu-webhook.service.ts @@ -75,7 +75,7 @@ export class OpenViduWebhookService { this.logger.info(`Sending webhook event ${data.event}`); try { - await this.fetchWithRetry(webhookPreferences.url, { + await this.fetchWithRetry(webhookPreferences.url!, { method: 'POST', headers: { 'Content-Type': 'application/json',