A Telegram bot that authenticates users based on a whitelist, supports multilingual chat (English and Persian), and integrates with OpenAI's GPT-4o for conversational AI. Chat history is stored using SQLite for persistence.
- ๐ Whitelist-based authentication (by
@usernameor phone number)- Phone numbers must start with '+' the country code
- ๐ Language selection (English ๐ฌ๐ง or Persian ๐ฎ๐ท)
- ๐ฌ Natural conversation flow with GPT-4o
- ๐ง Per-user chat history using SQLite (persists across restarts)
- ๐ฑ Telegram-friendly UX (inline keyboards, typing indicators)
- โป๏ธ Reset conversation with
/reset
- Python 3.11+
- A Telegram Bot Token from @BotFather
- An OpenAI API Key
/your-project
โโโ gpt.py # Main bot script
โโโ db.py # SQLite models & helpers
โโโ translate.py # Language strings (EN & FA)
โโโ .env # Environment variables
โโโ requirements.txt # Python dependencies
โโโ bot_data/ # SQLite DB stored here
- Clone the project
git clone https://github.com/your-username/telegram-gpt-bot.git
cd telegram-gpt-bot- Create a virtual environment
python3 -m venv venv
source venv/bin/activate- Install dependencies
pip install -r requirements.txt- Create a
.envfile
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
OPENAI_API_KEY=your_openai_api_key
WHITELIST_IDS=@yourusername,+49123456789,@anotheruserโ The
WHITELIST_IDSsupports both@usernamesand+phone_numbers.
- Run the bot
python gpt.pyUsers can reset their conversation with:
/reset
- The SQLite database is stored in
bot_data/bot_data.db - User verification, language preference, and message history are all persisted
- Only whitelisted users can access the bot
MIT โ feel free to use, modify, and contribute.