diff --git a/apps/Frontend/src/components/settings/ai-chat-templates-card.tsx b/apps/Frontend/src/components/settings/ai-chat-templates-card.tsx index f08f1001..fbe48d30 100644 --- a/apps/Frontend/src/components/settings/ai-chat-templates-card.tsx +++ b/apps/Frontend/src/components/settings/ai-chat-templates-card.tsx @@ -19,23 +19,35 @@ type OfficeContact = { officeName?: string | null; }; +const SUPPORTED_SMS_VARS = [ + "{firstName}", "{officeName}", "{appointmentDate}", "{appointmentTime}", "{date}", "{time}", +] as const; + const DEFAULTS = { reminderSms: - "Hi {firstName}, this is a reminder from {officeName}. You have an appointment on {appointmentDate} at {appointmentTime}. Please come to our office at {officeAddress}. Please reply YES to confirm or NO to reschedule. Thank you!", + "Hi {firstName}, this is a reminder from {officeName}. You have an appointment on {appointmentDate} at {appointmentTime}. Please reply YES to confirm or NO to reschedule. Thank you!", reminderGreeting: - "Hi! My name is Lisa, the dedicated AI assistant at {officeName}. I can confirm or reschedule your appointment and answer general questions 24/7. I will reply you message at any time you need.", + "Hi! My name is Lisa, the dedicated AI assistant at {officeName}. I can confirm or reschedule your appointment and answer general questions 24/7. I will reply to your message at any time you need.", newPatientGreeting: "Hi! My name is Lisa, the dedicated AI assistant at {officeName}. I can help you schedule an appointment, check your insurance, and answer general questions 24/7. How can I help you today?", generalFallback: "Hi! My name is Lisa, the dedicated AI assistant at {officeName}. How can I help you today?", rescheduleGreeting: - "Hi! My name is Lisa, the dedicated AI assistant at {officeName}. I can help you find a new appointment time that works for you. Would you like to reschedule your appointment?", + "It is understandable! When would you like to reschedule your appointment?", }; function preview(text: string, officeName: string) { return text.replace(/\{officeName\}/g, officeName || "your dental office"); } +/** Returns any {variable} tokens in `text` that are not in the supported list. */ +function unsupportedVars(text: string): string[] { + const found = text.match(/\{[^}]+\}/g) ?? []; + return [...new Set(found)].filter( + (v) => !(SUPPORTED_SMS_VARS as readonly string[]).includes(v) + ); +} + export function AiChatTemplatesCard() { const { toast } = useToast(); @@ -115,7 +127,7 @@ export function AiChatTemplatesCard() { key: "reminderSms" as const, icon: , label: "Reminder SMS Text", - description: "Outgoing text sent from the Schedule page. Supports: {firstName}, {officeName}, {appointmentDate}, {appointmentTime}.", + description: "Outgoing text sent from the Schedule page. Supported variables: {firstName}, {officeName}, {appointmentDate}, {appointmentTime}, {date}, {time}. Any other {variable} will be sent as plain text.", value: reminderSms, onChange: setReminderSms, placeholder: DEFAULTS.reminderSms, @@ -190,28 +202,42 @@ export function AiChatTemplatesCard() {

Loading templates...

) : (
- {templates_list.map((t) => ( -
-
- {t.icon} - {t.label} + {templates_list.map((t) => { + const badVars = t.key === "reminderSms" ? unsupportedVars(t.value) : []; + return ( +
+
+ {t.icon} + {t.label} +
+

{t.description}

+