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
- When a support ticket's subject names a specific order ("Re: Order #4821 - ..."), extract that order number and route the ticket to the queue that owns the order, looked up in `order_index` (order_index is keyed by the order-number string, matching re group output).
- General inquiries have no order number in their subject; route those to the general queue.
- If the subject names an order number that isn't in `order_index`, also fall back to the general queue.
Files touched
- app/support/routing.py
--- 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