fix: prevent double self-introduction in reschedule MSG 2
- reminder-graph: add stripIntroFromFallback() to remove 'Hi! My name is Lisa...' from any saved rescheduleGreeting template before using it as the MSG 2 fallback - reminder-graph: add explicit 'Do NOT introduce yourself' to rescheduleNode Gemini prompt so the AI never adds its own intro to MSG 2 - ai-chat-templates-card: add hasIntroPattern() warning on the Reschedule Patients template field — shows an amber alert if the saved template starts with a self-introduction, guiding users to remove it Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -48,6 +48,11 @@ function unsupportedVars(text: string): string[] {
|
||||
);
|
||||
}
|
||||
|
||||
/** True if text starts with a self-introduction ("Hi! My name is Lisa…"). */
|
||||
function hasIntroPattern(text: string): boolean {
|
||||
return /^(Hi[!,]?\s*)?(My name is|I'?m|I am)\s+/i.test(text.trim());
|
||||
}
|
||||
|
||||
export function AiChatTemplatesCard() {
|
||||
const { toast } = useToast();
|
||||
|
||||
@@ -203,7 +208,9 @@ export function AiChatTemplatesCard() {
|
||||
) : (
|
||||
<form onSubmit={handleSubmit} className="space-y-6">
|
||||
{templates_list.map((t) => {
|
||||
const badVars = t.key === "reminderSms" ? unsupportedVars(t.value) : [];
|
||||
const badVars = t.key === "reminderSms" ? unsupportedVars(t.value) : [];
|
||||
const hasIntro = t.key === "reschedule" && hasIntroPattern(t.value);
|
||||
const hasWarn = badVars.length > 0 || hasIntro;
|
||||
return (
|
||||
<div key={t.key} className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
@@ -216,7 +223,7 @@ export function AiChatTemplatesCard() {
|
||||
onChange={(e) => t.onChange(e.target.value)}
|
||||
placeholder={t.placeholder}
|
||||
rows={3}
|
||||
className={`text-sm resize-none ${badVars.length ? "border-amber-400 focus-visible:ring-amber-400" : ""}`}
|
||||
className={`text-sm resize-none ${hasWarn ? "border-amber-400 focus-visible:ring-amber-400" : ""}`}
|
||||
/>
|
||||
{/* Unsupported variable warning */}
|
||||
{badVars.length > 0 && (
|
||||
@@ -229,6 +236,18 @@ export function AiChatTemplatesCard() {
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{/* Self-intro warning for reschedule greeting */}
|
||||
{hasIntro && (
|
||||
<div className="flex items-start gap-2 rounded-md bg-amber-50 border border-amber-300 px-3 py-2 text-xs text-amber-800">
|
||||
<span className="mt-0.5">⚠️</span>
|
||||
<span>
|
||||
This template starts with a self-introduction ("Hi! My name is Lisa…").
|
||||
The AI introduction is already sent as a <strong>separate first message</strong> —
|
||||
this template is only used as the <strong>second message</strong> (the intent response).
|
||||
Remove the intro to avoid the patient receiving "My name is Lisa…" twice.
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{/* Live preview */}
|
||||
{officeName && t.value.includes("{officeName}") && (
|
||||
<p className="text-xs text-muted-foreground italic pl-1">
|
||||
|
||||
Reference in New Issue
Block a user