This bot monitors the Announcements page of the Academic Affairs & Science Office at the University of Information Technology (UIT) and posts new announcements to Telegram.
- Every 5 minutes by default (configurable via
POLL_INTERVAL), the bot performs two tasks:- Fetches announcements from
https://sdh.uit.edu.vn/thong-bao-chung - Reads unread emails from Gmail (Inbox + Spam) — if configured
- Fetches announcements from
- It compares fetched items with a stored list of already-sent items and only posts new announcements.
- Emails are marked as read after being posted to avoid duplicates.
- Go 1.21+ — see Go downloads
- A Telegram Bot Token (free via BotFather)
- A Chat ID (group or personal chat)
- Open Telegram and search for @BotFather.
- Send
/newbotand follow the prompts. - Give your bot a name (e.g.
UIT Notify Bot). - Choose a username that ends with
bot(e.g.uit_notify_bot). - BotFather will provide a token after creation — keep it safe. Example:
8676555434:AAHYMxTY5_dQipO75wg4QzEjiaJj2weFGcI
Option 1: Use @userinfobot (for a personal chat)
- Search for @userinfobot.
- Send
/start— it will reply with your chat ID.
Option 2: Create a group and get its ID (recommended)
- Create a new group in Telegram.
- Add your bot to the group and give it Admin rights.
- Send any message in the group (e.g. "test").
- Run the following to fetch updates (replace
BOT_TOKEN):curl -s "https://api.telegram.org/botBOT_TOKEN/getUpdates" | python3 -m json.tool
- Look for a line like
"chat": {"id": -100xxxxxxxxx, "title": "...", "type": "supergroup"}— the group ID is the number (often negative), e.g.-1003986448291.
Note: If the
resultarray is empty, send another message in the group and try again.
macOS (Homebrew):
brew install goUbuntu/Debian:
sudo apt install golang-goWindows: Download the installer from go.dev/dl.
Verify:
go version
# e.g. go version go1.21.x# Change into the project directory
cd auto-get-mails
# Download dependencies
go mod tidy
# Build the binary
go build -o uit-bot ./cmd/bot/This produces an executable named uit-bot in the current directory.
# Run from source
TELEGRAM_BOT_TOKEN=xxxx:yyyy \
TELEGRAM_CHAT_ID=-1003986448291 \
go run ./cmd/bot/
# Or run the built binary
TELEGRAM_BOT_TOKEN=xxxx:yyyy \
TELEGRAM_CHAT_ID=-1003986448291 \
./uit-botOn the first run the bot will post all current announcements to Telegram; subsequent runs only post new announcements.
The bot can read unread emails from Gmail (Inbox and Spam) and post them to Telegram with subject, sender, and content.
How it works:
- In each cycle (default 5 minutes) the bot connects to Gmail via IMAP.
- It finds unread emails in Inbox and Spam.
- It posts them to the Telegram group (spam emails are prefixed with
💰 [SPAM]) and includes a link to view the email in Gmail. - After posting, an email is marked as read to prevent reposting.
Requirement: the Gmail account must have two-factor authentication (2FA) enabled.
Creating an App Password:
- Go to https://myaccount.google.com/security and enable 2-Step Verification if not enabled.
- Open https://myaccount.google.com/apppasswords
- Select Mail and Other (Custom name), enter
UIT Bot. - Google will generate a 16-character password (e.g.
abcd efgh ijkl mnop) — copy it. - Add to your
.env:GMAIL_USER=email@gmail.com GMAIL_APP_PASSWORD=xxxx
Note: After posting, emails are marked as read in Gmail to avoid duplicate posts.
# Start in background
nohup ./uit-bot > bot.log 2>&1 &
# View logs
tail -f bot.log
# Stop
pkill uit-botIf
nohup ... &stops when you close the terminal, adddisown:nohup ./uit-bot > bot.log 2>&1 & disown
brew install tmux
tmux new -s bot
./uit-bot
# Detach while leaving the bot running: Ctrl+B then D
# Reattach: tmux attach -t bot
# Stop inside session: Ctrl+C
# List sessions: tmux lsCreate /etc/systemd/system/uit-bot.service:
[Unit]
Description=UIT Announcement Bot
After=network.target
[Service]
Type=simple
User=ubuntu
WorkingDirectory=/home/ubuntu/auto-get-mails
ExecStart=/home/ubuntu/auto-get-mails/uit-bot
Environment="TELEGRAM_BOT_TOKEN=your_token_here"
Environment="TELEGRAM_CHAT_ID=your_chat_id_here"
Environment="POLL_INTERVAL=5m"
Environment="STORE_PATH=data/seen.json"
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.targetsudo systemctl daemon-reload
sudo systemctl enable uit-bot
sudo systemctl start uit-bot
sudo systemctl status uit-botCreate ~/Library/LaunchAgents/com.uit-bot.plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.uit-bot</string>
<key>ProgramArguments</key>
<array>
<string>/Users/your_user/auto-get-mails/uit-bot</string>
</array>
<key>WorkingDirectory</key>
<string>/Users/your_user/auto-get-mails</string>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<true/>
<key>StandardOutPath</key>
<string>/Users/your_user/auto-get-mails/bot.log</string>
<key>StandardErrorPath</key>
<string>/Users/your_user/auto-get-mails/bot.log</string>
</dict>
</plist># Load and run
launchctl load ~/Library/LaunchAgents/com.uit-bot.plist
# Unload
launchctl unload ~/Library/LaunchAgents/com.uit-bot.plist
# Check status
launchctl list | grep uit-bot| Variable | Required | Default | Description |
|---|---|---|---|
TELEGRAM_BOT_TOKEN |
✅ | — | Bot token from BotFather |
TELEGRAM_CHAT_ID |
✅ | — | Target group or chat ID |
POLL_INTERVAL |
❌ | 5m |
Interval between checks (e.g. 10m, 30s, 1h) |
STORE_PATH |
❌ | data/seen.json |
Path to store IDs of already-sent items |
GMAIL_USER |
❌ | — | Gmail address (to enable email reading) |
GMAIL_APP_PASSWORD |
❌ | — | Gmail App Password for IMAP |
Or use a .env file:
cp .env.example .env
# Edit .env with your token and chat ID
source .env && ./uit-botauto-get-mails/
├── cmd/bot/main.go # Entry point, main loop
├── internal/
│ ├── scraper/scraper.go # Fetch & parse HTML
│ ├── email/reader.go # Read Gmail via IMAP
│ ├── notifier/telegram.go # Send Telegram messages
│ └── store/store.go # Manage sent-state storage
├── data/
│ └── seen.json # (auto-created) IDs of announcements already sent
├── .env.example # Example environment file
├── go.mod / go.sum
├── uit-bot # Built binary
└── README.md
Bot does not send messages:
- Verify the token is correct:
curl -s "https://api.telegram.org/botTOKEN/getMe" - Ensure the bot has been added to the group.
- Confirm the chat ID is correct (pay attention to a leading
-for groups).
Cannot fetch the announcements page:
- Check internet access:
curl -s https://sdh.uit.edu.vn/thong-bao-chung | head -5 - The page HTML structure may have changed — update
internal/scraper/scraper.goaccordingly.
Emails are not posted:
- Verify
GMAIL_USERandGMAIL_APP_PASSWORDin.env. - If the App Password contains spaces, keep them (e.g.
abcd efgh ijkl mnop). - Ensure 2FA is enabled at https://myaccount.google.com/security.
- If Gmail reports "login failed", regenerate an App Password at https://myaccount.google.com/apppasswords.