Remove hina_invitation from custom templates - use built-in only, auto-delete old DB records
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
dvirlabs 2026-05-14 09:44:24 +03:00
parent 6971726fc9
commit 15890cc138
2 changed files with 11 additions and 61 deletions

View File

@ -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": ""
}
}

View File

@ -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:
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"Template fixed!")
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()