2023-07-19 14:30:37 +00:00
|
|
|
import type { WorkflowTriggerEvents } from "@prisma/client";
|
|
|
|
|
|
|
|
import type { TimeFormat } from "@calcom/lib/timeFormat";
|
2023-08-02 09:35:48 +00:00
|
|
|
import { WorkflowActions, WorkflowTemplates } from "@calcom/prisma/enums";
|
2023-07-18 20:27:54 +00:00
|
|
|
|
|
|
|
import {
|
|
|
|
whatsappEventCancelledTemplate,
|
|
|
|
whatsappEventCompletedTemplate,
|
|
|
|
whatsappEventRescheduledTemplate,
|
|
|
|
whatsappReminderTemplate,
|
|
|
|
} from "../lib/reminders/templates/whatsapp";
|
2023-01-18 14:32:39 +00:00
|
|
|
|
2023-08-02 09:35:48 +00:00
|
|
|
export function shouldScheduleEmailReminder(action: WorkflowActions) {
|
|
|
|
return action === WorkflowActions.EMAIL_ATTENDEE || action === WorkflowActions.EMAIL_HOST;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function shouldScheduleSMSReminder(action: WorkflowActions) {
|
|
|
|
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.SMS_NUMBER;
|
|
|
|
}
|
|
|
|
|
2023-01-18 14:32:39 +00:00
|
|
|
export function isSMSAction(action: WorkflowActions) {
|
|
|
|
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.SMS_NUMBER;
|
|
|
|
}
|
2023-04-18 10:08:09 +00:00
|
|
|
|
2023-07-11 15:48:44 +00:00
|
|
|
export function isWhatsappAction(action: WorkflowActions) {
|
|
|
|
return action === WorkflowActions.WHATSAPP_NUMBER || action === WorkflowActions.WHATSAPP_ATTENDEE;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isSMSOrWhatsappAction(action: WorkflowActions) {
|
2023-07-18 20:27:54 +00:00
|
|
|
return isSMSAction(action) || isWhatsappAction(action);
|
2023-07-11 15:48:44 +00:00
|
|
|
}
|
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
export function isAttendeeAction(action: WorkflowActions) {
|
2023-07-18 20:27:54 +00:00
|
|
|
return (
|
|
|
|
action === WorkflowActions.SMS_ATTENDEE ||
|
|
|
|
action === WorkflowActions.EMAIL_ATTENDEE ||
|
|
|
|
action === WorkflowActions.WHATSAPP_ATTENDEE
|
|
|
|
);
|
2023-07-11 15:48:44 +00:00
|
|
|
}
|
|
|
|
|
2023-08-10 18:52:36 +00:00
|
|
|
export function isTextMessageToAttendeeAction(action?: WorkflowActions) {
|
|
|
|
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.WHATSAPP_ATTENDEE;
|
|
|
|
}
|
|
|
|
|
2023-07-11 15:48:44 +00:00
|
|
|
export function getWhatsappTemplateForTrigger(trigger: WorkflowTriggerEvents): WorkflowTemplates {
|
2023-07-18 20:27:54 +00:00
|
|
|
switch (trigger) {
|
2023-07-11 15:48:44 +00:00
|
|
|
case "NEW_EVENT":
|
|
|
|
case "BEFORE_EVENT":
|
2023-07-18 20:27:54 +00:00
|
|
|
return WorkflowTemplates.REMINDER;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "AFTER_EVENT":
|
2023-07-18 20:27:54 +00:00
|
|
|
return WorkflowTemplates.COMPLETED;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "EVENT_CANCELLED":
|
2023-07-18 20:27:54 +00:00
|
|
|
return WorkflowTemplates.CANCELLED;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "RESCHEDULE_EVENT":
|
2023-07-18 20:27:54 +00:00
|
|
|
return WorkflowTemplates.RESCHEDULED;
|
2023-07-11 15:48:44 +00:00
|
|
|
default:
|
2023-07-18 20:27:54 +00:00
|
|
|
return WorkflowTemplates.REMINDER;
|
2023-07-11 15:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWhatsappTemplateFunction(template: WorkflowTemplates): typeof whatsappReminderTemplate {
|
2023-07-18 20:27:54 +00:00
|
|
|
switch (template) {
|
2023-07-11 15:48:44 +00:00
|
|
|
case "CANCELLED":
|
2023-07-18 20:27:54 +00:00
|
|
|
return whatsappEventCancelledTemplate;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "COMPLETED":
|
2023-07-18 20:27:54 +00:00
|
|
|
return whatsappEventCompletedTemplate;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "RESCHEDULED":
|
2023-07-18 20:27:54 +00:00
|
|
|
return whatsappEventRescheduledTemplate;
|
2023-07-11 15:48:44 +00:00
|
|
|
case "CUSTOM":
|
|
|
|
case "REMINDER":
|
2023-07-18 20:27:54 +00:00
|
|
|
return whatsappReminderTemplate;
|
2023-07-11 15:48:44 +00:00
|
|
|
default:
|
2023-07-18 20:27:54 +00:00
|
|
|
return whatsappReminderTemplate;
|
2023-07-11 15:48:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-18 20:27:54 +00:00
|
|
|
export function getWhatsappTemplateForAction(
|
|
|
|
action: WorkflowActions,
|
2023-07-19 14:30:37 +00:00
|
|
|
template: WorkflowTemplates,
|
|
|
|
timeFormat: TimeFormat
|
2023-07-18 20:27:54 +00:00
|
|
|
): string | null {
|
|
|
|
const templateFunction = getWhatsappTemplateFunction(template);
|
2023-07-19 14:30:37 +00:00
|
|
|
return templateFunction(true, action, timeFormat);
|
2023-04-18 10:08:09 +00:00
|
|
|
}
|