From 15890cc1384d4feb2f56976ae80cf0642e27341e Mon Sep 17 00:00:00 2001 From: dvirlabs <114520947+dvirlabs@users.noreply.github.com> Date: Thu, 14 May 2026 09:44:24 +0300 Subject: [PATCH] Remove hina_invitation from custom templates - use built-in only, auto-delete old DB records --- backend/custom_templates.json | 22 --------------- backend/main.py | 50 ++++++++--------------------------- 2 files changed, 11 insertions(+), 61 deletions(-) diff --git a/backend/custom_templates.json b/backend/custom_templates.json index c11ee35..c31743b 100644 --- a/backend/custom_templates.json +++ b/backend/custom_templates.json @@ -34,27 +34,5 @@ "button_index": 0, "param_key": "event_id" } - }, - "hina_invitation": { - "meta_name": "hina_invitation", - "language_code": "he", - "friendly_name": "הזמנה לחינה", - "description": "הזמנה לאירוע חינה עם שם אישי וקישור דינמי", - "header_type": "TEXT", - "header_text": "", - "header_params": [], - "body_text": "היי {{1}} 🤍\n\nמוזמנת לחינה שלנו!\n\nרק בנות ✨\nארוחה חלבית\n\nנשמח לאישור הגעה בקישור המצורף 🙏", - "body_params": [ - "contact_name" - ], - "button_type": "URL", - "button_url": "https://invy.dvirlabs.com/guest/{{1}}", - "button_text": "הצבע על הזמנה", - "button_param_key": "event_id", - "fallbacks": { - "contact_name": "חבר", - "event_id": "event-id" - }, - "guest_name_key": "" } } \ No newline at end of file diff --git a/backend/main.py b/backend/main.py index 68d09a5..2422b13 100644 --- a/backend/main.py +++ b/backend/main.py @@ -74,49 +74,21 @@ def _fix_template_parameters(): import json db = SessionLocal() try: - template = db.query(models.WhatsAppTemplate).filter( + # First, delete any old custom hina_invitation records (it's now built-in only) + old_templates = db.query(models.WhatsAppTemplate).filter( (models.WhatsAppTemplate.template_key == 'hina_invitation') | (models.WhatsAppTemplate.meta_name == 'hina_invitation') - ).first() + ).all() - if template: - # Expected correct parameters for hina_invitation - # Body {{1}} = contact_name (guest's name in greeting) - # Button {{1}} = event_id (sent as separate button parameter in URL) - expected_params = ["contact_name"] - expected_button_param_key = "event_id" - - try: - current_params = json.loads(template.body_params) - except: - current_params = [] - - needs_fixing = False - - # Check if body parameters need fixing - if current_params != expected_params: - print(f"[startup] Fixing hina_invitation template body parameters...") - print(f" Old: {current_params}") - print(f" New: {expected_params}") - template.body_params = json.dumps(expected_params) - needs_fixing = True - - # Check if button parameter key is set correctly - if not template.button_param_key or template.button_param_key != expected_button_param_key: - print(f"[startup] Setting hina_invitation button parameter...") - template.button_param_key = expected_button_param_key - needs_fixing = True - - # Check header type - if not template.header_type: - template.header_type = "TEXT" - needs_fixing = True - - if needs_fixing: - db.commit() - print(f" ✓ Template fixed!") + if old_templates: + print(f"[startup] Removing old custom hina_invitation templates from database...") + for old_tpl in old_templates: + print(f" Deleting: {old_tpl.template_key} (had {old_tpl.body_params} params)") + db.delete(old_tpl) + db.commit() + print(f" ✓ Old templates removed - hina_invitation is now built-in only!") except Exception as e: - print(f"[startup] Template fix warning: {e}") + print(f"[startup] Template cleanup warning: {e}") finally: db.close()