A GPT-3.5-powered Telegram chatbot built using Python, Aiogram, and Flask. The bot responds to user messages intelligently using OpenAI's Chat Completion API and remains active via a lightweight Flask web server — ideal for deployment on Replit or similar platforms.
- Handles
/startand/helpcommands - Generates AI responses using OpenAI GPT-3.5
- Uses environment variables for secure API key storage
- Keeps bot alive using a background Flask server (suitable for Replit)
- Clean, asynchronous structure with
aiogram
- Python
- Aiogram
- Flask
- OpenAI API
- Telegram Bot API
-
Clone the repository
git clone https://github.com/your-username/telegram-chatbot.git cd telegram-chatbot -
Install dependencies
pip install -r requirements.txt
-
Create a .env file in the root directory and add:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token OPENAI_API_KEY=your_openai_api_key
-
Run the bot
python main.py
telegram-chatbot/
│
├── main.py # Main bot logic and polling
├── example.py # Flask web server to keep the bot alive
├── requirements.txt
├── .gitignore
└── README.md
- Open Telegram and search for
@BotFather - Send
/newbotcommand - Follow the instructions to create your bot
- Copy the bot token provided
- Visit OpenAI Platform
- Sign up or log in to your account
- Navigate to API Keys section
- Create a new secret key
- Copy the API key
This bot is designed to work seamlessly on platforms like Replit, Heroku, or any cloud service that supports Python applications.
- Import your GitHub repository
- Add your environment variables in the Secrets tab
- Run the project
This project is open source and available under the MIT License.
Contributions, issues, and feature requests are welcome! Feel free to check issues page.
Vianyak Vinod
- GitHub: @therealvinayak