A small Java Spring Boot Telegram bot that fetches official exchange rates from the Central Bank of Russia (CBR) and shows basic weather information using a public weather API. The project is minimal and intended for development or small demos.
What it does
- Fetches USD and EUR official rates from the CBR XML feed and returns them on /usd and /eur commands.
- Provides a simple /weather command: the bot asks for a city name and returns the current temperature (°C) from WeatherAPI.
- Runs as a Telegram bot using the
telegrambotslibrary and OkHttp for HTTP calls.
Key files / classes
src/main/java/de/oyehiazarian/exchange_bot/ExchangeBotApplication.java— Spring Boot entry point.src/main/java/de/oyehiazarian/exchange_bot/bot/ExchangeRatesBot.java— Telegram bot with commands (/start, /help, /usd, /eur, /weather).src/main/java/de/oyehiazarian/exchange_bot/client/CbrClient.java— HTTP client using OkHttp to get CBR XML and weather JSON.src/main/java/de/oyehiazarian/exchange_bot/service/impl/ExchangeRatesServiceImpl.java— parses CBR XML to extract rates.src/main/java/de/oyehiazarian/exchange_bot/service/impl/WeatherServiceImpl.java— parses weather JSON to get temperature.
Configuration
The project reads a few properties from src/main/resources/application.properties:
bot.token— Telegram bot token (currently present in the file; remove before sharing publicly).cbr.currency.rates.xml.url— CBR XML URL (default:http://www.cbr.ru/scripts/XML_daily.asp).api.key— WeatherAPI key (currently present in the file; keep secrets out of the repo).
Quick start
- Requirements: Java 21, Maven 3.6+, Internet access.
- Build:
mvn clean package -DskipTests- Run:
java -jar target/exchange-bot-0.0.1-SNAPSHOT.jarOr run with Maven during development:
mvn spring-boot:runNotes and precautions
- The repository currently contains secrets (Telegram token and API key) in
application.properties. Remove or replace them and use environment variables or an external config for production. - Use the bot in
testmode (or with a test Telegram bot) before using it in production. - The bot username returned by the code is
exchange_money001bot(seeExchangeRatesBot#getBotUsername).