A Telegram bot for Evocoders Club management implemented in Go. Helps moderate discussions, provides AI-powered search, and generates daily chat summaries.
- ✅ Thread Management: Deletes non-admin messages in read-only threads
- ✅ Message Forwarding: Forwards replies from closed threads to the general topic
- ✅ Join/Leave Cleanup: Removes join/leave messages for cleaner conversations
- ✅ Message Tracking: Automatically stores group messages for summarization and analysis
- ✅ Topic Management: Tracks forum topics and their metadata
- 🔍 Tools Search (
/tools): Finds relevant AI tools based on user queries with fast and deep search options - 📚 Content Search (
/content): Searches through designated topics for information with fast and deep search options - 👋 Club Members Introduction Search (
/intro): Provides information about club members with fast and deep search options - 📋 Chat Summarization: Creates daily summaries of conversations
- Auto-posts at configured times
- Manual trigger with
/trySummarize(admin-only) - Send a knowledge base link with
/tryLinkToLearn(admin-only, private)
- Automated Participation Poll: Every week (configurable day and time in UTC, defaults to Friday at 2 PM UTC), the bot posts a poll asking members if they want to participate in random coffee meetings for the following week.
- Opt-in/Opt-out: Members can easily indicate their availability by responding to the poll. Votes can be changed or retracted before pairs are made.
- Automated Pairing: The bot automatically generates and announces pairs on a scheduled basis (configurable day and time in UTC, defaults to Monday at 12 PM UTC) using a smart algorithm that considers pairing history.
- Smart Pairing Algorithm: Pairs are generated considering past pairing history to avoid recent duplicates and ensure fair distribution of meetings.
- Manual Pairing: An administrator can also manually trigger the pairing process using the
/tryGenerateCoffeePairscommand. - Random Pair Announcement: The bot randomly pairs participating members and announces the pairs in the main chat.
- Self-Managed Meetings: Paired members are encouraged to contact each other to arrange the day, time, and format of their meeting.
- 👤 Profile Command (
/profile): Manage your personal profile- Create and edit personal information (name, bio)
- Publish your profile to the designated "Intro" topic
- Search for other club members' profiles
- 📅 Event Management: Track and organize community events
- Support for different event types and statuses
- Event publishing with start times
- Topic organization within events
- 📝 Topic Viewing (
/topics): Browse topics and questions from events - ➕ Topic Addition (
/topicAdd): Add new topics and questions to events (for all club members) - 🔧 Admin Topic Management (
/showTopics): View and delete topics (admin-only)
- 👥 Profiles Manager (
/profilesManager): Admin tool for managing user profiles - 🧪 Test Handlers: Manual testing tools for coffee pools (
/tryCreateCoffeePool), pair generation (/tryGenerateCoffeePairs), and sending knowledge base link (/tryLinkToLearn) - 📊 Event Management: Create, edit, start, and delete events (
/eventSetup,/eventEdit,/eventStart,/eventDelete)
- ❌ Cancel (
/cancel): Cancel any ongoing operation - 🧩 Dynamic Templates: Customizable AI prompts stored in database
For more details on bot usage, use the /help command in the bot chat.
- Language: Go 1.21+
- Framework: gotgbot for Telegram Bot API
- Database: PostgreSQL with automated migrations
- AI Integration: OpenAI API for content analysis and search
- Architecture: Clean layered architecture with dependency injection
- Testing: Comprehensive unit tests with gotestsum support
The bot follows a clean layered architecture:
- Handlers Layer (
internal/handlers/): Processes Telegram updatesadminhandlers/: Admin-only commandsgrouphandlers/: Group chat moderationprivatehandlers/: User-facing private commands
- Services Layer (
internal/services/): Business logic- Core services: Profile, RandomCoffee, Summarization
- Group handler services: Message processing, moderation
- Repository Layer (
internal/database/repositories/): Data access - Database Layer (
internal/database/): Schema migrations and connections - Configuration Layer (
internal/config/): Environment management - Utilities Layer (
internal/utils/): Helper functions and utilities
For the bot to function properly, it must have the following admin permissions in the Telegram supergroup:
- 📌 Pin messages: Required for pinning event announcements and important information
- 🗑️ Delete messages: Required for clearing service messages and moderating threads
To assign these permissions, add the bot as an administrator in your group and enable these specific rights.
The bot uses PostgreSQL with automatically initialized tables:
| Table | Purpose | Key Fields |
|---|---|---|
| group_messages | Stores group messages for summarization | id, message_id, message_text, reply_to_message_id, user_tg_id, group_topic_id, created_at, updated_at |
| group_topics | Stores forum topic names and metadata | id, topic_id, name, created_at, updated_at |
| prompting_templates | Stores AI prompting templates | template_key, template_text |
| users | Stores user information | id, tg_id, firstname, lastname, tg_username, score, has_coffee_ban, is_club_member |
| profiles | Stores user profile data | id, user_id, bio, published_message_id, created_at, updated_at |
| events | Stores event information | id, name, type, status, started_at, created_at, updated_at |
| topics | Stores topics related to events | id, topic, user_nickname, event_id, created_at |
| random_coffee_polls | Stores random coffee poll information | id, message_id, telegram_poll_id, week_start_date, created_at |
| random_coffee_participants | Stores poll participants data | id, poll_id, user_id, participating, updated_at |
| random_coffee_pairs | Stores the history of generated random coffee pairs | id, poll_id, user1_id, user2_id, created_at |
| migrations | Tracks database migrations | id, name, timestamp, created_at |
To build the executable for different platforms:
For Windows:
GOOS=windows GOARCH=amd64 go build -o bot.exeFor Linux:
GOOS=linux GOARCH=amd64 go build -o botFor macOS:
GOOS=darwin GOARCH=amd64 go build -o botRun the bot with:
go run main.go Build the project:
go build main.goCommand for update dependencies:
go mod tidyThe bot uses environment variables for configuration, make sure to set them all:
TG_EVO_BOT_TOKEN: Your Telegram bot tokenTG_EVO_BOT_SUPERGROUP_CHAT_ID: Chat ID of your SupergroupTG_EVO_BOT_ADMIN_USER_ID: User ID for the administrator account (will get notifications about new topics)TG_EVO_BOT_OPENAI_API_KEY: OpenAI API key
TG_EVO_BOT_CLOSED_TOPICS_IDS: Comma-separated list of topic IDs that are closed for chattingTG_EVO_BOT_FORWARDING_TOPIC_ID: ID of the topic where forwarded replies will be sent (0 for General topic)TG_EVO_BOT_TOOL_TOPIC_ID: Topic ID for the AI tools database (used by/toolscommand)TG_EVO_BOT_CONTENT_TOPIC_ID: Topic ID for the content topic (used by/contentcommand)TG_EVO_BOT_INTRO_TOPIC_ID: Topic ID for club introductions and member information (used by/introcommand)TG_EVO_BOT_ANNOUNCEMENT_TOPIC_ID: Topic ID for announcements
TG_EVO_BOT_DB_CONNECTION: PostgreSQL connection string (e.g.,postgresql://user:password@localhost:5432/dbname) - the database will be automatically initialized with required tablesTG_EVO_BOT_MONITORED_TOPICS_IDS: Comma-separated list of topic IDs to monitor for summarizationTG_EVO_BOT_SUMMARY_TOPIC_ID: Topic ID where daily summaries will be postedTG_EVO_BOT_SUMMARY_TIME: Time to run daily summary in 24-hour format (e.g.,03:00for 3 AM)TG_EVO_BOT_SUMMARIZATION_TASK_ENABLED: Enable or disable the daily summarization task (trueorfalse, defaults totrueif not specified)
TG_EVO_BOT_RANDOM_COFFEE_TOPIC_ID: Topic ID where random coffee polls and pairs will be postedTG_EVO_BOT_RANDOM_COFFEE_POLL_TASK_ENABLED: Enable or disable the weekly coffee poll task (trueorfalse, defaults totrueif not specified)TG_EVO_BOT_RANDOM_COFFEE_POLL_TIME: Time to send the weekly coffee poll in 24-hour format UTC (e.g.,14:00for 2 PM UTC, defaults to14:00if not specified)TG_EVO_BOT_RANDOM_COFFEE_POLL_DAY: Day of the week to send the poll (e.g.,friday,monday, etc., defaults tofridayif not specified)TG_EVO_BOT_RANDOM_COFFEE_PAIRS_TASK_ENABLED: Enable or disable the automatic pairs generation task (trueorfalse, defaults totrueif not specified)TG_EVO_BOT_RANDOM_COFFEE_PAIRS_TIME: Time to generate and announce coffee pairs in 24-hour format UTC (e.g.,12:00for 12 PM UTC, defaults to12:00if not specified)TG_EVO_BOT_RANDOM_COFFEE_PAIRS_DAY: Day of the week to generate pairs (e.g.,monday,tuesday, etc., defaults tomondayif not specified)
On Windows, you can set the environment variables using the following commands in Command Prompt:
# Basic Bot Configuration
set TG_EVO_BOT_TOKEN=your_bot_token_here
set TG_EVO_BOT_OPENAI_API_KEY=your_openai_api_key_here
set TG_EVO_BOT_SUPERGROUP_CHAT_ID=chat_id
set TG_EVO_BOT_ADMIN_USER_ID=admin_user_id
# Topics Management
set TG_EVO_BOT_CLOSED_TOPICS_IDS=topic_id_1,topic_id_2,topic_id_3
set TG_EVO_BOT_FORWARDING_TOPIC_ID=forwarding_topic_id
set TG_EVO_BOT_TOOL_TOPIC_ID=tool_topic_id
set TG_EVO_BOT_CONTENT_TOPIC_ID=content_topic_id
set TG_EVO_BOT_INTRO_TOPIC_ID=intro_topic_id
set TG_EVO_BOT_ANNOUNCEMENT_TOPIC_ID=announcement_topic_id
# Daily Summarization Feature
set TG_EVO_BOT_DB_CONNECTION=postgresql://user:password@localhost:5432/dbname
set TG_EVO_BOT_MONITORED_TOPICS_IDS=0,2
set TG_EVO_BOT_SUMMARY_TOPIC_ID=3
set TG_EVO_BOT_SUMMARY_TIME=03:00
set TG_EVO_BOT_SUMMARIZATION_TASK_ENABLED=true
# Random Coffee Feature
set TG_EVO_BOT_RANDOM_COFFEE_TOPIC_ID=random_coffee_topic_id
set TG_EVO_BOT_RANDOM_COFFEE_POLL_TASK_ENABLED=true
set TG_EVO_BOT_RANDOM_COFFEE_POLL_TIME=14:00
set TG_EVO_BOT_RANDOM_COFFEE_POLL_DAY=friday
set TG_EVO_BOT_RANDOM_COFFEE_PAIRS_TASK_ENABLED=true
set TG_EVO_BOT_RANDOM_COFFEE_PAIRS_TIME=12:00
set TG_EVO_BOT_RANDOM_COFFEE_PAIRS_DAY=mondayThen run the executable.
This project includes unit tests to ensure functionality works as expected. Here are various ways to run the tests:
To run all tests in the project:
go test ./...This command will recursively run all tests in all packages of your project.
To run tests in a specific package:
go test evo-bot-go/internal/handlers/privatehandlersOr navigate to the package directory and run:
cd internal/handlers/privatehandlers
go testTo run a specific test function:
go test -run TestHelpHandler_Name evo-bot-go/internal/handlers/privatehandlersThe -run flag accepts a regular expression that matches test function names.
For more detailed test output, add the -v flag:
go test -v ./...To see test coverage:
go test -cover ./...For a detailed coverage report:
go test -coverprofile=coverage.out ./...
go tool cover -html=coverage.outThis will generate an HTML report showing which lines of code are covered by tests.
To check for race conditions:
go test -race ./...For better visibility with colored test output and icons, you can use gotestsum:
# Install gotestsum
go install gotest.tools/gotestsum@latest
# Run tests with colored output and icons
gotestsum --format pkgname --format-icons hivis
# If gotestsum is not in your PATH, run it directly
go run gotest.tools/gotestsum@latest --format pkgname --format-icons hivisFor maximum detail with colors and icons:
go run gotest.tools/gotestsum@latest --format standard-verbose --format-icons hivis --packages=./... -- -vThis provides colored output with clear pass/fail indicators and detailed test information.