Scheduling infrastructure for absolutely everyone.
fix: Add custom payload template support for form submission webhooks (#25719)
Anik Dhabal Babu476460dad808
diff --git a/packages/features/webhooks/lib/sendPayload.ts b/packages/features/webhooks/lib/sendPayload.tsindex b5686ca657a..d8ee69a5211 100644--- a/packages/features/webhooks/lib/sendPayload.ts+++ b/packages/features/webhooks/lib/sendPayload.ts@@ -173,7 +173,11 @@ function getZapierPayload(data: WithUTCOffsetType<EventPayloadType & { createdAtreturn JSON.stringify(body);}-function applyTemplate(template: string, data: WebhookDataType, contentType: ContentType) {+function applyTemplate(+ template: string,+ data: WebhookDataType | Record<string, unknown>,+ contentType: ContentType+) {const compiled = compile(template)(data).replace(/"/g, '"');if (contentType === "application/json") {@@ -268,15 +272,27 @@ export const sendGenericWebhookPayload = async ({data: Record<string, unknown>;rootData?: Record<string, unknown>;}) => {- const body = JSON.stringify({+ const { payloadTemplate: template } = webhook;++ const contentType =+ !template || jsonParse(template) ? "application/json" : "application/x-www-form-urlencoded";++ const defaultPayload = {// Added rootData props first so that using the known(i.e. triggerEvent, createdAt, payload) properties in rootData doesn't override the known properties...rootData,triggerEvent: triggerEvent,createdAt: createdAt,payload: data,- });+ };++ let body: string;+ if (template) {+ body = applyTemplate(template, defaultPayload, contentType);+ } else {+ body = JSON.stringify(defaultPayload);+ }- return _sendPayload(secretKey, webhook, body, "application/json");+ return _sendPayload(secretKey, webhook, body, contentType);};export const createWebhookSignature = (params: { secret?: string | null; body: string }) =>