Skip to content

Commit

Permalink
Telegram_Bot Python Code
Browse files Browse the repository at this point in the history
  • Loading branch information
ParasY1724 authored Oct 29, 2024
1 parent 5dfd902 commit 0f818a6
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
72 changes: 72 additions & 0 deletions Advanced_Projects/Telegram_Bot/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Advanced Telegram Bot Project

This project is a feature-rich Telegram bot built using the `python-telegram-bot` library. The bot provides a variety of interactive commands and functionalities, such as weather updates, motivational quotes, and more.

## Features

- **Basic Commands**: Includes `/start`, `/help`, and `/info` commands to guide users.
- **Weather Updates**: Provides real-time weather information for any city, using an external API.
- **Motivational Quotes**: Offers daily motivational quotes with an option to get more via inline buttons.
- **Interactive Elements**: Inline keyboards for quick interactions, making the bot more engaging.
- **Error Handling**: Comprehensive logging and error handling for smooth operation.

## Setup and Installation

### 1. Install Dependencies

Ensure you have Python 3 installed. Then, install the required libraries:

```bash
pip install -r requirements.txt
```

### 2. Get API Keys

- **Telegram Bot API Key**: Create a bot through [BotFather on Telegram](https://core.telegram.org/bots#botfather) and get the token.
- **Weather API Key**: Sign up on [WeatherAPI](https://www.weatherapi.com/) or [OpenWeatherMap](https://openweathermap.org/) to obtain an API key.

### 3. Configure API Keys

Replace placeholders in `app.py` with your actual API keys:

```python
WEATHER_API_KEY = 'your_weather_api_key'
TELEGRAM_TOKEN = 'your_telegram_bot_token'
```

### 4. Run the Bot

Run the bot using:

```bash
python app.py
```

## Usage

Once the bot is running, you can interact with it on Telegram:

- **/start** - Starts the bot and displays a welcome message.
- **/help** - Lists available commands.
- **/weather `<city_name>`** - Retrieves the current weather for a specified city.
- **/motivate** - Sends a motivational quote with an inline option to get more quotes.

## Example Interactions

- `/start`: "Welcome! Use /help to see available commands."
- `/weather London`: "Weather in London: 18°C, Partly Cloudy"
- `/motivate`: "Stay positive, work hard, make it happen!" with a button for more quotes.

## Project Structure

```
├── app.py # Main bot code
├── README.md # Project documentation
└── requirements.txt # Dependencies
```

## Troubleshooting

- **TypeError**: If you encounter issues with the `Updater` class, ensure you're using `Application` instead (for `python-telegram-bot` v20+).
- **Network/API Errors**: Ensure API keys are correctly configured and active.

2 changes: 2 additions & 0 deletions Advanced_Projects/Telegram_Bot/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
python-telegram-bot
requests

0 comments on commit 0f818a6

Please sign in to comment.