1. Open the file app/lia_rules.py. 2. At the bottom of the file, define a new function: def classify_inbound_tier(body_lower: str) -> str: """ Classify an inbound message body (already lower-cased) into a LIA tier: - T3_HARD_STOP - T4_SCHEDULED - T5_MONEY - T2_SOFT_OBJECTION - T6_SUPPORT - T1_GENERAL (default) The order of checks matters: strongest intent should be caught first. """ # Tier 3: hard stops / do-not-contact hard_stop_keywords = [ "stop", "do not contact", "dont contact", "remove my details", "remove my data", "leave it", "not interested", "go away", "unsubscribe", "take me off", ] for k in hard_stop_keywords: if k in body_lower: return "T3_HARD_STOP" # Tier 4: time-based follow-up scheduled_keywords = [ "next week", "next month", "in a few weeks", "in a couple of weeks", "in a couple of months", "later this year", "towards the end of the year", "try me again", "reach out nearer the time", "contact me in", ] for k in scheduled_keywords: if k in body_lower: return "T4_SCHEDULED" # Tier 5: money / price / payment objections money_keywords = [ "too expensive", "too dear", "too much", "too high", "cant afford", "can't afford", "afford it", "payment is too", "monthly is too", "need it cheaper", "need cheaper", "price is too", ] for k in money_keywords: if k in body_lower: return "T5_MONEY" # Tier 2: soft objections / hesitations soft_objection_keywords = [ "not right now", "not right just now", "bit busy", "i'm busy", "im busy", "maybe later", "maybe in a few weeks", "maybe in a few months", "not urgent", "not a priority", "leave it for now", "ill leave it for now", "i'll leave it for now", "need to think", "need to have a think", "thinking about it", "not sure", "unsure", ] for k in soft_objection_keywords: if k in body_lower: return "T2_SOFT_OBJECTION" # Tier 6: support / service / repair / mot style queries support_keywords = [ "service", "mot", "repair", "courtesy car", "courtesy", "update on my car", "update on the car", "in the workshop", "warning light", "light on the dash", "breakdown", ] for k in support_keywords: if k in body_lower: return "T6_SUPPORT" # Default: general conversation return "T1_GENERAL" 3. Save the file. 4. Now open app/lia_inbound.py and: - Add this import at the top if it does not exist: from app.lia_rules import LIA_TIER_BEHAVIOUR, LIA_TONE_GUIDELINES, classify_inbound_tier - Inside process_inbound_message, after you lower-case the body (look for something like: body_lower = payload.body.lower()), insert: tier = classify_inbound_tier(body_lower) and then use that tier when selecting the template: template = LIA_TIER_BEHAVIOUR[tier] response_text = template["example_reply"] final_reply = response_text reply = final_reply 5. Do not change any database logic, defer / DNC updates, or inserts into dp_messages. Only wire in the classify_inbound_tier() function and the template selection.