Tree-Based Chatbot

Customer Need

The client is a non-profit educational foundation that manages multiple projects and a wide range of educational courses. The foundation required a chatbot solution to streamline communication with students, offering predefined, guided interactions. The objective was to develop a system capable of responding to frequently asked questions, providing institutional information, retrieving real-time data from the School Management System (SMS), and executing specific internal processes.

Tree-Based Chatbot Architecture

To meet this need, a tree-based chatbot architecture was designed and implemented. The solution was backed by a PostgreSQL relational database, which stores the conversational flows in a recursive table structure, modeling each interaction as part of a hierarchical logic tree.

Each node in the tree represents a step or decision point in the chatbot’s flow and is stored as a record in the database. Nodes can be marked with a “disappear” flag, which dynamically hides all associated branches, allowing the chatbot to adapt its structure in real time without needing code changes.

The system supports “action leaves”, which are terminal nodes that perform specific tasks. These were implemented using C#’s reflection capabilities, enabling the system to interpret the metadata associated with each leaf node and dynamically invoke the corresponding method during runtime. This architecture ensures a highly customizable and modular approach to chatbot functionality.

WhatsApp Integration via Twilio

The chatbot communicates through WhatsApp, integrated seamlessly using the Twilio API. Twilio acts as the intermediary layer between the chatbot application and the WhatsApp platform, providing a robust, user-friendly communication channel that enhances accessibility for students.

Adaptability and Flexibility

This solution includes several features designed for maintainability, adaptability, and scalability:

  • Real-time flow configuration: Chatbot flows can be updated during runtime by modifying the recursive database structure—without the need to redeploy or restart the system.

  • Dynamic visibility management: Administrators can quickly enable or disable specific nodes, allowing them to hide or remove flows and actions based on the foundation’s operational needs.

  • Scalable and maintainable architecture: New actions, flows, and content can be added by simply updating the tree structure in the database and implementing the new actions as methods in code. This design supports continuous evolution of the chatbot without compromising stability.