feat: SMS/Whatsapp to attendee for teams (#14648)
* remove event type requires confirmation * allow sms sending also for team (frontend) * allow text to attendee for team (backend) * add rate limiting for SMS (WIP) * add functionality to lock and unlock SMS sending (+admin UI view) * rename to smsLockState * add ability to lock users and teams * don't send sms if locked * add missing imports * fix rate limit namespace * add translation * fix type error * remove prop from UsersTable * add smsLockState to buildUser * code clean up * create seperate sms rate limit function * fix type error * add missing userId and teamId to sendSMS * code improvements * add User Team type * fix marking as reviewed * check monthly sms limit only for user * don't lock orgs * fix type error * fix avatars * fix type error * fix type error * fix type error --------- Co-authored-by: CarinaWolli <[email protected]> Co-authored-by: Joe Au-Yeung <[email protected]> Co-authored-by: Udit Takkar <[email protected]>
This commit is contained in:
34 files changed
+725
-164
No files matched your search
@@ -316,7 +316,6 @@ async function handler(req: CustomRequest) {
|
||||
...{ eventType: { slug: bookingToDelete.eventType.slug } },
|
||||
},
|
||||
hideBranding: !!bookingToDelete.eventType.owner?.hideBranding,
|
||||
eventTypeRequiresConfirmation: bookingToDelete.eventType.requiresConfirmation,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -288,7 +288,6 @@ export async function handleConfirmation(args: {
|
||||
calendarEvent: evtOfBooking,
|
||||
isFirstRecurringEvent: isFirstBooking,
|
||||
hideBranding: !!updatedBookings[index].eventType?.owner?.hideBranding,
|
||||
eventTypeRequiresConfirmation: true,
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -2354,7 +2354,6 @@ async function handler(
|
||||
isFirstRecurringEvent: true,
|
||||
hideBranding: !!eventType.owner?.hideBranding,
|
||||
seatReferenceUid: evt.attendeeSeatId,
|
||||
eventTypeRequiresConfirmation: eventType.requiresConfirmation,
|
||||
});
|
||||
} catch (error) {
|
||||
loggerWithEventDetails.error("Error while scheduling workflow reminders", JSON.stringify({ error }));
|
||||
|
||||
@@ -110,7 +110,6 @@ const handleSeats = async (newSeatedBookingObject: NewSeatedBookingObject) => {
|
||||
isFirstRecurringEvent: true,
|
||||
emailAttendeeSendToOverride: bookerEmail,
|
||||
seatReferenceUid: evt.attendeeSeatId,
|
||||
eventTypeRequiresConfirmation: eventType.requiresConfirmation,
|
||||
});
|
||||
} catch (error) {
|
||||
loggerWithEventDetails.error("Error while scheduling workflow reminders", JSON.stringify({ error }));
|
||||
|
||||
@@ -56,6 +56,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!reminder.workflowStep || !reminder.booking) {
|
||||
continue;
|
||||
}
|
||||
const userId = reminder.workflowStep.workflow.userId;
|
||||
const teamId = reminder.workflowStep.workflow.teamId;
|
||||
|
||||
try {
|
||||
const sendTo =
|
||||
reminder.workflowStep.action === WorkflowActions.SMS_NUMBER
|
||||
@@ -141,17 +144,26 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
}
|
||||
|
||||
if (message?.length && message?.length > 0 && sendTo) {
|
||||
const scheduledSMS = await twilio.scheduleSMS(sendTo, message, reminder.scheduledDate, senderID);
|
||||
const scheduledSMS = await twilio.scheduleSMS(
|
||||
sendTo,
|
||||
message,
|
||||
reminder.scheduledDate,
|
||||
senderID,
|
||||
userId,
|
||||
teamId
|
||||
);
|
||||
|
||||
await prisma.workflowReminder.update({
|
||||
where: {
|
||||
id: reminder.id,
|
||||
},
|
||||
data: {
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
},
|
||||
});
|
||||
if (scheduledSMS) {
|
||||
await prisma.workflowReminder.update({
|
||||
where: {
|
||||
id: reminder.id,
|
||||
},
|
||||
data: {
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Error scheduling SMS with error ${error}`);
|
||||
|
||||
@@ -8,6 +8,8 @@ import prisma from "@calcom/prisma";
|
||||
import { WorkflowActions, WorkflowMethods } from "@calcom/prisma/enums";
|
||||
|
||||
import { getWhatsappTemplateFunction } from "../lib/actionHelperFunctions";
|
||||
import type { PartialWorkflowReminder } from "../lib/getWorkflowReminders";
|
||||
import { select } from "../lib/getWorkflowReminders";
|
||||
import * as twilio from "../lib/reminders/providers/twilioProvider";
|
||||
|
||||
async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
@@ -28,7 +30,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
});
|
||||
|
||||
//find all unscheduled WHATSAPP reminders
|
||||
const unscheduledReminders = await prisma.workflowReminder.findMany({
|
||||
const unscheduledReminders = (await prisma.workflowReminder.findMany({
|
||||
where: {
|
||||
method: WorkflowMethods.WHATSAPP,
|
||||
scheduled: false,
|
||||
@@ -36,17 +38,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
lte: dayjs().add(7, "day").toISOString(),
|
||||
},
|
||||
},
|
||||
include: {
|
||||
workflowStep: true,
|
||||
booking: {
|
||||
include: {
|
||||
eventType: true,
|
||||
user: true,
|
||||
attendees: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
select,
|
||||
})) as PartialWorkflowReminder[];
|
||||
|
||||
if (!unscheduledReminders.length) {
|
||||
res.json({ ok: true });
|
||||
@@ -57,6 +50,9 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
if (!reminder.workflowStep || !reminder.booking) {
|
||||
continue;
|
||||
}
|
||||
const userId = reminder.workflowStep.workflow.userId;
|
||||
const teamId = reminder.workflowStep.workflow.teamId;
|
||||
|
||||
try {
|
||||
const sendTo =
|
||||
reminder.workflowStep.action === WorkflowActions.WHATSAPP_NUMBER
|
||||
@@ -91,17 +87,27 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
);
|
||||
|
||||
if (message?.length && message?.length > 0 && sendTo) {
|
||||
const scheduledSMS = await twilio.scheduleSMS(sendTo, message, reminder.scheduledDate, "", true);
|
||||
const scheduledSMS = await twilio.scheduleSMS(
|
||||
sendTo,
|
||||
message,
|
||||
reminder.scheduledDate,
|
||||
"",
|
||||
userId,
|
||||
teamId,
|
||||
true
|
||||
);
|
||||
|
||||
await prisma.workflowReminder.update({
|
||||
where: {
|
||||
id: reminder.id,
|
||||
},
|
||||
data: {
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
},
|
||||
});
|
||||
if (scheduledSMS) {
|
||||
await prisma.workflowReminder.update({
|
||||
where: {
|
||||
id: reminder.id,
|
||||
},
|
||||
data: {
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Error scheduling WHATSAPP with error ${error}`);
|
||||
|
||||
@@ -175,8 +175,7 @@ export const AddActionDialog = (props: IAddActionDialog) => {
|
||||
label: string;
|
||||
value: WorkflowActions;
|
||||
needsTeamsUpgrade: boolean;
|
||||
needsOrgsUpgrade: boolean;
|
||||
}) => option.needsTeamsUpgrade || option.needsOrgsUpgrade}
|
||||
}) => option.needsTeamsUpgrade}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
|
||||
@@ -5,7 +5,6 @@ import { useFormContext } from "react-hook-form";
|
||||
import { Trans } from "react-i18next";
|
||||
|
||||
import useLockedFieldsManager from "@calcom/features/ee/managed-event-types/hooks/useLockedFieldsManager";
|
||||
import { isTextMessageToAttendeeAction } from "@calcom/features/ee/workflows/lib/actionHelperFunctions";
|
||||
import type { FormValues } from "@calcom/features/eventtypes/lib/types";
|
||||
import classNames from "@calcom/lib/classNames";
|
||||
import { useLocale } from "@calcom/lib/hooks/useLocale";
|
||||
@@ -105,12 +104,6 @@ const WorkflowListItem = (props: ItemProps) => {
|
||||
}
|
||||
});
|
||||
|
||||
const needsRequiresConfirmationWarning =
|
||||
!eventType.requiresConfirmation &&
|
||||
workflow.steps.find((step) => {
|
||||
return isTextMessageToAttendeeAction(step.action);
|
||||
});
|
||||
|
||||
return (
|
||||
<div className="border-subtle w-full overflow-hidden rounded-md border p-6 px-3 md:p-6">
|
||||
<div className="flex items-center ">
|
||||
@@ -179,15 +172,6 @@ const WorkflowListItem = (props: ItemProps) => {
|
||||
</div>
|
||||
</Tooltip>
|
||||
</div>
|
||||
|
||||
{needsRequiresConfirmationWarning ? (
|
||||
<div className="text-attention -mb-2 mt-3 flex">
|
||||
<Icon name="info" className="mr-1 mt-0.5 h-4 w-4" />
|
||||
<p className="text-sm">{t("requires_confirmation_mandatory")}</p>
|
||||
</div>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
@@ -45,7 +45,6 @@ import {
|
||||
isAttendeeAction,
|
||||
isSMSAction,
|
||||
isSMSOrWhatsappAction,
|
||||
isTextMessageToAttendeeAction,
|
||||
isWhatsappAction,
|
||||
} from "../lib/actionHelperFunctions";
|
||||
import { DYNAMIC_TEXT_VARIABLES } from "../lib/constants";
|
||||
@@ -120,10 +119,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
form.getValues("trigger") === WorkflowTriggerEvents.AFTER_EVENT
|
||||
);
|
||||
|
||||
const [isRequiresConfirmationNeeded, setIsRequiresConfirmationNeeded] = useState(
|
||||
isTextMessageToAttendeeAction(step?.action)
|
||||
);
|
||||
|
||||
const { data: actionOptions } = trpc.viewer.workflows.getWorkflowActionOptions.useQuery();
|
||||
const triggerOptions = getWorkflowTriggerOptions(t);
|
||||
const templateOptions = getWorkflowTemplateOptions(t, step?.action);
|
||||
@@ -345,7 +340,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
label: actionString.charAt(0).toUpperCase() + actionString.slice(1),
|
||||
value: step.action,
|
||||
needsTeamsUpgrade: false,
|
||||
needsOrgsUpgrade: false,
|
||||
};
|
||||
|
||||
const selectedTemplate = { label: t(`${step.template.toLowerCase()}`), value: step.template };
|
||||
@@ -463,12 +457,6 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
setIsEmailSubjectNeeded(true);
|
||||
}
|
||||
|
||||
if (isTextMessageToAttendeeAction(val.value)) {
|
||||
setIsRequiresConfirmationNeeded(true);
|
||||
} else {
|
||||
setIsRequiresConfirmationNeeded(false);
|
||||
}
|
||||
|
||||
if (
|
||||
form.getValues(`steps.${step.stepNumber - 1}.template`) ===
|
||||
WorkflowTemplates.REMINDER
|
||||
@@ -541,20 +529,11 @@ export default function WorkflowStepContainer(props: WorkflowStepProps) {
|
||||
label: string;
|
||||
value: WorkflowActions;
|
||||
needsTeamsUpgrade: boolean;
|
||||
needsOrgsUpgrade: boolean;
|
||||
}) => option.needsTeamsUpgrade || option.needsOrgsUpgrade}
|
||||
}) => option.needsTeamsUpgrade}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
/>
|
||||
{isRequiresConfirmationNeeded ? (
|
||||
<div className="text-attention mb-3 mt-2 flex">
|
||||
<Icon name="info" className="mr-1 mt-0.5 h-4 w-4" />
|
||||
<p className="text-sm">{t("requires_confirmation_mandatory")}</p>
|
||||
</div>
|
||||
) : (
|
||||
<></>
|
||||
)}
|
||||
</div>
|
||||
{isPhoneNumberNeeded && (
|
||||
<div className="bg-muted mt-2 rounded-md p-4 pt-0">
|
||||
|
||||
@@ -42,9 +42,6 @@ export function isEmailToAttendeeAction(action: WorkflowActions) {
|
||||
return action === WorkflowActions.EMAIL_ATTENDEE;
|
||||
}
|
||||
|
||||
export function isTextMessageToAttendeeAction(action?: WorkflowActions) {
|
||||
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.WHATSAPP_ATTENDEE;
|
||||
}
|
||||
export function isTextMessageToSpecificNumber(action?: WorkflowActions) {
|
||||
return action === WorkflowActions.SMS_NUMBER || action === WorkflowActions.WHATSAPP_NUMBER;
|
||||
}
|
||||
@@ -65,7 +62,7 @@ export function getWhatsappTemplateForTrigger(trigger: WorkflowTriggerEvents): W
|
||||
}
|
||||
}
|
||||
|
||||
export function getWhatsappTemplateFunction(template: WorkflowTemplates): typeof whatsappReminderTemplate {
|
||||
export function getWhatsappTemplateFunction(template?: WorkflowTemplates): typeof whatsappReminderTemplate {
|
||||
switch (template) {
|
||||
case "CANCELLED":
|
||||
return whatsappEventCancelledTemplate;
|
||||
|
||||
@@ -2,12 +2,7 @@ import type { TFunction } from "next-i18next";
|
||||
|
||||
import { WorkflowActions } from "@calcom/prisma/enums";
|
||||
|
||||
import {
|
||||
isTextMessageToAttendeeAction,
|
||||
isSMSOrWhatsappAction,
|
||||
isWhatsappAction,
|
||||
isEmailToAttendeeAction,
|
||||
} from "./actionHelperFunctions";
|
||||
import { isSMSOrWhatsappAction, isWhatsappAction, isEmailToAttendeeAction } from "./actionHelperFunctions";
|
||||
import {
|
||||
TIME_UNIT,
|
||||
WHATSAPP_WORKFLOW_TEMPLATES,
|
||||
@@ -25,9 +20,7 @@ export function getWorkflowActionOptions(t: TFunction, isTeamsPlan?: boolean, is
|
||||
return {
|
||||
label: actionString.charAt(0).toUpperCase() + actionString.slice(1),
|
||||
value: action,
|
||||
needsTeamsUpgrade:
|
||||
isSMSOrWhatsappAction(action) && !isTextMessageToAttendeeAction(action) && !isTeamsPlan,
|
||||
needsOrgsUpgrade: isTextMessageToAttendeeAction(action) && !isOrgsPlan,
|
||||
needsTeamsUpgrade: isSMSOrWhatsappAction(action) && !isTeamsPlan,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ import prisma from "@calcom/prisma";
|
||||
import type { EventType, Prisma, User, WorkflowReminder, WorkflowStep } from "@calcom/prisma/client";
|
||||
import { WorkflowMethods } from "@calcom/prisma/enums";
|
||||
|
||||
type PartialWorkflowStep = Partial<WorkflowStep> | null;
|
||||
type PartialWorkflowStep =
|
||||
| (Partial<WorkflowStep> & { workflow: { userId?: number; teamId?: number } })
|
||||
| null;
|
||||
|
||||
type Booking = Prisma.BookingGetPayload<{
|
||||
include: {
|
||||
@@ -120,6 +122,12 @@ export const select: Prisma.WorkflowReminderSelect = {
|
||||
template: true,
|
||||
sender: true,
|
||||
includeCalendarEvent: true,
|
||||
workflow: {
|
||||
select: {
|
||||
userId: true,
|
||||
teamId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
booking: {
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
import TwilioClient from "twilio";
|
||||
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import logger from "@calcom/lib/logger";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { SMSLockState } from "@calcom/prisma/enums";
|
||||
|
||||
declare global {
|
||||
// eslint-disable-next-line no-var
|
||||
var twilio: TwilioClient.Twilio | undefined;
|
||||
}
|
||||
|
||||
const log = logger.getSubLogger({ prefix: ["[twilioProvider]"] });
|
||||
|
||||
export const twilio =
|
||||
globalThis.twilio ||
|
||||
(process.env.TWILIO_SID && process.env.TWILIO_TOKEN && process.env.TWILIO_MESSAGING_SID)
|
||||
@@ -31,8 +38,30 @@ function getSMSNumber(phone: string, whatsapp = false) {
|
||||
return whatsapp ? `whatsapp:${phone}` : phone;
|
||||
}
|
||||
|
||||
export const sendSMS = async (phoneNumber: string, body: string, sender: string, whatsapp = false) => {
|
||||
export const sendSMS = async (
|
||||
phoneNumber: string,
|
||||
body: string,
|
||||
sender: string,
|
||||
userId?: number | null,
|
||||
teamId?: number | null,
|
||||
whatsapp = false
|
||||
) => {
|
||||
assertTwilio(twilio);
|
||||
|
||||
const isSMSSendingLocked = await isLockedForSMSSending(userId, teamId);
|
||||
|
||||
if (isSMSSendingLocked) {
|
||||
log.debug(`${teamId ? `Team id ${teamId} ` : `User id ${userId} `} is locked for SMS sending `);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!teamId && userId) {
|
||||
await checkSMSRateLimit({
|
||||
identifier: `sms:user:${userId}`,
|
||||
rateLimitingType: "smsMonth",
|
||||
});
|
||||
}
|
||||
|
||||
const response = await twilio.messages.create({
|
||||
body: body,
|
||||
messagingServiceSid: process.env.TWILIO_MESSAGING_SID,
|
||||
@@ -48,9 +77,26 @@ export const scheduleSMS = async (
|
||||
body: string,
|
||||
scheduledDate: Date,
|
||||
sender: string,
|
||||
userId?: number | null,
|
||||
teamId?: number | null,
|
||||
whatsapp = false
|
||||
) => {
|
||||
assertTwilio(twilio);
|
||||
|
||||
const isSMSSendingLocked = await isLockedForSMSSending(userId, teamId);
|
||||
|
||||
if (isSMSSendingLocked) {
|
||||
log.debug(`${teamId ? `Team id ${teamId} ` : `User id ${userId} `} is locked for SMS sending `);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!teamId && userId) {
|
||||
await checkSMSRateLimit({
|
||||
identifier: `sms:user:${userId}`,
|
||||
rateLimitingType: "smsMonth",
|
||||
});
|
||||
}
|
||||
|
||||
const response = await twilio.messages.create({
|
||||
body: body,
|
||||
messagingServiceSid: process.env.TWILIO_MESSAGING_SID,
|
||||
@@ -90,3 +136,44 @@ export const verifyNumber = async (phoneNumber: string, code: string) => {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
async function isLockedForSMSSending(userId?: number | null, teamId?: number | null) {
|
||||
if (teamId) {
|
||||
const team = await prisma.team.findFirst({
|
||||
where: {
|
||||
id: teamId,
|
||||
},
|
||||
});
|
||||
return team?.smsLockState === SMSLockState.LOCKED;
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
const memberships = await prisma.membership.findMany({
|
||||
where: {
|
||||
userId: userId,
|
||||
},
|
||||
select: {
|
||||
team: {
|
||||
select: {
|
||||
smsLockState: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const memberOfLockedTeam = memberships.find(
|
||||
(membership) => membership.team.smsLockState === SMSLockState.LOCKED
|
||||
);
|
||||
|
||||
if (!!memberOfLockedTeam) {
|
||||
return true;
|
||||
}
|
||||
|
||||
const user = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: userId,
|
||||
},
|
||||
});
|
||||
return user?.smsLockState === SMSLockState.LOCKED;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,7 @@
|
||||
import type { Workflow, WorkflowsOnEventTypes, WorkflowStep } from "@prisma/client";
|
||||
|
||||
import {
|
||||
isSMSAction,
|
||||
isTextMessageToAttendeeAction,
|
||||
isWhatsappAction,
|
||||
} from "@calcom/features/ee/workflows/lib/actionHelperFunctions";
|
||||
import { isSMSAction, isWhatsappAction } from "@calcom/features/ee/workflows/lib/actionHelperFunctions";
|
||||
import { checkSMSRateLimit } from "@calcom/lib/checkRateLimitAndThrowError";
|
||||
import { SENDER_NAME } from "@calcom/lib/constants";
|
||||
import { WorkflowActions, WorkflowMethods, WorkflowTriggerEvents } from "@calcom/prisma/enums";
|
||||
import type { CalendarEvent } from "@calcom/types/Calendar";
|
||||
@@ -25,7 +22,6 @@ type ProcessWorkflowStepParams = {
|
||||
emailAttendeeSendToOverride?: string;
|
||||
hideBranding?: boolean;
|
||||
seatReferenceUid?: string;
|
||||
eventTypeRequiresConfirmation?: boolean;
|
||||
};
|
||||
|
||||
export interface ScheduleWorkflowRemindersArgs extends ProcessWorkflowStepParams {
|
||||
@@ -48,12 +44,14 @@ const processWorkflowStep = async (
|
||||
emailAttendeeSendToOverride,
|
||||
hideBranding,
|
||||
seatReferenceUid,
|
||||
eventTypeRequiresConfirmation,
|
||||
}: ProcessWorkflowStepParams
|
||||
) => {
|
||||
if (isTextMessageToAttendeeAction(step.action) && !eventTypeRequiresConfirmation) return;
|
||||
|
||||
if (isSMSAction(step.action)) {
|
||||
await checkSMSRateLimit({
|
||||
identifier: `sms:${workflow.teamId ? "team:" : "user:"}${workflow.teamId || workflow.userId}`,
|
||||
rateLimitingType: "sms",
|
||||
});
|
||||
|
||||
const sendTo = step.action === WorkflowActions.SMS_ATTENDEE ? smsReminderNumber : step.sendTo;
|
||||
await scheduleSMSReminder({
|
||||
evt,
|
||||
@@ -141,7 +139,6 @@ export const scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersA
|
||||
emailAttendeeSendToOverride = "",
|
||||
hideBranding,
|
||||
seatReferenceUid,
|
||||
eventTypeRequiresConfirmation = false,
|
||||
} = args;
|
||||
if (isNotConfirmed || !workflows.length) return;
|
||||
|
||||
@@ -173,7 +170,6 @@ export const scheduleWorkflowReminders = async (args: ScheduleWorkflowRemindersA
|
||||
smsReminderNumber,
|
||||
hideBranding,
|
||||
seatReferenceUid,
|
||||
eventTypeRequiresConfirmation,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -204,11 +200,10 @@ export interface SendCancelledRemindersArgs {
|
||||
smsReminderNumber: string | null;
|
||||
evt: ExtendedCalendarEvent;
|
||||
hideBranding?: boolean;
|
||||
eventTypeRequiresConfirmation?: boolean;
|
||||
}
|
||||
|
||||
export const sendCancelledReminders = async (args: SendCancelledRemindersArgs) => {
|
||||
const { workflows, smsReminderNumber, evt, hideBranding, eventTypeRequiresConfirmation } = args;
|
||||
const { workflows, smsReminderNumber, evt, hideBranding } = args;
|
||||
if (!workflows.length) return;
|
||||
|
||||
for (const workflowRef of workflows) {
|
||||
@@ -221,7 +216,6 @@ export const sendCancelledReminders = async (args: SendCancelledRemindersArgs) =
|
||||
smsReminderNumber,
|
||||
hideBranding,
|
||||
calendarEvent: evt,
|
||||
eventTypeRequiresConfirmation,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +86,7 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
|
||||
isVerificationPending = false,
|
||||
seatReferenceUid,
|
||||
} = args;
|
||||
|
||||
const { startTime, endTime } = evt;
|
||||
const uid = evt.uid as string;
|
||||
const currentDate = dayjs();
|
||||
@@ -184,7 +185,7 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
|
||||
triggerEvent === WorkflowTriggerEvents.RESCHEDULE_EVENT
|
||||
) {
|
||||
try {
|
||||
await twilio.sendSMS(reminderPhone, smsMessage, senderID);
|
||||
await twilio.sendSMS(reminderPhone, smsMessage, senderID, userId, teamId);
|
||||
} catch (error) {
|
||||
log.error(`Error sending SMS with error ${error}`);
|
||||
}
|
||||
@@ -203,20 +204,24 @@ export const scheduleSMSReminder = async (args: ScheduleTextReminderArgs) => {
|
||||
reminderPhone,
|
||||
smsMessage,
|
||||
scheduledDate.toDate(),
|
||||
senderID
|
||||
senderID,
|
||||
userId,
|
||||
teamId
|
||||
);
|
||||
|
||||
await prisma.workflowReminder.create({
|
||||
data: {
|
||||
bookingUid: uid,
|
||||
workflowStepId: workflowStepId,
|
||||
method: WorkflowMethods.SMS,
|
||||
scheduledDate: scheduledDate.toDate(),
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
seatReferenceId: seatReferenceUid,
|
||||
},
|
||||
});
|
||||
if (scheduledSMS) {
|
||||
await prisma.workflowReminder.create({
|
||||
data: {
|
||||
bookingUid: uid,
|
||||
workflowStepId: workflowStepId,
|
||||
method: WorkflowMethods.SMS,
|
||||
scheduledDate: scheduledDate.toDate(),
|
||||
scheduled: true,
|
||||
referenceId: scheduledSMS.sid,
|
||||
seatReferenceId: seatReferenceUid,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
log.error(`Error scheduling SMS with error ${error}`);
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
|
||||
isVerificationPending = false,
|
||||
seatReferenceUid,
|
||||
} = args;
|
||||
|
||||
const { startTime, endTime } = evt;
|
||||
const uid = evt.uid as string;
|
||||
const currentDate = dayjs();
|
||||
@@ -147,7 +148,7 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
|
||||
triggerEvent === WorkflowTriggerEvents.RESCHEDULE_EVENT
|
||||
) {
|
||||
try {
|
||||
await twilio.sendSMS(reminderPhone, textMessage, "", true);
|
||||
await twilio.sendSMS(reminderPhone, textMessage, "", userId, teamId, true);
|
||||
} catch (error) {
|
||||
console.log(`Error sending WHATSAPP with error ${error}`);
|
||||
}
|
||||
@@ -167,20 +168,24 @@ export const scheduleWhatsappReminder = async (args: ScheduleTextReminderArgs) =
|
||||
textMessage,
|
||||
scheduledDate.toDate(),
|
||||
"",
|
||||
userId,
|
||||
teamId,
|
||||
true
|
||||
);
|
||||
|
||||
await prisma.workflowReminder.create({
|
||||
data: {
|
||||
bookingUid: uid,
|
||||
workflowStepId: workflowStepId,
|
||||
method: WorkflowMethods.WHATSAPP,
|
||||
scheduledDate: scheduledDate.toDate(),
|
||||
scheduled: true,
|
||||
referenceId: scheduledWHATSAPP.sid,
|
||||
seatReferenceId: seatReferenceUid,
|
||||
},
|
||||
});
|
||||
if (scheduledWHATSAPP) {
|
||||
await prisma.workflowReminder.create({
|
||||
data: {
|
||||
bookingUid: uid,
|
||||
workflowStepId: workflowStepId,
|
||||
method: WorkflowMethods.WHATSAPP,
|
||||
scheduledDate: scheduledDate.toDate(),
|
||||
scheduled: true,
|
||||
referenceId: scheduledWHATSAPP.sid,
|
||||
seatReferenceId: seatReferenceUid,
|
||||
},
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`Error scheduling WHATSAPP with error ${error}`);
|
||||
}
|
||||
|
||||
@@ -119,6 +119,7 @@ const tabs: VerticalTabItemProps[] = [
|
||||
{ name: "apps", href: "/settings/admin/apps/calendar" },
|
||||
{ name: "users", href: "/settings/admin/users" },
|
||||
{ name: "organizations", href: "/settings/admin/organizations" },
|
||||
{ name: "lockedSMS", href: "/settings/admin/lockedSMS" },
|
||||
{ name: "oAuth", href: "/settings/admin/oAuth" },
|
||||
],
|
||||
},
|
||||
|
||||
@@ -107,6 +107,7 @@ const tabs: VerticalTabItemProps[] = [
|
||||
{ name: "apps", href: "/settings/admin/apps/calendar" },
|
||||
{ name: "users", href: "/settings/admin/users" },
|
||||
{ name: "organizations", href: "/settings/admin/organizations" },
|
||||
{ name: "lockedSMS", href: "/settings/admin/lockedSMS" },
|
||||
{ name: "oAuth", href: "/settings/admin/oAuth" },
|
||||
],
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user