Skip to content

MaxFstl/COMP_7940_CC

Repository files navigation

HKBU ChatGPT Telegram Bot

Telegram chatbot for COMP7940 Cloud Computing Project. Connects to HKBU's LLM API.

Architecture

User sends message to Telegram bot → Bot calls ChatGPT service (Flask API) → ChatGPT service calls HKBU API → Response sent back to user.

The ChatGPT service is stateless, so we can run multiple instances behind a load balancer.

Project Structure

config.py              # Loads config from ini file
config.ini             # Your credentials (not in git)
docker-compose.yml     # Runs both services
Dockerfile.chatgpt     # Flask API container
Dockerfile.telegram    # Bot container
src/
  bot/telegram_bot.py  # Handles Telegram messages
  chatgpt/
    client.py          # HTTP client
    service.py         # Flask API
  hkbu/api.py          # HKBU ChatGPT wrapper

Setup

  1. Copy config.example.ini to config.ini
  2. Add your Telegram bot token (from @BotFather)
  3. Add your HKBU API key

Run

Docker:

docker-compose up --build

Local:

pip install -r requirements.txt
python -m src.chatgpt.service   # Terminal 1
python -m src.bot.telegram_bot  # Terminal 2

Config

config.ini:

[TELEGRAM]
ACCESS_TOKEN = your_token
URL = t.me/your_bot

[CHATGPT]
API_KEY = your_key
BASE_URL = https://genai.hkbu.edu.hk/api/v0/rest
MODEL = gpt-5-mini
API_VER = 2024-12-01-preview
MongoDB (Azure Cosmos DB) Required:
The service will automatically create the ChatMessages collection in the 'chatbot' database.

Required environment variable:
MONGODB_URI=mongodb://username:password@host:port/?ssl=true&replicaSet=globaldb&retrywrites=false&maxIdleTimeMS=120000&appName=@username@

The collection will store documents with the following structure:
{
  session_id: String,
  timestamp: ISODate,
  user_id: String,
  username: String (optional),
  role: String ("user" or "assistant"),
  content: String
}

Indexes created automatically:
- session_id (ascending) + timestamp (ascending) for efficient history queries

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors