Scheduling infrastructure for absolutely everyone.
feat: meeting started webhook (#12764)
Somay Chauhan2e0c9c7068c6
diff --git a/apps/web/public/static/locales/en/common.json b/apps/web/public/static/locales/en/common.jsonindex 9522b32d74b..2b956a25ffa 100644--- a/apps/web/public/static/locales/en/common.json+++ b/apps/web/public/static/locales/en/common.json@@ -2168,5 +2168,6 @@"need_help": "Need help?","troubleshooter": "Troubleshooter","please_install_a_calendar": "Please install a calendar",+ "meeting_started": "Meeting Started","ADD_NEW_STRINGS_ABOVE_THIS_LINE_TO_PREVENT_MERGE_CONFLICTS": "↑↑↑↑↑↑↑↑↑↑↑↑↑ Add your new strings above here ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑"}diff --git a/packages/features/bookings/lib/handleConfirmation.ts b/packages/features/bookings/lib/handleConfirmation.tsindex cc71c27041c..fd23e806994 100644--- a/packages/features/bookings/lib/handleConfirmation.ts+++ b/packages/features/bookings/lib/handleConfirmation.ts@@ -300,6 +300,12 @@ export async function handleConfirmation(args: {triggerEvent: WebhookTriggerEvents.BOOKING_CREATED,teamId,});+ const subscribersMeetingStarted = await getWebhooks({+ userId: triggerForUser ? booking.userId : null,+ eventTypeId: booking.eventTypeId,+ triggerEvent: WebhookTriggerEvents.MEETING_STARTED,+ teamId: booking.eventType?.teamId,+ });const subscribersMeetingEnded = await getWebhooks({userId: triggerForUser ? booking.userId : null,eventTypeId: booking.eventTypeId,@@ -307,9 +313,14 @@ export async function handleConfirmation(args: {teamId: booking.eventType?.teamId,});+ subscribersMeetingStarted.forEach((subscriber) => {+ updatedBookings.forEach((booking) => {+ scheduleTrigger(booking, subscriber.subscriberUrl, subscriber, WebhookTriggerEvents.MEETING_STARTED);+ });+ });subscribersMeetingEnded.forEach((subscriber) => {updatedBookings.forEach((booking) => {- scheduleTrigger(booking, subscriber.subscriberUrl, subscriber);+ scheduleTrigger(booking, subscriber.subscriberUrl, subscriber, WebhookTriggerEvents.MEETING_ENDED);});});diff --git a/packages/features/bookings/lib/handleNewBooking.ts b/packages/features/bookings/lib/handleNewBooking.tsindex 6deee33c56f..9d6249474d3 100644--- a/packages/features/bookings/lib/handleNewBooking.ts+++ b/packages/features/bookings/lib/handleNewBooking.ts@@ -1416,6 +1416,12 @@ async function handler(teamId,};+ const subscriberOptionsMeetingStarted = {+ userId: triggerForUser ? organizerUser.id : null,+ eventTypeId,+ triggerEvent: WebhookTriggerEvents.MEETING_STARTED,+ teamId,+ };const handleSeats = async () => {let resultBooking:| (Partial<Booking> & {@@ -2693,13 +2699,28 @@ async function handler(if (isConfirmedByDefault) {try {const subscribersMeetingEnded = await getWebhooks(subscriberOptionsMeetingEnded);+ const subscribersMeetingStarted = await getWebhooks(subscriberOptionsMeetingStarted);subscribersMeetingEnded.forEach((subscriber) => {if (rescheduleUid && originalRescheduledBooking) {cancelScheduledJobs(originalRescheduledBooking, undefined, true);}if (booking && booking.status === BookingStatus.ACCEPTED) {- scheduleTrigger(booking, subscriber.subscriberUrl, subscriber);+ scheduleTrigger(booking, subscriber.subscriberUrl, subscriber, WebhookTriggerEvents.MEETING_ENDED);+ }+ });++ subscribersMeetingStarted.forEach((subscriber) => {+ if (rescheduleUid && originalRescheduledBooking) {+ cancelScheduledJobs(originalRescheduledBooking, undefined, true);+ }+ if (booking && booking.status === BookingStatus.ACCEPTED) {+ scheduleTrigger(+ booking,+ subscriber.subscriberUrl,+ subscriber,+ WebhookTriggerEvents.MEETING_STARTED+ );}});} catch (error) {diff --git a/packages/features/webhooks/components/WebhookForm.tsx b/packages/features/webhooks/components/WebhookForm.tsxindex d599f77394c..d55061b06f9 100644--- a/packages/features/webhooks/components/WebhookForm.tsx+++ b/packages/features/webhooks/components/WebhookForm.tsx@@ -39,6 +39,7 @@ const WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP_V2: Record<string, WebhookTriggerEve{ value: WebhookTriggerEvents.BOOKING_RESCHEDULED, label: "booking_rescheduled" },{ value: WebhookTriggerEvents.BOOKING_PAID, label: "booking_paid" },{ value: WebhookTriggerEvents.MEETING_ENDED, label: "meeting_ended" },+ { value: WebhookTriggerEvents.MEETING_STARTED, label: "meeting_started" },{ value: WebhookTriggerEvents.RECORDING_READY, label: "recording_ready" },],"routing-forms": [{ value: WebhookTriggerEvents.FORM_SUBMITTED, label: "form_submitted" }],diff --git a/packages/features/webhooks/lib/constants.ts b/packages/features/webhooks/lib/constants.tsindex 326a866a6e8..8630da4879b 100644--- a/packages/features/webhooks/lib/constants.ts+++ b/packages/features/webhooks/lib/constants.ts@@ -10,6 +10,7 @@ export const WEBHOOK_TRIGGER_EVENTS_GROUPED_BY_APP = {WebhookTriggerEvents.BOOKING_PAID,WebhookTriggerEvents.BOOKING_PAYMENT_INITIATED,WebhookTriggerEvents.MEETING_ENDED,+ WebhookTriggerEvents.MEETING_STARTED,WebhookTriggerEvents.BOOKING_REQUESTED,WebhookTriggerEvents.BOOKING_REJECTED,WebhookTriggerEvents.RECORDING_READY,diff --git a/packages/features/webhooks/lib/scheduleTrigger.ts b/packages/features/webhooks/lib/scheduleTrigger.tsindex ab44805f214..9048be3c657 100644--- a/packages/features/webhooks/lib/scheduleTrigger.ts+++ b/packages/features/webhooks/lib/scheduleTrigger.ts@@ -45,7 +45,10 @@ export async function addSubscription({},});- if (triggerEvent === WebhookTriggerEvents.MEETING_ENDED) {+ if (+ triggerEvent === WebhookTriggerEvents.MEETING_ENDED ||+ triggerEvent === WebhookTriggerEvents.MEETING_STARTED+ ) {//schedule job for already existing bookingsconst where: Prisma.BookingWhereInput = {};if (teamId) {@@ -64,10 +67,15 @@ export async function addSubscription({});for (const booking of bookings) {- scheduleTrigger(booking, createSubscription.subscriberUrl, {- id: createSubscription.id,- appId: createSubscription.appId,- });+ scheduleTrigger(+ booking,+ createSubscription.subscriberUrl,+ {+ id: createSubscription.id,+ appId: createSubscription.appId,+ },+ triggerEvent+ );}}@@ -273,12 +281,13 @@ export async function listBookings(}export async function scheduleTrigger(- booking: { id: number; endTime: Date; scheduledJobs: string[] },+ booking: { id: number; endTime: Date; startTime: Date; scheduledJobs: string[] },subscriberUrl: string,- subscriber: { id: string; appId: string | null }+ subscriber: { id: string; appId: string | null },+ triggerEvent: WebhookTriggerEvents) {try {- const payload = JSON.stringify({ triggerEvent: WebhookTriggerEvents.MEETING_ENDED, ...booking });+ const payload = JSON.stringify({ triggerEvent, ...booking });const jobName = `${subscriber.appId}_${subscriber.id}`;// add scheduled job to database@@ -286,7 +295,7 @@ export async function scheduleTrigger(data: {jobName,payload,- startAfter: booking.endTime,+ startAfter: triggerEvent === WebhookTriggerEvents.MEETING_ENDED ? booking.endTime : booking.startTime,subscriberUrl,},});diff --git a/packages/prisma/migrations/20231213083720_add_meeting_started_webhook/migration.sql b/packages/prisma/migrations/20231213083720_add_meeting_started_webhook/migration.sqlnew file mode 100644index 00000000000..06a86818216--- /dev/null+++ b/packages/prisma/migrations/20231213083720_add_meeting_started_webhook/migration.sql@@ -0,0 +1,2 @@+-- AlterEnum+ALTER TYPE "WebhookTriggerEvents" ADD VALUE 'MEETING_STARTED';diff --git a/packages/prisma/schema.prisma b/packages/prisma/schema.prismaindex 7c959a8e05e..7560ce3b1a8 100644--- a/packages/prisma/schema.prisma+++ b/packages/prisma/schema.prisma@@ -570,6 +570,7 @@ enum WebhookTriggerEvents {BOOKING_REJECTEDFORM_SUBMITTEDMEETING_ENDED+ MEETING_STARTEDRECORDING_READY}