B2B wholesale / distributor chatbot — code snippets · 2026-05-31
Companion code for the blog post
AI Chatbot สำหรับร้านค้าส่ง / ยี่ปั๊ว / B2B Distributor SME ไทย 2026.
All snippets are MIT-licensed, production references — adapt to your stack.
thai-tax-id-validator.py — validate Thai 13-digit tax ID (mod-11 checksum) + normalize branch code, before issuing a full e-Tax Invoice
tier-price-resolver.py — resolve correct unit price by customer tier (RETAIL/WHOLESALE/DEALER/AGENT) + price-break ladder + proactive upsell hint
credit-term-guardrail.js — check credit days, remaining limit, and overdue invoices before accepting a credit order (returns a polite action, not a hard reject)
reorder-cadence.py — learn each customer's median reorder cycle per SKU and decide when to nudge / flag for sales follow-up
etax-invoice-xml.py — build a minimal e-Tax Invoice (ใบกำกับภาษีเต็มรูป) payload with VAT 7% checks, before handoff to a certified ETDA provider
sales-rep-router.js — route big/DEALER/AGENT accounts to their owning rep by territory; let the bot self-serve small repeat work
wholesale-bot-prompt.yaml — LLM system-prompt fragment with the golden rule: the model never computes price/credit/VAT, only phrases tool results
⚠️ The e-Tax snippet is a field/validation reference only — it is not a signed ETDA RDXML document. Submit signed XML via a certified e-Tax service provider by the 15th of the following tax month.
← back to blog · korpai.co