A Telegram chatbot powered by OpenAI's GPT model. This bot allows users to have conversational interactions with an AI assistant directly through Telegram.
- AI-Powered Conversations: Utilizes OpenAI's GPT model for intelligent responses.
- Conversation Memory: Maintains context within a conversation session.
- Easy Commands: Simple commands to control the bot interaction.
- Privacy Focused: Uses environment variables to secure API keys.
- Python 3.7+
- Telegram Bot Token (from BotFather)
- OpenAI API Key (from OpenAI Platform)
- Clone or download this repository.
- Install required dependencies:
pip install -r requirements.txt
- Create a
.envfile in the project directory with your API keys:TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here OPENAI_API_KEY=your_openai_api_key_here - Run the bot:
python main.py
/start- Initialize the bot and receive a welcome message/help- Display help information and available commands/clear- Clear the conversation history and context- Send any text message to chat with the AI assistant
- The bot maintains conversation context using a reference class
- Each message you send is processed by OpenAI's GPT model
- Responses are sent back to you in the Telegram chat
- Use
/clearto reset the conversation when needed
The bot currently uses the GPT-5 model (as specified in the code). You can modify the model_name variable to use different OpenAI models if needed.
This bot was created for learning purpose. Make sure to comply with both Telegram's and OpenAI's terms of service when using this application.
- Ensure all environment variables are properly set in the
.envfile. - Verify that both API keys are valid and have sufficient credits.
- Check that your Python environment has all required dependencies installed.
This project is for demonstration purposes. Please ensure proper usage of both Telegram and OpenAI APIs according to their respective terms of service.