A Telegram bot that provides air quality information based on user location using the IQAir API.
- Asks users for their location
- Finds the closest air quality monitoring station using IQAir's
/nearest_stationendpoint - Retrieves accurate pollution data from the nearest monitoring station
- Falls back to city-level data if station data is unavailable
- Sends formatted air quality reports to users
- Python 3.7+
- Telegram Bot Token (from @BotFather)
- IQAir API Key (from IQAir)
-
Clone this repository:
git clone https://github.com/yourusername/air_quality_bot.git cd air_quality_bot -
Install the required packages:
pip install -r requirements.txtIf you encounter any import errors, make sure all dependencies are installed correctly:
pip install aiogram==3.2.0 python-dotenv==1.0.0 aiohttp~=3.9.0 geopy==2.3.0 -
Create a
.envfile in the project root and add your API keys:BOT_TOKEN=your_telegram_bot_token IQAIR_API_KEY=your_iqair_api_key
-
Make sure Docker and Docker Compose are installed on your system.
-
Create a
.envfile with your API tokens and user configuration:BOT_TOKEN=your_telegram_bot_token IQAIR_API_KEY=your_iqair_api_key # Docker user configuration DOCKER_USER=botuser DOCKER_UID=1000 DOCKER_GID=1000 -
Build and start the container:
docker-compose up -d -
Check the logs:
docker-compose logs -f
-
Run the bot:
Local:
python main.pyDocker:
docker-compose up -d -
Open Telegram and start a chat with your bot.
-
Use the
/startcommand to begin and share your location when prompted. -
The bot will send you air quality information for your location.
- 0-50: Good (✅)
- 51-100: Moderate (✳️)
- 101-150: Unhealthy for Sensitive Groups (
⚠️ ) - 151-200: Unhealthy (❗)
- 201-300: Very Unhealthy (❌)
- 301+: Hazardous (☣️)
/start- Start the bot and share your location/refresh- Get updated air quality data for your last shared location/help- Show help information
MIT