Skip to content

ALor79/telegram-ai-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

9 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ“ฆ Telegram GPT Bot

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.


โœจ Features

  • ๐Ÿ” Whitelist-based authentication (by @username or 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

โš™๏ธ Requirements

  • Python 3.11+
  • A Telegram Bot Token from @BotFather
  • An OpenAI API Key

๐Ÿ“ Project Structure

/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

๐Ÿ”ง Setup

  1. Clone the project
git clone https://github.com/your-username/telegram-gpt-bot.git
cd telegram-gpt-bot
  1. Create a virtual environment
python3 -m venv venv
source venv/bin/activate
  1. Install dependencies
pip install -r requirements.txt
  1. Create a .env file
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
OPENAI_API_KEY=your_openai_api_key
WHITELIST_IDS=@yourusername,+49123456789,@anotheruser

โœ… The WHITELIST_IDS supports both @usernames and +phone_numbers.

  1. Run the bot
python gpt.py

๐Ÿง  Reset Chat History

Users can reset their conversation with:

/reset

๐Ÿ›ก๏ธ Notes

  • 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

๐Ÿ“œ License

MIT โ€” feel free to use, modify, and contribute.

About

๐Ÿค– A Telegram bot powered by GPT-4o with language selection (English & Persian), user authentication via whitelist, and persistent chat history using SQLite.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages