Skip to content

Scheduling infrastructure for absolutely everyone.

fix custom workflow template (#7154)

Carina Wollendorfer38be2bef9a7b
diff --git a/packages/features/webhooks/lib/sendPayload.ts b/packages/features/webhooks/lib/sendPayload.ts
index b39e63d844e..73e680c86d5 100644
--- a/packages/features/webhooks/lib/sendPayload.ts
+++ b/packages/features/webhooks/lib/sendPayload.ts
@@ -16,6 +16,19 @@ export type EventTypeInfo = {
length?: number | null;
};
+type WebhookDataType = CalendarEvent &
+ EventTypeInfo & {
+ metadata?: { [key: string]: string };
+ bookingId?: number;
+ status?: string;
+ smsReminderNumber?: string;
+ rescheduleUid?: string;
+ rescheduleStartTime?: string;
+ rescheduleEndTime?: string;
+ triggerEvent: string;
+ createdAt: string;
+ };
+
function getZapierPayload(data: CalendarEvent & EventTypeInfo & { status?: string }): string {
const attendees = data.attendees.map((attendee) => {
return {
@@ -57,8 +70,13 @@ function getZapierPayload(data: CalendarEvent & EventTypeInfo & { status?: strin
return JSON.stringify(body);
}
-function applyTemplate(template: string, data: CalendarEvent, contentType: ContentType) {
- const compiled = compile(template)(data);
+function applyTemplate(template: string, data: WebhookDataType, contentType: ContentType) {
+ const organizer = JSON.stringify(data.organizer);
+ const attendees = JSON.stringify(data.attendees);
+ const formattedData = { ...data, metadata: JSON.stringify(data.metadata), organizer, attendees };
+
+ const compiled = compile(template)(formattedData).replace(/"/g, '"');
+
if (contentType === "application/json") {
return JSON.stringify(jsonParse(compiled));
}
@@ -79,16 +97,7 @@ const sendPayload = async (
triggerEvent: string,
createdAt: string,
webhook: Pick<Webhook, "subscriberUrl" | "appId" | "payloadTemplate">,
- data: CalendarEvent &
- EventTypeInfo & {
- metadata?: { [key: string]: string };
- bookingId?: number;
- status?: string;
- smsReminderNumber?: string;
- rescheduleUid?: string;
- rescheduleStartTime?: string;
- rescheduleEndTime?: string;
- }
+ data: Omit<WebhookDataType, "createdAt" | "triggerEvent">
) => {
const { appId, payloadTemplate: template } = webhook;
@@ -96,14 +105,13 @@ const sendPayload = async (
!template || jsonParse(template) ? "application/json" : "application/x-www-form-urlencoded";
data.description = data.description || data.additionalNotes;
-
let body;
/* Zapier id is hardcoded in the DB, we send the raw data for this case */
if (appId === "zapier") {
body = getZapierPayload(data);
} else if (template) {
- body = applyTemplate(template, data, contentType);
+ body = applyTemplate(template, { ...data, triggerEvent, createdAt }, contentType);
} else {
body = JSON.stringify({
triggerEvent: triggerEvent,