Prechádzať zdrojové kódy

fix: recognize alphanumeric SO IDs like A8487 in intent detection

Previously only matched digits-only format (SO-12345). Now handles:
- "SO: A8487" → extracts A8487 as the order ID
- "SO# B123"  → extracts B123 as the order ID
- "SO-12345"  → unchanged existing behavior

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Tony T 6 dní pred
rodič
commit
5b50ba015b
1 zmenil súbory, kde vykonal 11 pridanie a 4 odobranie
  1. 11 4
      server/routers.ts

+ 11 - 4
server/routers.ts

@@ -347,10 +347,17 @@ export const appRouter = router({
               erpContactCid: ctx.user.erpContactCid,
             };
 
-            // 1. Single order lookup  —  "SO-12345", "order SO12345", "#SO-99"
-            const soMatch = msg.match(/\bSO[-\s]?\d{4,}\b/i);
-            if (soMatch) {
-              const soId = soMatch[0].replace(/\s/, "-").toUpperCase();
+            // 1. Single order lookup
+            // Format A: "SO: A8487", "SO# B123"  — SO is a label, alphanumeric ID follows
+            // Format B: "SO-12345", "SO 12345"   — SO is part of the digits-only ID
+            const soLabelMatch = msg.match(/\bSO[-:\s#]+([A-Z]\d{3,})\b/i);
+            const soPrefixMatch = msg.match(/\bSO[-\s]?\d{4,}\b/i);
+            const soId = soLabelMatch
+              ? soLabelMatch[1].toUpperCase()
+              : soPrefixMatch
+                ? soPrefixMatch[0].replace(/\s/, "-").toUpperCase()
+                : null;
+            if (soId) {
               erpContext = await lookupOrder(soId, userCtx);
 
             // 2. "my orders" / "recent orders" — needs customer CID on conversation