Skip to content

Repository files navigation

Chat API

A Flask-based API for handling Web Chat UI to Chatbot backend communication.

Setup

  1. Create a virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Create a .env file 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
  1. Initialize the database:
flask db init
flask db migrate
flask db upgrade

Running the Application

Development:

flask run

Production:

gunicorn src.app:create_app()

API Endpoints

Send Message

  • POST /api/chat/message
  • Body:
{
    "message": "Hello!",
    "user_id": "user123",
    "session_id": "session123"
}

Get Chat History

  • GET /api/chat/history/<session_id>

Deployment on DigitalOcean with CapRover

  1. Create a new app in CapRover

  2. Set up the following environment variables in CapRover:

    • DATABASE_URL
    • FLASK_APP
    • FLASK_ENV=production
    • FLASK_DEBUG=0
  3. Deploy using CapRover's deployment interface

Database Setup on DigitalOcean

  1. Create a new PostgreSQL database on DigitalOcean
  2. Update the DATABASE_URL in your environment variables with the new database credentials
  3. Run database migrations after deployment

About

New Anima API App

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages