A Telegram bot for managing questions and answers during Tehran Linux User Group (TehLUG) events. Users can register, select presenters, ask questions, and admins can view and filter questions.
- Registration: Users register with their name and email
- Ask Questions: Select a presenter and submit questions
- Simple Interface: Easy-to-use keyboard-based navigation
- View All Questions: See all submitted questions
- Filter by Presenter: View questions for specific presenters
- Filter by User: Search questions by user name
- Manage Presenters: Add new presenters to the system
- Manage Users: View all users, promote users to admin, or demote admins
- Channel Forwarding: Automatically forward questions to a Telegram channel (optional)
pip install -r requirements.txtOr if using uv:
uv pip install -e .Install PostgreSQL and create a database:
# Using psql
createdb tehlug_bot
# Or connect to PostgreSQL and run:
# CREATE DATABASE tehlug_bot;- Open Telegram and search for @BotFather
- Send
/newbotand follow the instructions - Copy the bot token provided
- Open Telegram and search for @userinfobot
- Start a chat with the bot
- Copy your Telegram ID
To automatically forward questions to a Telegram channel:
- Create a channel or use an existing one
- Add your bot as an admin to the channel
- Get the channel ID:
- For public channels: Use the channel username (e.g.,
@mychannel) - For private channels:
- Forward any message from the channel to @JsonDumpBot
- Look for
"forward_from_chat"→"id"in the JSON response - Copy the numeric ID (e.g.,
-1001234567890)
- For public channels: Use the channel username (e.g.,
Create a .env file (or set environment variables):
cp .env.example .envEdit .env and add your values:
BOT_TOKEN=your_bot_token_from_botfather
FIRST_ADMIN_ID=your_telegram_id
DATABASE_URL=postgresql://username:password@localhost:5432/tehlug_bot
QUESTIONS_CHANNEL_ID=-1001234567890 # Optional: only if you want to forward questions to a channelRequired Variables:
BOT_TOKEN: Your bot token from BotFatherDATABASE_URL: PostgreSQL connection string
Optional Variables:
FIRST_ADMIN_ID: Only used to set the initial admin when they register. After that, use the "Manage Users" feature in the Admin Panel to promote other users to admin.QUESTIONS_CHANNEL_ID: Channel ID to forward questions to. Leave empty if you don't want this feature.
python main.pyThe database tables will be created automatically on first run.
- Start the bot with
/start - Register with your name and email
- Click "Ask Question"
- Select a presenter
- Type your question
- Click "Admin Panel" from the main menu
- Options available:
- View All Questions: See all submitted questions
- Filter by Presenter: Filter questions by presenter name
- Filter by User: Search questions by user name
- Add Presenter: Add new presenters (comma-separated for multiple)
- Manage Users: View all registered users, promote users to admin, or demote admins
tehlug-tlg-bot/
|_ main.py # Entry point - starts the bot
|_ bot.py # Bot handlers and conversation flows
|_ database.py # Database operations (PostgreSQL with SQLAlchemy)
|_ pyproject.toml # Project dependencies
|_ .env.example # Environment variable template
telegram_id(BIGINT, PRIMARY KEY)name(TEXT)email(TEXT)is_admin(BOOLEAN, default: FALSE)registered_at(TIMESTAMP)
id(SERIAL, PRIMARY KEY)telegram_id(BIGINT, FOREIGN KEY)user_name(TEXT)presenter_name(TEXT)question(TEXT)created_at(TIMESTAMP)
id(SERIAL, PRIMARY KEY)name(TEXT, UNIQUE)title(TEXT)start_time(TEXT)end_time(TEXT)
The bot uses:
- python-telegram-bot for Telegram API
- PostgreSQL for data storage
- SQLAlchemy (async) with asyncpg driver for database operations
- ConversationHandler for multi-step interactions
MIT