-
Notifications
You must be signed in to change notification settings - Fork 12k
chore: Remove SendGrid related code from emailReminderManager #23591
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
27aa5b0
chore: Remove SendGrid related code from emailReminderManager
emrysal a525465
Small type fixes in consumers
emrysal c65054b
Remove redundant userId/teamId from activateEventType.handler
emrysal 20598d1
Merge branch 'main' into chore/use-smtp-workflow-reminders
emrysal d36daa7
Remove sendSengridMail as dep
emrysal 5899e21
Remove teamId param
emrysal a8d55ec
Merge branch 'main' into chore/use-smtp-workflow-reminders
keithwillcode c0f075c
Address NIT
emrysal bb19be1
Merge branch 'chore/use-smtp-workflow-reminders' of https://github.co…
emrysal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,6 @@ import { v4 as uuidv4 } from "uuid"; | |
|
|
||
| import dayjs from "@calcom/dayjs"; | ||
| import generateIcsString from "@calcom/emails/lib/generateIcsString"; | ||
| import { FeaturesRepository } from "@calcom/features/flags/features.repository"; | ||
| import { preprocessNameFieldDataWithVariant } from "@calcom/features/form-builder/utils"; | ||
| import tasker from "@calcom/features/tasker"; | ||
| import { SENDER_NAME, WEBSITE_URL } from "@calcom/lib/constants"; | ||
|
|
@@ -19,10 +18,8 @@ import { | |
| } from "@calcom/prisma/enums"; | ||
| import { bookingMetadataSchema } from "@calcom/prisma/zod-utils"; | ||
|
|
||
| import { IMMEDIATE_WORKFLOW_TRIGGER_EVENTS } from "../constants"; | ||
| import { getWorkflowRecipientEmail } from "../getWorkflowReminders"; | ||
| import { sendOrScheduleWorkflowEmails } from "./providers/emailProvider"; | ||
| import { getBatchId, sendSendgridMail } from "./providers/sendgridProvider"; | ||
| import type { AttendeeInBookingInfo, BookingInfo, timeUnitLowerCase } from "./smsReminderManager"; | ||
| import type { VariablesType } from "./templates/customTemplate"; | ||
| import customTemplate from "./templates/customTemplate"; | ||
|
|
@@ -53,13 +50,10 @@ interface scheduleEmailReminderArgs extends ScheduleReminderArgs { | |
| evt: BookingInfo; | ||
| sendTo: string[]; | ||
| action: ScheduleEmailReminderAction; | ||
| userId?: number | null; | ||
| teamId?: number | null; | ||
| emailSubject?: string; | ||
| emailBody?: string; | ||
| hideBranding?: boolean; | ||
| includeCalendarEvent?: boolean; | ||
| isMandatoryReminder?: boolean; | ||
| verifiedAt: Date | null; | ||
| } | ||
|
|
||
|
|
@@ -77,11 +71,8 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) => | |
| emailBody = "", | ||
| hideBranding, | ||
| includeCalendarEvent, | ||
| isMandatoryReminder, | ||
| action, | ||
| verifiedAt, | ||
| userId, | ||
| teamId, | ||
| } = args; | ||
|
|
||
| if (!verifiedAt) { | ||
|
|
@@ -91,7 +82,6 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) => | |
|
|
||
| const { startTime, endTime } = evt; | ||
| const uid = evt.uid as string; | ||
| const currentDate = dayjs(); | ||
| const timeUnit: timeUnitLowerCase | undefined = timeSpan.timeUnit?.toLocaleLowerCase() as timeUnitLowerCase; | ||
|
|
||
| let scheduledDate = null; | ||
|
|
@@ -286,130 +276,26 @@ export const scheduleEmailReminder = async (args: scheduleEmailReminderArgs) => | |
|
|
||
| const mailData = await prepareEmailData(); | ||
|
|
||
| const isSendgridEnabled = !!(process.env.SENDGRID_API_KEY && process.env.SENDGRID_EMAIL); | ||
|
|
||
| const featureRepo = new FeaturesRepository(prisma); | ||
|
|
||
| const isWorkflowSmtpEmailsEnabled = teamId | ||
| ? await featureRepo.checkIfTeamHasFeature(teamId, "workflow-smtp-emails") | ||
| : userId | ||
| ? await featureRepo.checkIfUserHasFeature(userId, "workflow-smtp-emails") | ||
| : false; | ||
|
|
||
| if (isWorkflowSmtpEmailsEnabled || !isSendgridEnabled) { | ||
| let reminderUid; | ||
| if (scheduledDate) { | ||
| const reminder = await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| workflowStepId, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: true, | ||
| }, | ||
| }); | ||
| reminderUid = reminder.uuid; | ||
| } | ||
|
|
||
| await sendOrScheduleWorkflowEmails({ | ||
| ...mailData, | ||
| to: sendTo, | ||
| sendAt: scheduledDate?.toDate(), | ||
| referenceUid: reminderUid ?? undefined, | ||
| let reminderUid = undefined; | ||
| if (scheduledDate) { | ||
| const reminder = await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| workflowStepId, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: true, | ||
| }, | ||
| }); | ||
|
|
||
| return; | ||
| reminderUid = reminder.uuid; | ||
| } | ||
|
|
||
| /** | ||
| * @deprecated only needed for SendGrid, use SMTP with tasker instead | ||
| */ | ||
| if (IMMEDIATE_WORKFLOW_TRIGGER_EVENTS.includes(triggerEvent)) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. NIT: import in line https://github.com/calcom/cal.com/pull/23591/files#diff-675b1da8590d6cdd4d5e3d50ada134c6cbdf4ec2893b991247595df3b95c9617L22 can be removed |
||
| try { | ||
| const promises = sendTo.map((email) => sendSendgridMail({ ...mailData, to: email })); | ||
| // TODO: Maybe don't await for this? | ||
| await Promise.all(promises); | ||
| } catch (error) { | ||
| log.error("Error sending Email"); | ||
| } | ||
| } else if ( | ||
| (triggerEvent === WorkflowTriggerEvents.BEFORE_EVENT || | ||
| triggerEvent === WorkflowTriggerEvents.AFTER_EVENT) && | ||
| scheduledDate | ||
| ) { | ||
| // Sendgrid to schedule emails | ||
| // Can only schedule at least 60 minutes and at most 72 hours in advance | ||
| // To limit the amount of canceled sends we schedule at most 2 hours in advance | ||
| if ( | ||
| currentDate.isBefore(scheduledDate.subtract(1, "hour")) && | ||
| !scheduledDate.isAfter(currentDate.add(2, "hour")) | ||
| ) { | ||
| try { | ||
| const sendgridBatchId = await getBatchId(); | ||
|
|
||
| // If sendEmail failed then workflowReminer will not be created, failing E2E tests | ||
| await sendSendgridMail({ | ||
| ...mailData, | ||
| to: sendTo, | ||
| sendAt: scheduledDate.unix(), | ||
| batchId: sendgridBatchId, | ||
| }); | ||
|
|
||
| if (!isMandatoryReminder) { | ||
| await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| workflowStepId: workflowStepId, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: true, | ||
| referenceId: sendgridBatchId, | ||
| seatReferenceId: seatReferenceUid, | ||
| }, | ||
| }); | ||
| } else { | ||
| await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: true, | ||
| referenceId: sendgridBatchId, | ||
| seatReferenceId: seatReferenceUid, | ||
| isMandatoryReminder: true, | ||
| }, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| log.error(`Error scheduling email with error ${error}`); | ||
| } | ||
| } else if (scheduledDate.isAfter(currentDate.add(2, "hour"))) { | ||
| // Write to DB and send to CRON if scheduled reminder date is past 2 hours | ||
| if (!isMandatoryReminder) { | ||
| await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| workflowStepId: workflowStepId, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: false, | ||
| seatReferenceId: seatReferenceUid, | ||
| }, | ||
| }); | ||
| } else { | ||
| await prisma.workflowReminder.create({ | ||
| data: { | ||
| bookingUid: uid, | ||
| method: WorkflowMethods.EMAIL, | ||
| scheduledDate: scheduledDate.toDate(), | ||
| scheduled: false, | ||
| seatReferenceId: seatReferenceUid, | ||
| isMandatoryReminder: true, | ||
| }, | ||
| }); | ||
| } | ||
| } | ||
| } | ||
| await sendOrScheduleWorkflowEmails({ | ||
| ...mailData, | ||
| to: sendTo, | ||
| sendAt: scheduledDate?.toDate(), | ||
| referenceUid: reminderUid ?? undefined, | ||
| }); | ||
| }; | ||
|
|
||
| export const deleteScheduledEmailReminder = async (reminderId: number) => { | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.