This project is a Telegram bot powered by OpenAI's GPT-4o-mini model and LangChain. Designed as a boilerplate, the structure is highly customizable, with detailed comments and examples for easy future development. The bot is capable of handling general queries, performing web searches, and managing appointment scheduling and rescheduling.
- 💬 General Queries: Answer user questions using the LLM.
- 🌐 Web Search: Search the web for the latest information.
- 📅 Appointment Scheduling: Schedule and reschedule appointments.
- 🌦️ Current Weather: Provide real-time weather updates.
Analyzes user queries using ReAct to determine which sub-agent should handle the task.
- Agent 0: Handles general-purpose queries (e.g.,
answer_questions
,web_search
,current_weather
). - Agent 1: Manages appointment-related queries (e.g.,
schedule_appointment
,reschedule_appointment
).
To create a Telegram bot:
- Open Telegram and search for the BotFather.
- Type
/newbot
and follow the prompts to create your bot. - Once done, you will receive an API token that will be used to authenticate your bot.
-
📥 Clone the repository:
git clone https://github.com/osamatech786/Telegram-Bot cd Telegram-Bot
-
🐍 Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows, use `venv\Scripts\activate`
-
📦 Install dependencies:
pip install -r requirements.txt
-
🔑 Set up environment variables: Create a
.env
file in the project root and add your API keys:OPENAI_API_KEY=your_openai_api_key SERPAPI_KEY=your_serpapi_key TELEGRAM_BOT_TOKEN=your_telegram_bot_token OPENWEATHER_API_KEY=your_openweather_key
To start the bot, run:
python tg_bot_main.py
💡 Usage
- /start: Send this command to receive a welcome message.
- /help: Get instructions on how to use the bot.
- Ask questions: Simply type your question or command, and the bot will respond accordingly.
📊 Logging
The bot uses Python's logging
module to log important events and errors. Logs include timestamps and log levels, printed directly to the console.
🔗 References
📜 License
This project is licensed under the MIT License.