How buildwithsachin02/telegram_bot works
SR Khata is a two-bot Telegram ledger: customers record purchases immediately, while payment and undo claims await owner review before changing ledger state. The customer bot also serves totals and history; the owner bot handles request decisions, reports, and ledger cleanup. The graph preserves these documented capabilities, but ownerBot.js and several service implementations were not sampled, so their internal call wiring is shown conservatively.
Main entry points: app.js Customer bot · ownerBot.js Owner bot · dataCleanupService.js Ledger cleanup · ownerNotificationService.js Owner notifications
Components 20
Customer workflow
- Customer bot
src/app.js - Message parser
src/utils/messageParser.js
Owner operations
- Owner bot
src/ownerBot.js - Cleanup commands
src/ownerCleanupCommands.js
Domain services
- Ledger service
src/services/ledgerService.js - Payment requests
src/services/paymentRequestService.js - Undo requests
src/services/undoRequestService.js - Owner reports
src/services/ownerReportService.js - Ledger cleanup
src/services/dataCleanupService.js - Owner notifications
src/services/ownerNotificationService.js - User service
src/services/userService.js
Persistence
- DB connection
src/config/db.js - User records
src/models/User.js - Transactions
src/models/Transaction.js - Payment requests
src/models/PaymentRequest.js - Undo requests
src/models/UndoRequest.js
Other components
- Customer
- Shop owner
- Telegram
- MongoDB
Connections 30
- Customer → Customer bot: sends commands
- Customer bot → Telegram: replies
- Customer bot → Message parser: parses messages
- Customer bot → User service: finds customers
- Customer bot → Ledger service: records and reads ledger
- Customer bot → Payment requests: creates payment claims
- Customer bot → Undo requests: creates undo claims
- Customer bot → Owner notifications: notifies owner
- Shop owner → Owner bot: reviews and manages
- Owner bot → Telegram: sends owner updates
- Owner bot → Payment requests: reviews payments
- Owner bot → Undo requests: reviews undos
- Owner bot → Owner reports: requests reports
- Owner bot → Cleanup commands: dispatches cleanup
- Cleanup commands → Ledger cleanup: clears ledger data
- Owner notifications → Telegram: sends notifications
- Ledger service → Transactions: reads and writes
- Payment requests → Payment requests: reads and transitions
- Payment requests → Undo requests: checks conflicts
- Undo requests → Undo requests: reads and transitions
- Undo requests → Payment requests: checks conflicts
- Owner reports → Transactions: aggregates ledger
- Owner reports → User records: looks up customers
- User service → User records: reads and writes
- Owner notifications → User records: loads customer
- Owner notifications → Transactions: loads transaction
- Ledger cleanup → Transactions: deletes records
- Ledger cleanup → Payment requests: deletes records
- Ledger cleanup → Undo requests: deletes records
- DB connection → MongoDB: connects