Auto-route order tickets from the subject line

Python · Python · intermediate · modification

Automates the first triage step: instead of dropping every inbound ticket in the general queue for a human to sort, we now pull the order number out of the subject and route order-specific tickets straight to the owning team. Fell back to the general queue for the sample tickets that had no matching order.

route_ticket runs on every inbound support email. General inquiries (no order number in the subject) are a large share of the volume; they carry a subject like "Question about returns" with no "Order #" token.

Requirements

Files touched

--- app/support/routing.py
     """Route an inbound support ticket to a queue.
 
-    For now every ticket lands in the general queue; a human triages the
-    order-specific ones by hand.
+    Tickets about a specific order ("Re: Order #4821 - ...") route to the
+    team that owns that order; general inquiries with no order number go
+    to the general queue.
     """
-    return GENERAL_QUEUE
+    match = re.search(r"Order #(\d+)", subject)
+    order_id = match.group(1)
+    owner = order_index.get(order_id)
+    return owner or GENERAL_QUEUE
 

Review this PR

Python practice