A Flask-based API for handling Web Chat UI to Chatbot backend communication.
- Create a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile with the following variables:
DATABASE_URL=postgresql://user:password@localhost:5432/chat_db
FLASK_APP=src.app:create_app()
FLASK_ENV=development
FLASK_DEBUG=1
PORT=5000
HOST=0.0.0.0
- Initialize the database:
flask db init
flask db migrate
flask db upgradeDevelopment:
flask runProduction:
gunicorn src.app:create_app()- POST
/api/chat/message - Body:
{
"message": "Hello!",
"user_id": "user123",
"session_id": "session123"
}- GET
/api/chat/history/<session_id>
-
Create a new app in CapRover
-
Set up the following environment variables in CapRover:
DATABASE_URLFLASK_APPFLASK_ENV=productionFLASK_DEBUG=0
-
Deploy using CapRover's deployment interface
- Create a new PostgreSQL database on DigitalOcean
- Update the
DATABASE_URLin your environment variables with the new database credentials - Run database migrations after deployment