Gupshup (WhatsApp)
Gupshup receives WhatsApp messages and sends replies on behalf of the business number. Required env vars:- Customer sends an order via WhatsApp
- Gupshup forwards it to
POST /gupshup_incoming_webhook - Backend validates the sender against
ALLOWED_PHONE_NUMBERS - Message is sent to OpenAI for parsing
- An
OrderDraftis created - A WhatsApp confirmation is sent back to the customer
- Staff review and convert the draft at
/order-drafts
OpenAI
OpenAI is used with structured output (JSON mode) to parse unstructured WhatsApp order messages into typed order entries. Used in:services.py / gupshup_incoming_webhook.py
Required env var:
Khata OCR
Processes scanned/photographed hand-written ledger pages. Flow:- Upload a photo or PDF of a khata page via
POST /khata-uploador/khata-upload-v2 - Backend converts PDF to image using
pdf2imageif needed - OCR extracts transaction data
- User reviews in a multi-step UI:
UploadStep→ReviewStep→AssignStep - On submission, entries are posted to the relevant party ledgers
PDF Generation
PDFs are generated server-side using reportlab viapdf_service.py.
| Endpoint | Description |
|---|---|
GET /karigar-ledger/{id}/pdf/{side} | Karigar ledger PDF |
GET /client-ledger/{id}/pdf/{side} | Client ledger PDF |
GET /polisher-ledger/{id}/pdf | Polisher ledger PDF |
GET /bullion-ledger/{id}/pdf/{side} | Bullion ledger PDF |
GET /client-orders/pdf | Client orders PDF |
side parameter accepts in or out. All responses return Content-Type: application/pdf and trigger a browser download.
HTTP Client (Frontend)
The Axios instance (src/lib/axiosInstance.ts) is configured with:
| Setting | Value |
|---|---|
| Base URL | VITE_API_BASE_URL or http://localhost:8000 |
| Timeout | 600,000 ms (10 min — for large PDF/upload ops) |
| Auth header | Bearer testToken (placeholder) |
| 401/403 handler | Logs unauthorized access |
| 500 handler | Logs server errors |
CORS
The backend allows requests from:http://localhost:5173(Vite dev server)http://localhost:3000- Production EC2 domain (
ec2-15-207-84-167.ap-south-1.compute.amazonaws.com)
backend/src/sj/__init__.py using FastAPI’s CORSMiddleware.