This WeatherBot is a Telegram bot that provides users with real-time weather updates and personalized location-based forecasts. It is powered by the OpenWeatherMap API and offers a seamless experience for users to get weather information instantly.
Additionally, the project includes an admin control panel backend for managing user preferences, locations, and bot functionality.
Built with the lightweight and robust grammY framework for Telegram bot development, the bot is designed to handle user interactions efficiently, while the server handles data validation, persistence, and API integrations.
-
Real-Time Weather Updates Users can query the bot for live weather data, including temperature, humidity, and conditions.
-
Personalized Location-Based Forecasts Users can set their preferred locations and receive forecasts for those locations.
-
Natural Language Interaction Users can input city names, and the bot will validate and respond conversationally.
-
Location Validation Checks the validity of user-provided locations using OpenWeatherMap’s Geocoding API before saving them.
-
User Management Admins can view and manage user data and preferences through an intuitive control panel.
-
Error Handling Ensures smooth operation by handling invalid data, network issues, and API errors gracefully.
- grammY: A robust Telegram bot framework for handling bot interactions.
- OpenWeatherMap API: Fetches weather data and validates locations.
- Node.js: Backend runtime environment.
- TypeScript: Strongly typed programming language.
- Express.js: Fast and lightweight web framework.
- Mongoose: MongoDB Object Modeling for Node.js.
- MongoDB: Database for storing user preferences and data.
- dotenv: For environment variable management.
- Node.js (v14 or above)
- npm or yarn
- A valid OpenWeatherMap API Key
- A Telegram bot token from BotFather
-
Clone the repository:
git clone https://github.com/deepsingh132/weatherbot.git cd weatherbot
-
Install dependencies:
npm install
-
Set up environment variables: Create a
.env
file in the root directory (see Environment Variables). -
Start the server and bot:
npm run start
Set up the following keys in a .env
file:
PORT=5000
OPENWEATHER_API_KEY=your_openweathermap_api_key
MONGODB_URI=your_mongodb_connection_string
BOT_TOKEN=your_telegram_bot_token
TOKEN_SECRET=your_token_secret (any random string)
Command | Description | Example |
---|---|---|
/start |
Starts interaction with the bot. | /start |
/current <city> |
Fetches current weather for a city. | /current New York |
/subscribe |
Saves a preferred location. | /subscribe |
/unsubscribe |
Removes a saved location | /unsubscribe |
/update_city |
Configures location updates. | /update_city |
/update_frequency |
Configures frequency updates. | /update_frequency |
/help |
Displays help information. | /help |
/about |
Provides information about the bot. | /about |
This project is licensed under the GPL v3 License. See the LICENSE file for details.
Developed with ❤️ by Mandeep Singh