Telegram chatbot for COMP7940 Cloud Computing Project. Connects to HKBU's LLM API.
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.
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
- Copy config.example.ini to config.ini
- Add your Telegram bot token (from @BotFather)
- Add your HKBU API key
Docker:
docker-compose up --buildLocal:
pip install -r requirements.txt
python -m src.chatgpt.service # Terminal 1
python -m src.bot.telegram_bot # Terminal 2config.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-previewMongoDB (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