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
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
6971726fc9
commit
15890cc138
@ -34,27 +34,5 @@
|
|||||||
"button_index": 0,
|
"button_index": 0,
|
||||||
"param_key": "event_id"
|
"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": ""
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,49 +74,21 @@ def _fix_template_parameters():
|
|||||||
import json
|
import json
|
||||||
db = SessionLocal()
|
db = SessionLocal()
|
||||||
try:
|
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.template_key == 'hina_invitation') |
|
||||||
(models.WhatsAppTemplate.meta_name == 'hina_invitation')
|
(models.WhatsAppTemplate.meta_name == 'hina_invitation')
|
||||||
).first()
|
).all()
|
||||||
|
|
||||||
if template:
|
if old_templates:
|
||||||
# Expected correct parameters for hina_invitation
|
print(f"[startup] Removing old custom hina_invitation templates from database...")
|
||||||
# Body {{1}} = contact_name (guest's name in greeting)
|
for old_tpl in old_templates:
|
||||||
# Button {{1}} = event_id (sent as separate button parameter in URL)
|
print(f" Deleting: {old_tpl.template_key} (had {old_tpl.body_params} params)")
|
||||||
expected_params = ["contact_name"]
|
db.delete(old_tpl)
|
||||||
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()
|
db.commit()
|
||||||
print(f" ✓ Template fixed!")
|
print(f" ✓ Old templates removed - hina_invitation is now built-in only!")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[startup] Template fix warning: {e}")
|
print(f"[startup] Template cleanup warning: {e}")
|
||||||
finally:
|
finally:
|
||||||
db.close()
|
db.close()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user