Intelligent order management system
Goal: Develop a fault-tolerant order acceptance system (E-commerce Bot) with logic to protect against data collisions. Requirement: the system must operate as a State Machine (finite automaton), dynamically adjusting the interface based on the availability of products in the database and ensuring the "cleanliness" of input data even before the processing stage by the manager.
My Contribution / Solution: Designed and implemented a "State-Aware Architecture" based on n8n, which manages the user lifecycle from entry to deal finalization. A Low-Code + Custom JS approach was used to bypass the limitations of standard nodes.
1. "Gatekeeper" Architecture (Session Management):
Logic Engine & Concurrency Control: A strict "Face Control" algorithm (Switch Node Logic) was implemented. The system checks the database for any unfinished transactions (statuses "Pending", "Payment Wait") before starting a new process. This prevents the creation of duplicates and "junk" records.
Session Reset & Cleanup: A mechanism for forcibly resetting stuck sessions (force_cancel) was implemented, allowing the user to resolve state conflicts independently without contacting support.
2. Dynamic Frontend (Telegram UI):
JSON-Generated Interface: Instead of hardcoding buttons, dynamic menu generation was implemented (JavaScript Code Node). The bot queries the warehouse database (n8n Table/Airtable), retrieves the current product catalog, and renders the keyboard "on the fly." This allows adding products (/add) without restarting the bot.
Raw HTTP Requests: To bypass the limitations of standard n8n nodes and eliminate UI glitches, direct POST requests to the Telegram API were used. This ensured stable operation of complex reply_markup objects and correct transmission of callback data.
3. Data Integrity & Validation:
Smart Parsing: A combination of regular expressions (RegEx) and conditional operators for input validation (for example, distinguishing the amount "200" from the phone "050...").
Database Locking: The use of atomic updates of rows by unique IDs (instead of ChatID), which solved the problem of data overwriting when multiple operators or instances were working simultaneously.
Result: An autonomous sales system was created that does not require technical supervision:
Zero-Conflict Database: The number of duplicated or erroneous orders has been reduced to 0 thanks to state-management logic.
Scalability: Adding new product items takes seconds through admin commands, automatically updating the interface for all users.
User Experience: The system itself "guides" the client, blocking illogical actions and offering contextual scenarios for error recovery.
#n8n #JavaScript #BackendArchitecture #StateManagement #TelegramBotAPI #ECommerceAutomation #ErrorHandling #DatabaseDesign
My Contribution / Solution: Designed and implemented a "State-Aware Architecture" based on n8n, which manages the user lifecycle from entry to deal finalization. A Low-Code + Custom JS approach was used to bypass the limitations of standard nodes.
1. "Gatekeeper" Architecture (Session Management):
Logic Engine & Concurrency Control: A strict "Face Control" algorithm (Switch Node Logic) was implemented. The system checks the database for any unfinished transactions (statuses "Pending", "Payment Wait") before starting a new process. This prevents the creation of duplicates and "junk" records.
Session Reset & Cleanup: A mechanism for forcibly resetting stuck sessions (force_cancel) was implemented, allowing the user to resolve state conflicts independently without contacting support.
2. Dynamic Frontend (Telegram UI):
JSON-Generated Interface: Instead of hardcoding buttons, dynamic menu generation was implemented (JavaScript Code Node). The bot queries the warehouse database (n8n Table/Airtable), retrieves the current product catalog, and renders the keyboard "on the fly." This allows adding products (/add) without restarting the bot.
Raw HTTP Requests: To bypass the limitations of standard n8n nodes and eliminate UI glitches, direct POST requests to the Telegram API were used. This ensured stable operation of complex reply_markup objects and correct transmission of callback data.
3. Data Integrity & Validation:
Smart Parsing: A combination of regular expressions (RegEx) and conditional operators for input validation (for example, distinguishing the amount "200" from the phone "050...").
Database Locking: The use of atomic updates of rows by unique IDs (instead of ChatID), which solved the problem of data overwriting when multiple operators or instances were working simultaneously.
Result: An autonomous sales system was created that does not require technical supervision:
Zero-Conflict Database: The number of duplicated or erroneous orders has been reduced to 0 thanks to state-management logic.
Scalability: Adding new product items takes seconds through admin commands, automatically updating the interface for all users.
User Experience: The system itself "guides" the client, blocking illogical actions and offering contextual scenarios for error recovery.
#n8n #JavaScript #BackendArchitecture #StateManagement #TelegramBotAPI #ECommerceAutomation #ErrorHandling #DatabaseDesign