Skip to content

jatinnxn/Telegram-Chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Telegram Chatbot with GPT Integration

This project is a Telegram chatbot that integrates OpenAI's GPT models, allowing users to interact with the bot and ask questions. The bot responds using the GPT model and provides relevant answers to the user's queries. Additionally, a basic Flask web server is included to demonstrate the project running as a background service.

Features

  • Telegram bot interface using the aiogram library.
  • Integration with OpenAI's GPT API to provide intelligent responses.
  • Basic Flask server running in a background thread.
  • Easy-to-deploy project with environment variable support.

Prerequisites

  1. Python: Make sure Python 3.8 or higher is installed on your system.
  2. Telegram Bot Token: Create a new bot on Telegram via BotFather and get the token.
  3. OpenAI API Key: Sign up on OpenAI and get your API key.

Installation

Step 1: Clone the repository

git clone https://github.com/your-username/telegram-chatbot-gpt.git cd telegram-chatbot-gpt

Step 2: Create a virtual environment

python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate

Step 3: Install dependencies

pip install -r requirements.txt

Step 4: Set up environment variables

Create a .env file in the root directory and add the following variables:

OPENAI_API_KEY=your-openai-api-key TELEGRAM_BOT_TOKEN=your-telegram-bot-token

Alternatively, you can export these variables in your shell:

export OPENAI_API_KEY=your-openai-api-key export TELEGRAM_BOT_TOKEN=your-telegram-bot-token

Step 5: Run the chatbot

You can now run the bot using the following command:

python bot.py

This will start the bot and Flask server in the background.

Project Structure

telegram-chatbot-gpt/

├── bot.py # Main Telegram bot code

├── example.py # Flask server running in a thread

├── requirements.txt # List of dependencies├── .env # Environment variables

└── README.md # Project documentation

bot.py

The main script that contains the code to handle incoming Telegram messages, call the OpenAI GPT API, and reply to the user.

example.py

Contains a simple Flask server that runs in the background to simulate additional services running alongside the bot.

Usage

  1. Start the bot: Once the bot is running, you can interact with it on Telegram.
  2. Send a message: The bot will respond to your queries using OpenAI's GPT model.

Example Commands:

  • /start: Starts the bot and sends a welcome message.
  • Any other text message will be processed by GPT-3.5 Turbo.

Dependencies

  • aiogram: Telegram bot framework for Python.
  • openai: OpenAI API library.
  • Flask: Lightweight web framework to run the example server.

Install dependencies via:

pip install aiogram openai Flask

Deployment

You can deploy this bot on platforms such as:

  • Heroku
  • Google Cloud
  • AWS

Make sure to properly set up your environment variables in your chosen deployment platform.

Contributing

If you would like to contribute to this project, feel free to fork the repository and submit a pull request.

Contact

If you have any questions, feel free to reach out or create an issue in the repository.


This README provides step-by-step instructions for setting up the bot and the basic functionality it offers. Adjust as needed for your specific project details.

About

this project is a Telegram chatbot powered by OpenAI's GPT model, allowing users to interact and receive intelligent responses. It utilizes the aiogram framework for handling messages and includes a simple Flask server running in the background. The bot is easily deployable and supports environment variables for secure API key management.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages