Overview
The Price Tracker Bot requires minimal configuration to get started. This guide walks you through creating the necessary configuration files, setting up data persistence, and ensuring proper file permissions.Prerequisites
Before setting up the bot, ensure you have:- Node.js 16+ installed
- A Telegram Bot Token from @BotFather
- Playwright browsers installed (
npx playwright install chromium)
The bot uses Playwright with Chromium for web scraping. The first run may take longer while Playwright downloads the browser binaries.
Environment File Setup
Creating the .env File
The bot uses a.env file to store sensitive configuration. Create this file in your project root:
.env
Token Validation
The bot validates the presence ofTELEGRAM_TOKEN at startup. If the token is missing, the application will exit immediately:
index.mjs (lines 11-15)
Data Persistence Configuration
Storage File
The bot stores all product data and chat subscriptions in a JSON file:index.mjs (line 20)
- products: All tracked products with price history
- chats: Registered chat IDs for notifications
Data Structure
The persistence file follows this structure:Loading Data on Startup
The bot loads existing data during initialization:index.mjs (lines 24-39)
History Limit Configuration
To prevent unbounded growth of price history, the bot limits stored records:index.mjs (line 69)
Maximum number of price history entries to retain per product. Older entries are automatically removed.
You can modify
HISTORY_LIMIT directly in the source code. Higher values provide longer history but increase file size.File Permissions
Read/Write Access
Ensure the bot has proper permissions to create and modifyprices.json:
Directory Permissions
The bot should run in a directory where it can create files:Running the Bot
First Launch
After configuration, start the bot:Testing Configuration
- Send
/startto your bot in Telegram - Add a test product with
/add [amazon-url] - Verify data persistence by restarting the bot and checking the product is still tracked
Backup Strategy
Manual Backups
Regularly backup yourprices.json file:
Automated Backups
Consider using a cron job for automatic backups:The bot automatically saves data after every change, so you don’t need to manually trigger saves.
Troubleshooting
Bot Won’t Start
Symptom: Bot exits immediately with “TELEGRAM_TOKEN no definido” Solution:- Verify
.envfile exists in the project root - Check the token is on a line starting with
TELEGRAM_TOKEN= - Ensure no spaces around the
=sign
Data Not Persisting
Symptom: Products disappear after restart Solution:- Check file permissions on
prices.json - Verify disk space is available:
df -h - Look for write errors in bot console output
Corrupted Data File
Symptom: Bot starts with empty data despite existingprices.json
Solution:
- Validate JSON syntax:
jq . prices.json - Restore from backup if available
- Bot will create fresh file if current one is deleted
Next Steps
Environment Variables
Learn about all available configuration options
Scheduling
Configure automated price checks and summaries