diff --git a/apps/web/lib/webhooks/sendPayload.tsx b/apps/web/lib/webhooks/sendPayload.tsx index 4eb97437..c2793580 100644 --- a/apps/web/lib/webhooks/sendPayload.tsx +++ b/apps/web/lib/webhooks/sendPayload.tsx @@ -7,7 +7,7 @@ type ContentType = "application/json" | "application/x-www-form-urlencoded"; function applyTemplate(template: string, data: CalendarEvent, contentType: ContentType) { const compiled = compile(template)(data); if (contentType === "application/json") { - return jsonParse(compiled); + return JSON.stringify(jsonParse(compiled)); } return compiled; } diff --git a/apps/web/pages/integrations/index.tsx b/apps/web/pages/integrations/index.tsx index a01e5455..c90deea2 100644 --- a/apps/web/pages/integrations/index.tsx +++ b/apps/web/pages/integrations/index.tsx @@ -56,7 +56,7 @@ function WebhookListItem(props: { webhook: TWebhook; onEditWebhook: () => void }
- + {props.webhook.eventTriggers.map((eventTrigger, ind) => ( { + form.setValue("subscriberUrl", e.target.value); + const ind = supportedWebhookIntegrationList.findIndex((integration) => { + return e.target.value.includes(integration); + }); + if (ind > -1) updateCustomTemplate(supportedWebhookIntegrationList[ind]); + }; + + const updateCustomTemplate = (webhookIntegration) => { + setUseCustomPayloadTemplate(true); + switch (webhookIntegration) { + case "https://discord.com/api/webhooks/": + form.setValue( + "payloadTemplate", + '{"content": "A new event has been scheduled","embeds": [{"color": 2697513,"fields": [{"name": "What","value": "{{title}} ({{type}})"},{"name": "When","value": "Start: {{startTime}} \\n End: {{endTime}} \\n Timezone: ({{organizer.timeZone}})"},{"name": "Who","value": "Organizer: {{organizer.name}} ({{organizer.email}}) \\n Booker: {{attendees.0.name}} ({{attendees.0.email}})" },{"name":"Description", "value":": {{description}}"},{"name":"Where","value":": {{location}} "}]}]}' + ); + } + }; const { defaultValues = { @@ -219,7 +239,13 @@ function WebhookDialogForm(props: { /> - +
{t("event_triggers")} diff --git a/apps/web/server/routers/viewer/webhook.tsx b/apps/web/server/routers/viewer/webhook.tsx index 5afa7c37..02c86055 100644 --- a/apps/web/server/routers/viewer/webhook.tsx +++ b/apps/web/server/routers/viewer/webhook.tsx @@ -23,6 +23,7 @@ export const webhookRouter = createProtectedRouter() subscriberUrl: z.string().url(), eventTriggers: z.enum(WEBHOOK_TRIGGER_EVENTS).array(), active: z.boolean(), + payloadTemplate: z.string().nullable(), }), async resolve({ ctx, input }) { return await ctx.prisma.webhook.create({