Step 1 – Update lia_rules.py 1. Open app/lia_rules.py. 2. Under the LIA_EOT_INTROS dictionary, add this helper function: def select_eot_intro(payments_remaining: int | None) -> str | None: """ Choose the correct end-of-term intro based on payments remaining. Returns one of the LIA_EOT_INTROS values or None if not applicable. """ if payments_remaining is None: return None try: pr = int(payments_remaining) except (TypeError, ValueError): return None if pr >= 10: return LIA_EOT_INTROS["EOT_12"] elif pr >= 7: return LIA_EOT_INTROS["EOT_9"] elif pr >= 4: return LIA_EOT_INTROS["EOT_6"] else: return LIA_EOT_INTROS["EOT_3"] 3. Save the file. Step 2 – Extend the LiaInbound model 4. Open app/lia_inbound.py. 5. Find the LiaInbound BaseModel definition and add an optional payments_remaining field: class LiaInbound(BaseModel): from_number: str body: str channel: str | None = "whatsapp" conversation_id: str | None = None payments_remaining: int | None = None 6. Make sure any imports of LiaInbound still work (no changes needed elsewhere for this step). Step 3 – Import the new helper 7. At the top of app/lia_inbound.py, where other symbols are imported from lia_rules, update the import so it includes select_eot_intro, for example: from app.lia_rules import ( LIA_TIER_BEHAVIOUR, LIA_TONE_GUIDELINES, classify_inbound_tier, select_eot_intro, ) If the import is currently a single-line import, you can simply add select_eot_intro to the end of it. Step 4 – Use the intros when tier is T1_GENERAL 8. Still in app/lia_inbound.py, inside process_inbound_message, find where the body is lower-cased and the tier is set. It will look similar to: body_lower = payload.body.lower() tier = classify_inbound_tier(body_lower) 9. Immediately after that, add: eot_intro = select_eot_intro(payload.payments_remaining) 10. Next, find the code block where the template reply is chosen from LIA_TIER_BEHAVIOUR and assigned to reply. It will look something like: template = LIA_TIER_BEHAVIOUR[tier] response_text = template["example_reply"] final_reply = response_text reply = final_reply 11. Replace that block with this logic: template = LIA_TIER_BEHAVIOUR[tier] if eot_intro and tier == "T1_GENERAL": final_reply = eot_intro else: final_reply = template["example_reply"] reply = final_reply 12. Do NOT change any of the existing logic that: - updates conversation status to 'paused' or 'dnc' - sets defer_until - inserts into dp_messages Only change the part that decides what text goes into reply. 13. Save the file.