2023-07-11 15:48:44 +00:00
|
|
|
import { WorkflowActions, WorkflowTemplates, WorkflowTriggerEvents } from "@prisma/client";
|
|
|
|
import { whatsappEventCancelledTemplate, whatsappEventCompletedTemplate, whatsappEventRescheduledTemplate, whatsappReminderTemplate } from "../lib/reminders/templates/whatsapp";
|
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) {
|
|
|
|
return isSMSAction(action) || isWhatsappAction(action)
|
|
|
|
}
|
|
|
|
|
2023-04-18 10:08:09 +00:00
|
|
|
export function isAttendeeAction(action: WorkflowActions) {
|
2023-07-11 15:48:44 +00:00
|
|
|
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.EMAIL_ATTENDEE || action === WorkflowActions.WHATSAPP_ATTENDEE;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWhatsappTemplateForTrigger(trigger: WorkflowTriggerEvents): WorkflowTemplates {
|
|
|
|
switch(trigger) {
|
|
|
|
case "NEW_EVENT":
|
|
|
|
case "BEFORE_EVENT":
|
|
|
|
return WorkflowTemplates.REMINDER
|
|
|
|
case "AFTER_EVENT":
|
|
|
|
return WorkflowTemplates.COMPLETED
|
|
|
|
case "EVENT_CANCELLED":
|
|
|
|
return WorkflowTemplates.CANCELLED
|
|
|
|
case "RESCHEDULE_EVENT":
|
|
|
|
return WorkflowTemplates.RESCHEDULED
|
|
|
|
default:
|
|
|
|
return WorkflowTemplates.REMINDER
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWhatsappTemplateFunction(template: WorkflowTemplates): typeof whatsappReminderTemplate {
|
|
|
|
switch(template) {
|
|
|
|
case "CANCELLED":
|
|
|
|
return whatsappEventCancelledTemplate
|
|
|
|
case "COMPLETED":
|
|
|
|
return whatsappEventCompletedTemplate
|
|
|
|
case "RESCHEDULED":
|
|
|
|
return whatsappEventRescheduledTemplate
|
|
|
|
case "CUSTOM":
|
|
|
|
case "REMINDER":
|
|
|
|
return whatsappReminderTemplate
|
|
|
|
default:
|
|
|
|
return whatsappReminderTemplate
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export function getWhatsappTemplateForAction(action: WorkflowActions, template: WorkflowTemplates): string | null {
|
|
|
|
const templateFunction = getWhatsappTemplateFunction(template)
|
|
|
|
return templateFunction(true, action)
|
2023-04-18 10:08:09 +00:00
|
|
|
}
|