Complete guide to deploy the bot on Azure for Students (free tier).
- Azure for Students account ($100 free credit)
- Telegram Bot Token (from @BotFather)
- Gemini API Key(s) (from Google AI Studio)
- Go to: https://azure.microsoft.com/en-us/free/students
- Click "Start free"
- Sign in with your student email (e.g.,
B012345678@student.utem.edu.my) - Complete verification via email
- You get: $100 credit + 750 free VM hours/month
- Go to: https://portal.azure.com
- Search "virtual machines" in top search bar
- Click "+ Create" → "Azure virtual machine"
| Field | Value |
|---|---|
| Subscription | Azure for Students |
| Resource group | Create new → productivity-bot-rg |
| Virtual machine name | productivity-bot-vm |
| Region | (Asia Pacific) Southeast Asia |
| Availability options | No infrastructure redundancy required |
| Security type | Standard |
| Image | Ubuntu Server 22.04 LTS - x64 Gen2 |
| Size | Standard_B2ats_v2 (free tier eligible) |
| Field | Value |
|---|---|
| Authentication type | SSH public key |
| Username | azureuser |
| SSH public key source | Generate new key pair |
| Key pair name | productivity-bot-key |
| Field | Value |
|---|---|
| Public inbound ports | Allow selected ports |
| Select inbound ports | SSH (22) |
- Click "Next: Disks >"
- OS disk type:
Standard SSD - Check: Delete with VM
- Click "Next: Networking >"
- Leave defaults
- Check: Delete public IP and NIC when VM is deleted
- Click "Next: Management >"
- Enable auto-shutdown:
11:00 PM - Time zone:
(UTC+08:00) Kuala Lumpur, Singapore
- Click "Review + create"
- Click "Create"
- Download the
.pemkey file when prompted - Save to:
C:\Users\YOUR_USERNAME\.ssh\productivity-bot-key.pem - Wait for deployment (~2 minutes)
- Click "Go to resource"
- Copy the Public IP address
Already configured when you selected SSH (22). To verify:
- In your VM page, click "Networking" in left menu
- Confirm SSH rule exists (port 22)
Press Win + X → Select "Terminal" or "PowerShell"
icacls "C:\Users\YOUR_USERNAME\.ssh\productivity-bot-key.pem" /inheritance:r
icacls "C:\Users\YOUR_USERNAME\.ssh\productivity-bot-key.pem" /grant:r "%USERNAME%:R"ssh -i "C:\Users\YOUR_USERNAME\.ssh\productivity-bot-key.pem" azureuser@YOUR_PUBLIC_IPReplace YOUR_PUBLIC_IP with your VM's IP address.
Type yes when prompted about fingerprint.
You should see:
Welcome to Ubuntu 22.04 LTS
azureuser@productivity-bot-vm:~$
Run these commands on the VM:
# Update system
sudo apt update && sudo apt upgrade -y
# Install Python, pip, venv, git
sudo apt install -y python3-pip python3-venv git# Create app directory
sudo mkdir -p /opt/productivity-bot
sudo chown azureuser:azureuser /opt/productivity-bot
cd /opt/productivity-bot
# Clone your repository
git clone https://github.com/YOUR_USERNAME/productivity.git .
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Create data directory
mkdir -p data
# Create .env file
nano .envTELEGRAM_TOKEN=your_telegram_bot_token
GEMINI_API_KEYS=key1,key2,key3,key4,key5,key6,key7,key8,key9,key10
DATABASE_PATH=data/bot.db
ALLOWED_USER_ID=561393547Note: Use
GEMINI_API_KEYS(comma-separated) for multiple API keys with auto-rotation.
Press Ctrl+X, then Y, then Enter to save.
sudo nano /etc/systemd/system/productivity-bot.service[Unit]
Description=UTeM Productivity Telegram Bot
After=network.target
[Service]
Type=simple
User=azureuser
WorkingDirectory=/opt/productivity-bot
Environment=PATH=/opt/productivity-bot/venv/bin
EnvironmentFile=/opt/productivity-bot/.env
ExecStart=/opt/productivity-bot/venv/bin/python -m src.main
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetPress Ctrl+X, then Y, then Enter to save.
sudo systemctl daemon-reload
sudo systemctl enable productivity-bot
sudo systemctl start productivity-bot# Check service status
sudo systemctl status productivity-bot
# View live logs
sudo journalctl -u productivity-bot -fYou should see:
● productivity-bot.service - UTeM Productivity Telegram Bot
Loaded: loaded
Active: active (running)
...
Gemini client ready with 10 API key(s)
Initializing database at data/bot.db
Starting bot...
Bot is running. Press Ctrl+C to stop.
Test your bot: Send /start to your Telegram bot!
| Action | Command |
|---|---|
| Check status | sudo systemctl status productivity-bot |
| View logs | sudo journalctl -u productivity-bot -f |
| Restart bot | sudo systemctl restart productivity-bot |
| Stop bot | sudo systemctl stop productivity-bot |
| Start bot | sudo systemctl start productivity-bot |
| Update code | cd /opt/productivity-bot && git pull && sudo systemctl restart productivity-bot |
# Check logs for errors
sudo journalctl -u productivity-bot -n 50
# Verify .env file exists and has correct values
cat /opt/productivity-bot/.env# Fix ownership
sudo chown -R azureuser:azureuser /opt/productivity-botcd /opt/productivity-bot
source venv/bin/activate
pip install -r requirements.txt
sudo systemctl restart productivity-bot- Check VM is running in Azure Portal
- Verify NSG allows port 22
- Confirm you're using correct IP address
The bot supports multiple Gemini API keys with automatic rotation:
- Configure keys in
.env:GEMINI_API_KEYS=key1,key2,key3,... - When one key hits rate limit, bot auto-switches to next key
- Each key gets 60-second cooldown before retry
- With 10 keys (20 RPD each) = 200 requests/day
| Resource | Cost |
|---|---|
| VM (B2ats_v2) | Free (750 hrs/month) |
| Dynamic IP | Free |
| Storage | ~$1.20/month |
| Total | ~$1.20/month from $100 credit |
Your $100 credit lasts approximately 12+ months.