Telebot is a Rust-based Telegram bot framework designed to manage and interact with services. The bot enables users to communicate with various services and receive updates or notifications via Telegram. Currently, the project includes a Milk Price Service that scrapes websites to monitor milk prices and notifies users of price changes.
This project uses the teloxide library to handle the Telegram interface, simplifying bot interactions and updates.
- Telegram Bot Integration: Seamless interaction with Telegram users powered by the
teloxide
library. - Milk Price Monitoring: Scrapes milk prices from a predefined website and notifies users of any changes.
- SQLite Database Support: Stores data locally in an SQLite database.
- Containerized Deployment: Includes a
Dockerfile
and scripts for building and running the bot in a container. - Environment Variable Management: Easily configurable through an environment variable script (
env_vars.sh
).
telebot/
├── Cargo.lock # Rust dependency lockfile
├── Cargo.toml # Rust project manifest
├── db/ # Database files and initialization scripts
│ ├── creation.sql # SQL script for initializing the database
│ └── sqlite.db # SQLite database file
├── Dockerfile # Container setup for the bot
├── env_vars.sh # Script to define environment variables
├── LICENSE # License file
├── local-db # Directory for local database persistence
├── README.md # Project documentation
├── scripts/ # Utility scripts
│ ├── build_image.sh # Script to build the Docker image
│ ├── get_version.sh # Script to retrieve the bot version
│ ├── push_image.sh # Script to push Docker image to a registry
│ └── run_telebot.sh # Script to run the bot
└── src/ # Source code for the bot
├── chat.rs # Telegram chat logic
├── constants.rs # Constants used throughout the bot
├── db.rs # Database interaction logic
├── main.rs # Main entry point of the application
├── milk_price.rs # Milk price scraping and notifications
└── services.rs # Service management logic
- Rust (version 1.70 or later recommended)
- Docker (optional for containerized deployment)
- Telegram Bot API token
- SQLite for database support
- Clone the repository:
git clone https://github.com/yourusername/telebot.git
cd telebot
- Set up the environment variables:
source env_vars.sh
- Run the bot:
cargo run
Docker Deployment
- Build the Docker image:
./scripts/build_image.sh
- Run the bot in a container:
./scripts/run_telebot.sh
- (Optional) Push the Docker image to a registry:
./scripts/push_image.sh
- Description: Monitors the price of milk on a specific website and notifies users of changes.
- Implementation: Located in src/milk_price.rs.
- Command: /milk_price
To add a new service:
- Create a new module in the src directory (e.g., new_service.rs).
- Implement the service logic (e.g., web scraping, API integration, etc.).
- Register the service in src/services.rs.
- Update the bot commands in src/chat.rs.
- Create src/weather.rs for weather monitoring:
pub fn get_weather() -> String {
"Current weather: Sunny, 25°C".to_string()
}
- Register it in src/services.rs:
pub mod weather;
- Update the chat logic in src/chat.rs:
if command == "/weather" {
let response = services::weather::get_weather();
bot.send_message(chat_id, response).await?;
}
Contributions are welcome! Feel free to submit a pull request for new features, bug fixes, or documentation updates.
This project is licensed under Apache-2.0.