A conversational assistant designed to streamline inquiries, providing users with accurate and timely information through natural language interactions.
- Intent Recognition: Utilizes pattern matching to discern user intents from messages.
- State Management: Maintains conversational context for seamless interactions.
- Extensible Intent Handlers: Easily add or modify functionalities by updating intent actions.
- Twilio Integration: Supports WhatsApp messaging via Twilio API.
- Error Handling: Gracefully manages unexpected inputs and system errors.
See CHANGELOG.md for release history.
Deterministic-chatbot/
├── .github/
│ ├── workflows/ # GitHub Actions CI workflow
│ └── dependabot.yml # Automated dependency update PRs
├── .vscode/ # VSCode-specific settings
├── src/
│ ├── app/
│ │ ├── __init__.py
│ │ ├── chat.py # Chat class handling intents and prompt processing
│ │ ├── intent_actions.py # Functions mapping intents to responses
│ │ ├── state.py # State management (in-memory or SQLite)
│ │ ├── model.py # SQLAlchemy table schema
│ │ └── twilio.py # Twilio client setup
│ └── routes/
│ ├── __init__.py
│ ├── webhook.py # POST /webhook/ - main chat endpoint
│ └── callback.py # POST /status-callback/ - Twilio status callback
├── tests/ # Unit and integration tests
│ ├── test_main.py
│ ├── test_state.py
│ ├── test_chat.py
│ └── test_webhook.py
├── conftest.py # Shared pytest env-var setup
├── .env.example # Sample environment variables file
├── .flake8 # Lint configuration
├── Dockerfile
├── .gitignore
├── LICENSE
├── README.md
├── main.py # FastAPI application entry point
├── requirements.in # Direct runtime dependencies (source)
├── requirements.txt # Fully pinned runtime dependencies (lock)
├── requirements-dev.in # Direct dev/test dependencies (source)
└── requirements-dev.txt # Fully pinned dev/test dependencies (lock)- Python 3.13 or higher
- Twilio account (for WhatsApp integration)
-
Clone the repository:
git clone https://github.com/nyashaChiza/deterministic-chatbot.git cd deterministic-chatbot -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
For local development (tests, linting), also install the dev dependencies:
pip install -r requirements-dev.txt
-
Configure environment variables:
- Copy
.env.exampleto.env. - Update the
.envfile with your Twilio credentials and desired settings.
- Copy
uvicorn main:app --reloadThe application will be accessible at http://127.0.0.1:8000.
docker compose upThis builds the image, serves the app at localhost:8000, reads config
from .env, and persists db.sqlite3 on the host (only relevant if
STATE_BACKEND=sqlite; the default in-memory backend has nothing to
persist).
To run the container directly instead:
docker build -t deterministic-chatbot .
docker run --env-file .env -p 8000:8000 -v $(pwd)/db.sqlite3:/app/db.sqlite3 deterministic-chatbot-
Send a POST request to the
/webhook/endpoint with form data containing:From: Sender's identifier (e.g., WhatsApp number).Body: Message content.
-
The chatbot will process the message, determine the intent, and respond accordingly.
pip install -r requirements-dev.txt
pytestThis will execute the full test suite located in the tests/ directory (intent detection, prompt validation, state backends, and the /webhook/ endpoint).
flake8 .CI runs this on every push/PR and fails the build on style or complexity violations.
requirements.txt and requirements-dev.txt are the pinned, hash-locked lockfiles enforced by CI - pip-audit scans requirements.txt, and CI installs with pip install -r requirements-dev.txt --require-hashes, so a fresh install is byte-identical or it fails. requirements.in and requirements-dev.in list the direct dependencies they were compiled from (via pip-tools):
pip install pip-tools
pip-compile --generate-hashes requirements.in
pip-compile --generate-hashes requirements-dev.inDependabot opens a weekly PR for outdated pip and GitHub Actions dependencies. CI also runs pip-audit against requirements.txt on every push/PR:
pip install pip-audit
pip-audit -r requirements.txt --descSee CONTRIBUTING.md.
This project is licensed under the GPL-3.0 License.
Developed by Nyasha Chizampeni