A simple Telegram bot written in Go that fetches the current price of Bitcoin and Gold (per ounce) in USD, as well as USD to IRR (Iranian Rial) exchange rate and Gold price in IRR.
- Get Bitcoin price in USD
- Get Gold price in USD
- Get USD to IRR exchange rate
- Get Gold price in IRR (Iranian Rials)
- Get all prices at once
- Hourly automatic price updates (price cache refreshes every hour)
- Subscribe to automatic price updates at custom intervals
- Use in both private chats and group chats/channels
/start- Starts the bot/help- Shows available commands/price- Get all available prices (Bitcoin, Gold in USD, USD to IRR, Gold in IRR)/bitcoin- Get Bitcoin price in USD/gold- Get Gold price in USD/usd- Get USD to IRR exchange rate/goldirr- Get Gold price in IRR/refresh- Force refresh of all price data/subscribe <minutes>- Subscribe to price updates (e.g.,/subscribe 30for updates every 30 minutes)/unsubscribe- Stop receiving price updates/status- Check subscription status and cache information
The bot automatically fetches and caches all price data:
- Hourly Updates: The price data is automatically refreshed at the top of each hour
- Command Responses: All price commands first check the cache before fetching fresh data
- Cache Validity: Cached data is considered valid for up to 70 minutes
- Manual Refresh: You can force a cache refresh with the
/refreshcommand
- Add the bot to your group or channel
- Make the bot an admin (for channels) to allow it to post messages
- Use the
/subscribecommand to set up automatic updates - The bot will automatically send price updates at the specified interval
- Create a Telegram bot via BotFather and get your bot token
- Set the required environment variables:
# For Windows PowerShell
$env:TELEGRAM_BOT_TOKEN="your_telegram_bot_token"
# For Linux/macOS
export TELEGRAM_BOT_TOKEN="your_telegram_bot_token"- Run the bot:
go run main.go- Create a Telegram bot via BotFather and get your bot token
- Create a
.envfile with your bot token (you can copy from.env.example):
cp .env.example .env- Edit the
.envfile to add your bot token:
TELEGRAM_BOT_TOKEN=your_telegram_bot_token_here
- Build and run with Docker Compose:
docker-compose up -d- Check logs:
docker-compose logs -f- To stop the bot:
docker-compose down- Bitcoin price: CoinGecko API
- Gold price in USD: Metals.live API
- USD to IRR exchange rate: TGJU.org
- Gold price in IRR: TGJU.org
For production use, you might want to:
- Add error handling for API rate limits
- Implement database storage for the price cache
- Add monitoring for failed scraping attempts
- Set up a proxy for more reliable access to the websites being scraped
- Persist subscriptions to a database to survive bot restarts
├── main.go # Main application code
├── .env.example # Example environment variables
├── .env # Environment variables (not committed to git)
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .gitignore # Git ignore file
└── logs/ # Generated logs directory