feat: office address, multi-template SMS manager, hardcoded defaults with auto-seed

- Add streetAddress/city/state/zipCode fields to OfficeContact (schema + storage + UI)
- Support {officeAddress} variable in batch reminder SMS
- Replace single SMS template field with full CRUD template list (add/rename/edit/delete)
- Store SMS template list under _sms_template_list; first template synced to batch reminder
- Hardcode all AI chat template defaults into codebase (reminder SMS, greetings, fallback)
- Add seed-templates.ts that auto-seeds default templates for all users on server boot
- Update README: note that templates are auto-configured on first boot

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Gitead
2026-05-11 23:18:04 -04:00
parent 11244ace7f
commit 7929dc6e19
56 changed files with 763 additions and 46 deletions

View File

@@ -22,7 +22,7 @@ router.put("/", async (req: Request, res: Response): Promise<any> => {
const userId = req.user?.id;
if (!userId) return res.status(401).json({ message: "Unauthorized" });
const { officeName, receptionistName, dentistName, phoneNumber, email, fax } = req.body;
const { officeName, receptionistName, dentistName, phoneNumber, email, fax, streetAddress, city, state, zipCode } = req.body;
const record = await storage.upsertOfficeContact(userId, {
officeName: officeName ?? undefined,
receptionistName: receptionistName ?? undefined,
@@ -30,6 +30,10 @@ router.put("/", async (req: Request, res: Response): Promise<any> => {
phoneNumber: phoneNumber ?? undefined,
email: email ?? undefined,
fax: fax ?? undefined,
streetAddress: streetAddress ?? undefined,
city: city ?? undefined,
state: state ?? undefined,
zipCode: zipCode ?? undefined,
});
return res.status(200).json(record);
} catch (err) {

View File

@@ -132,13 +132,19 @@ router.post("/send-reminders-batch", async (req: Request, res: Response): Promis
return res.status(400).json({ message: "Twilio is not configured. Please add your Twilio credentials in Settings." });
}
// Resolve office name and reminder SMS template
// Resolve office name, address, and reminder SMS template
const officeContact = await storage.getOfficeContact(userId);
const officeName = (officeContact as any)?.officeName?.trim() || "";
const officeAddress = [
(officeContact as any)?.streetAddress?.trim(),
(officeContact as any)?.city?.trim(),
(officeContact as any)?.state?.trim(),
(officeContact as any)?.zipCode?.trim(),
].filter(Boolean).join(", ");
const chatTemplates = await storage.getAiChatTemplates(userId);
const DEFAULT_REMINDER_SMS =
"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!";
"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!";
const templateBody = chatTemplates.reminderSms?.trim() || DEFAULT_REMINDER_SMS;
// Fetch appointments for the selected staff columns on the given date
@@ -187,6 +193,7 @@ router.post("/send-reminders-batch", async (req: Request, res: Response): Promis
const message = templateBody
.replace(/\{firstName\}/g, patient.firstName ?? "")
.replace(/\{officeName\}/g, officeName)
.replace(/\{officeAddress\}/g, officeAddress)
.replace(/\{appointmentDate\}/g, apptDate)
.replace(/\{appointmentTime\}/g, apptTime)
.replace(/\{date\}/g, apptDate)
@@ -222,6 +229,32 @@ router.post("/send-reminders-batch", async (req: Request, res: Response): Promis
}
});
// GET /api/twilio/sms-template-list
router.get("/sms-template-list", async (req: Request, res: Response): Promise<any> => {
try {
const userId = req.user?.id;
if (!userId) return res.status(401).json({ message: "Unauthorized" });
const list = await storage.getSmsTemplateList(userId);
return res.status(200).json(list);
} catch (err) {
return res.status(500).json({ error: "Failed to fetch SMS templates", details: String(err) });
}
});
// PUT /api/twilio/sms-template-list
router.put("/sms-template-list", async (req: Request, res: Response): Promise<any> => {
try {
const userId = req.user?.id;
if (!userId) return res.status(401).json({ message: "Unauthorized" });
const templates = req.body;
if (!Array.isArray(templates)) return res.status(400).json({ message: "Expected an array of templates" });
await storage.saveSmsTemplateList(userId, templates);
return res.status(200).json({ ok: true });
} catch (err) {
return res.status(500).json({ error: "Failed to save SMS templates", details: String(err) });
}
});
// GET /api/twilio/templates
router.get("/templates", async (req: Request, res: Response): Promise<any> => {
try {