cal.pub0.org/packages/features/ee/workflows/lib/actionHelperFunctions.ts

73 lines
2.2 KiB
TypeScript
Raw Normal View History

import type { WorkflowTriggerEvents } from "@prisma/client";
import { WorkflowActions, WorkflowTemplates } from "@prisma/client";
import type { TimeFormat } from "@calcom/lib/timeFormat";
2023-07-18 20:27:54 +00:00
import {
whatsappEventCancelledTemplate,
whatsappEventCompletedTemplate,
whatsappEventRescheduledTemplate,
whatsappReminderTemplate,
} from "../lib/reminders/templates/whatsapp";
export function isSMSAction(action: WorkflowActions) {
return action === WorkflowActions.SMS_ATTENDEE || action === WorkflowActions.SMS_NUMBER;
}
Allow editing workflow templates (#8028) * add event end time as variable * add timezone as new variable * add first version of template prefill * set template body when template is updated * set reminder template body and subject when creating workflow * set email subject when changes templates * save emailBody and emailsubject for all templates + fix duplicate template text * add more flexibility for templates * remove console.log * fix {ORAGANIZER} and {ATTENDEE} variable * make sure to always send reminder body and not default template * fix import * remove email body text and match variables in templates * handle translations of formatted variables * fix email reminder template * add cancel and reschedule link as variable * add cancel and reschedule link for scheduled emails/sms * make sure empty empty body and subject are set for reminder template * add info message for testing workflow * fix typo * add sms template * add migration to remove reminderBody and emailSubject * add branding * code clean up * add hide branding everywhere * fix sms reminder template * set sms reminder template if sms body is empty * fix custom inputs variables everywhere * fix variable translations + other small fixes * fix some type errors * fix more type errors * fix everything missing around cron job scheduling * make sure to always use custom template for sms messages * fix type error * code clean up * rename link to url * Add debug logs * Update handleNewBooking.ts * Add debug logs * removed unneded responses * fix booking questions + UI improvements * remove html email body when changing to sms action * code clean up + comments * code clean up * code clean up * remove comment * more clear info message for timezone variable --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: alannnc <alannnc@gmail.com>
2023-04-18 10:08:09 +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);
}
Allow editing workflow templates (#8028) * add event end time as variable * add timezone as new variable * add first version of template prefill * set template body when template is updated * set reminder template body and subject when creating workflow * set email subject when changes templates * save emailBody and emailsubject for all templates + fix duplicate template text * add more flexibility for templates * remove console.log * fix {ORAGANIZER} and {ATTENDEE} variable * make sure to always send reminder body and not default template * fix import * remove email body text and match variables in templates * handle translations of formatted variables * fix email reminder template * add cancel and reschedule link as variable * add cancel and reschedule link for scheduled emails/sms * make sure empty empty body and subject are set for reminder template * add info message for testing workflow * fix typo * add sms template * add migration to remove reminderBody and emailSubject * add branding * code clean up * add hide branding everywhere * fix sms reminder template * set sms reminder template if sms body is empty * fix custom inputs variables everywhere * fix variable translations + other small fixes * fix some type errors * fix more type errors * fix everything missing around cron job scheduling * make sure to always use custom template for sms messages * fix type error * code clean up * rename link to url * Add debug logs * Update handleNewBooking.ts * Add debug logs * removed unneded responses * fix booking questions + UI improvements * remove html email body when changing to sms action * code clean up + comments * code clean up * code clean up * remove comment * more clear info message for timezone variable --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: alannnc <alannnc@gmail.com>
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
);
}
export function getWhatsappTemplateForTrigger(trigger: WorkflowTriggerEvents): WorkflowTemplates {
2023-07-18 20:27:54 +00:00
switch (trigger) {
case "NEW_EVENT":
case "BEFORE_EVENT":
2023-07-18 20:27:54 +00:00
return WorkflowTemplates.REMINDER;
case "AFTER_EVENT":
2023-07-18 20:27:54 +00:00
return WorkflowTemplates.COMPLETED;
case "EVENT_CANCELLED":
2023-07-18 20:27:54 +00:00
return WorkflowTemplates.CANCELLED;
case "RESCHEDULE_EVENT":
2023-07-18 20:27:54 +00:00
return WorkflowTemplates.RESCHEDULED;
default:
2023-07-18 20:27:54 +00:00
return WorkflowTemplates.REMINDER;
}
}
export function getWhatsappTemplateFunction(template: WorkflowTemplates): typeof whatsappReminderTemplate {
2023-07-18 20:27:54 +00:00
switch (template) {
case "CANCELLED":
2023-07-18 20:27:54 +00:00
return whatsappEventCancelledTemplate;
case "COMPLETED":
2023-07-18 20:27:54 +00:00
return whatsappEventCompletedTemplate;
case "RESCHEDULED":
2023-07-18 20:27:54 +00:00
return whatsappEventRescheduledTemplate;
case "CUSTOM":
case "REMINDER":
2023-07-18 20:27:54 +00:00
return whatsappReminderTemplate;
default:
2023-07-18 20:27:54 +00:00
return whatsappReminderTemplate;
}
}
2023-07-18 20:27:54 +00:00
export function getWhatsappTemplateForAction(
action: WorkflowActions,
template: WorkflowTemplates,
timeFormat: TimeFormat
2023-07-18 20:27:54 +00:00
): string | null {
const templateFunction = getWhatsappTemplateFunction(template);
return templateFunction(true, action, timeFormat);
Allow editing workflow templates (#8028) * add event end time as variable * add timezone as new variable * add first version of template prefill * set template body when template is updated * set reminder template body and subject when creating workflow * set email subject when changes templates * save emailBody and emailsubject for all templates + fix duplicate template text * add more flexibility for templates * remove console.log * fix {ORAGANIZER} and {ATTENDEE} variable * make sure to always send reminder body and not default template * fix import * remove email body text and match variables in templates * handle translations of formatted variables * fix email reminder template * add cancel and reschedule link as variable * add cancel and reschedule link for scheduled emails/sms * make sure empty empty body and subject are set for reminder template * add info message for testing workflow * fix typo * add sms template * add migration to remove reminderBody and emailSubject * add branding * code clean up * add hide branding everywhere * fix sms reminder template * set sms reminder template if sms body is empty * fix custom inputs variables everywhere * fix variable translations + other small fixes * fix some type errors * fix more type errors * fix everything missing around cron job scheduling * make sure to always use custom template for sms messages * fix type error * code clean up * rename link to url * Add debug logs * Update handleNewBooking.ts * Add debug logs * removed unneded responses * fix booking questions + UI improvements * remove html email body when changing to sms action * code clean up + comments * code clean up * code clean up * remove comment * more clear info message for timezone variable --------- Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Hariom Balhara <hariombalhara@gmail.com> Co-authored-by: zomars <zomars@me.com> Co-authored-by: alannnc <alannnc@gmail.com>
2023-04-18 10:08:09 +00:00
}