How gruizv/whatsappchatbotwdb works
Main Components
• FastAPI Application: Represented by files like main.py (the entry point), utils.py (chatbot logic and message handling), models.py (database schema), and database.py (database connection and operations).
• PostgreSQL Database: Serves as the persistent store for conversation logs and session tracking.
• External Services: Twilio API (for sending/receiving WhatsApp messages) and ngrok (used to expose the local server to the internet for webhook callbacks).
• Supporting Layers: Environment and configuration (via .env and configuration in requirements.txt), and Tests (located in the Tests folder for chatbot logic).
Relationships and Dataflows
• Incoming WhatsApp messages are first received by Twilio, which is configured (using a webhook) to forward messages to the FastAPI endpoint (in main.py).
• The FastAPI application processes the incoming requests, leveraging utility functions (in utils.py) that implement the guided conversation logic.
• Interaction with the PostgreSQL database happens through operations coded in database.py using the schema defined in models.py.
• Outgoing responses, including those with emojis and contextual guidance, are sent back through Twilio to the user.
• The ngrok service is used to expose the local FastAPI server so that Twilio can reach your webhook endpoint.
Architectural Patterns & Technologies
• Separation of Concerns: The project separates the web server, utility logic, and database management into distinct modules.
• Service Integration: FastAPI acts as the central orchestrator that mediates between Twilio (external messaging service) and the PostgreSQL backend.
• Dependency Injection & Configuration: Usage of environment variables (with a configuration file like .env) to decouple sensitive configuration such as database credentials and Twilio tokens.
• Testing Component: There is a folder (Tests) dedicated to unit tests, indicating that testing is an integral part of the development process.