feat: queue donor WhatsApp confirmations

This commit is contained in:
Replit Agent
2026-06-06 22:27:47 +03:00
parent 94ccbf6fe4
commit a69da41f98
4 changed files with 101 additions and 0 deletions
+39
View File
@@ -77,6 +77,45 @@ export interface WhatsappLogEntry {
createdAt: string;
}
// Outbound WhatsApp "thank the donor" notifications, fired right after a
// successful donation. They are queued here (in-memory) and picked up by an
// external poller (OpenClaw) that actually sends the WhatsApp message and then
// marks the row as sent. Resets on container restart like all mock data.
export interface DonorNotification {
id: string;
caseId: string;
donorName: string;
donorPhone: string; // normalized to international form, e.g. 9665XXXXXXXX
message: string;
status: WhatsappStatus; // pending | sent | failed
sentAt: string | null;
createdAt: string;
}
// Fixed Arabic confirmation message sent to the donor after a successful
// donation. This is an outbound WhatsApp message (not in-app UI text), so it is
// intentionally a single fixed string and does not go through LanguageContext.
export const DONOR_THANK_YOU_MESSAGE =
"إحسانك يُثمر وعطاؤك يعين ..\n\nتمت عملية تبرعك عبر منصة إحسان بنجاح\n\n(والله يحب المحسنين)";
export const donorNotifications: DonorNotification[] = [];
// Normalize a Saudi phone number to WhatsApp international form.
// 05XXXXXXXX -> 9665XXXXXXXX
// 5XXXXXXXX -> 9665XXXXXXXX
// 9665XXXXXXXX -> 9665XXXXXXXX (unchanged)
// +966 5XXXXXXXX -> 9665XXXXXXXX
// Returns digits only (no '+'). Falls back to the cleaned digits if the shape
// is unexpected, so we never throw inside the donation flow.
export function normalizeSaudiPhone(raw: string): string {
const digits = String(raw || "").replace(/\D/g, "");
if (!digits) return "";
if (digits.startsWith("966")) return digits;
if (digits.startsWith("0")) return "966" + digits.slice(1);
if (digits.startsWith("5") && digits.length === 9) return "966" + digits;
return digits;
}
// ─── Eligibility Database ───────────────────────────────────────────────────
export const eligibilityDb: EligibilityRecord[] = [
{ nationalId: "1090512345", eligible: true },