From dd944bace1b29258f8b012bc427fedab5bddc782 Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Mon, 4 Nov 2024 21:42:34 +0530 Subject: [PATCH] chore: add webhook in payload (#17468) * chore: add webhook in payload * chore * chore: add more fields * add host email * chore: change name --- .../tasker/tasks/triggerNoShow/common.ts | 13 +++- .../triggerNoShow/triggerHostNoShow.test.ts | 76 +++++++++++-------- 2 files changed, 57 insertions(+), 32 deletions(-) diff --git a/packages/features/tasker/tasks/triggerNoShow/common.ts b/packages/features/tasker/tasks/triggerNoShow/common.ts index 1bf8fc0c37..0f338cd3dd 100644 --- a/packages/features/tasker/tasks/triggerNoShow/common.ts +++ b/packages/features/tasker/tasks/triggerNoShow/common.ts @@ -60,14 +60,22 @@ export function sendWebhookPayload( createdAt: new Date().toISOString(), webhook, data: { + title: booking.title, bookingId: booking.id, bookingUid: booking.uid, startTime: booking.startTime, + attendees: booking.attendees, endTime: booking.endTime, - ...(triggerEvent === WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW ? { email: hostEmail } : {}), + ...(!!hostEmail ? { hostEmail } : {}), eventType: { ...booking.eventType, id: booking.eventTypeId, + hosts: undefined, + users: undefined, + }, + webhook: { + ...webhook, + secret: undefined, }, message: triggerEvent === WebhookTriggerEvents.AFTER_GUESTS_CAL_VIDEO_NO_SHOW @@ -122,7 +130,8 @@ export const prepareNoShowTrigger = async ( return; } - const dailyVideoReference = booking.references.find((reference) => reference.type === "daily_video"); + const dailyVideoReference = + booking.references?.filter((reference) => reference.type === "daily_video")?.pop() ?? null; if (!dailyVideoReference) { log.error( diff --git a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts index c6daa17c0d..a4c7c15dc0 100644 --- a/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts +++ b/packages/features/tasker/tasks/triggerNoShow/triggerHostNoShow.test.ts @@ -126,21 +126,23 @@ describe("Trigger Host No Show:", () => { vi.mocked(getMeetingSessionsFromRoomName).mockResolvedValue(EMPTY_MEETING_SESSIONS); + const TEST_WEBHOOK = { + id: "22", + eventTriggers: [WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW], + subscriberUrl, + active: true, + eventTypeId: 1, + appId: null, + time: 5, + timeUnit: TimeUnit.MINUTE, + payloadTemplate: null, + secret: null, + }; + const payload = JSON.stringify({ triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, bookingId: 222, - webhook: { - id: "22", - eventTriggers: [WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW], - subscriberUrl, - active: true, - eventTypeId: 1, - appId: null, - time: 5, - timeUnit: TimeUnit.MINUTE, - payloadTemplate: null, - secret: null, - }, + webhook: TEST_WEBHOOK, } satisfies TSendNoShowWebhookPayloadSchema); await triggerHostNoShow(payload); @@ -150,17 +152,23 @@ describe("Trigger Host No Show:", () => { await expectWebhookToHaveBeenCalledWith(subscriberUrl, { triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, payload: { + title: "Test Booking Title", + attendees: [], bookingId: 222, bookingUid: uidOfBooking, - email: "organizer@example.com", + hostEmail: "organizer@example.com", startTime: `${plus1DateString}T05:00:00.000Z`, endTime: `${plus1DateString}T05:15:00.000Z`, eventType: { id: 1, teamId: null, parentId: null, - hosts: [], - users: [{ id: organizer.id, email: organizer.email }], + }, + webhook: { + ...TEST_WEBHOOK, + secret: undefined, + active: undefined, + eventTypeId: undefined, }, message: `Host with email ${organizer.email} didn't join the call or didn't join before ${maxStartTimeHumanReadable}`, }, @@ -278,21 +286,23 @@ describe("Trigger Host No Show:", () => { vi.mocked(getMeetingSessionsFromRoomName).mockResolvedValue(MOCKED_MEETING_SESSIONS); + const TEST_WEBHOOK = { + id: "22", + eventTriggers: [WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW], + subscriberUrl, + active: true, + eventTypeId: 1, + appId: null, + time: 5, + timeUnit: TimeUnit.MINUTE, + payloadTemplate: null, + secret: null, + }; + const payload = JSON.stringify({ triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, bookingId: 222, - webhook: { - id: "22", - eventTriggers: [WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW], - subscriberUrl, - active: true, - eventTypeId: 1, - appId: null, - time: 5, - timeUnit: TimeUnit.MINUTE, - payloadTemplate: null, - secret: null, - }, + webhook: TEST_WEBHOOK, } satisfies TSendNoShowWebhookPayloadSchema); await triggerHostNoShow(payload); @@ -303,17 +313,23 @@ describe("Trigger Host No Show:", () => { await expectWebhookToHaveBeenCalledWith(subscriberUrl, { triggerEvent: WebhookTriggerEvents.AFTER_HOSTS_CAL_VIDEO_NO_SHOW, payload: { + title: "Test Booking Title", + attendees: [], bookingId: 222, bookingUid: uidOfBooking, - email: "organizer@example.com", + hostEmail: "organizer@example.com", startTime: `${plus1DateString}T05:00:00.000Z`, endTime: `${plus1DateString}T05:15:00.000Z`, eventType: { id: 1, teamId: null, parentId: null, - hosts: [], - users: [{ id: organizer.id, email: organizer.email }], + }, + webhook: { + ...TEST_WEBHOOK, + secret: undefined, + active: undefined, + eventTypeId: undefined, }, message: `Host with email ${organizer.email} didn't join the call or didn't join before ${maxStartTimeHumanReadable}`, },