|
@@ -347,10 +347,17 @@ export const appRouter = router({
|
|
|
erpContactCid: ctx.user.erpContactCid,
|
|
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);
|
|
erpContext = await lookupOrder(soId, userCtx);
|
|
|
|
|
|
|
|
// 2. "my orders" / "recent orders" — needs customer CID on conversation
|
|
// 2. "my orders" / "recent orders" — needs customer CID on conversation
|