A comprehensive Python-based Amazon affiliate marketing bot that automates deal discovery, product search, and affiliate link management with Telegram integration and web dashboard analytics.
- π€ Telegram Bot: Interactive bot for deal discovery and product search
- π Web Dashboard: Real-time analytics and management interface
- ποΈ Deal Scraping: Automated scraping of Amazon deals (Today's Deals, Lightning Deals, Best Deals)
- π Keyword Search: Search Amazon products by keyword with affiliate tags
- πΌοΈ Image Extraction: Automatic product image extraction and display
- β Link Validation: Comprehensive affiliate link validation and tag verification
- π Analytics: Track clicks, conversions, and earnings
- π€ AI Content Generation: OpenAI-powered content generation for engaging posts
- Deal Quality Scoring: Filters deals by discount, rating, and review count
- Affiliate Tag Verification: Ensures affiliate tags persist after redirects
- Multi-Region Support: US, UK, DE, FR, CA, JP, AU, IN
- Deal of the Day Integration: Dedicated method for featured deals
- Rate Limiting: Smart rate limiting with exponential backoff
- Error Handling: Comprehensive error handling and logging
- Python: 3.11 or newer
- Database: PostgreSQL (recommended) or in-memory database for testing
- API Keys:
- Telegram Bot Token (from @BotFather)
- Amazon Affiliate ID (from Amazon Associates)
- OpenAI API Key (optional, for AI content generation)
git clone https://github.com/yourusername/AmazonAffiliatedBot.git
cd AmazonAffiliatedBotpython3 -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtOr install directly:
pip install .Create a .env file in the project root:
# Telegram Configuration
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
TELEGRAM_CHANNEL=@your_telegram_channel
# Amazon Affiliate
AMAZON_AFFILIATE_ID=one4allmarket-21
# Optional: Regional Affiliate IDs
AMAZON_AFFILIATE_ID_UK=your_uk_affiliate_id
AMAZON_AFFILIATE_ID_DE=your_de_affiliate_id
# ... etc for other regions
# OpenAI (Optional - for AI content generation)
OPENAI_API_KEY=your_openai_api_key
# Database Configuration
DATABASE_URL=postgresql://user:password@host/database?sslmode=require
PGDATABASE=your_database
PGHOST=your_host
PGPASSWORD=your_password
PGUSER=your_user
# Application Settings
MAX_DEALS_PER_SOURCE=5
POST_INTERVAL_MINUTES=6
REQUEST_TIMEOUT=30
RATE_LIMIT_DELAY=2
DEFAULT_REGION=US
# Web Dashboard
FLASK_HOST=0.0.0.0
FLASK_PORT=5000
FLASK_SECRET_KEY=your-secret-key-change-in-production
# Admin Users (comma-separated Telegram user IDs)
ADMIN_USER_IDS=123456789,987654321.env file to version control!
python main.pypython main.py botpython main.py webpython main.py post/start- Welcome message and setup/help- Show all available commands/deals- Get latest deals (all categories)/search <keyword>- Search products by keyword- Example:
/search wireless headphones
- Example:
/category- Set preferred product categories/region- Set your Amazon region/stats- View your statistics
/electronics- Electronics deals/home- Home & Kitchen deals/fashion- Fashion deals/sports- Sports & Outdoors deals/beauty- Beauty deals/books- Books deals
/admin- Admin panel/add_deal <url>- Manually add a deal/broadcast <message>- Broadcast message to all users
Access the dashboard at: http://localhost:5000
Features:
- Real-time deal statistics
- User analytics
- Deal management
- Configuration overview
- Health monitoring
AmazonAffiliatedBot/
βββ config.py # Configuration management
βββ scraper.py # Amazon deal scraper & product search
βββ telegram_bot.py # Telegram bot implementation
βββ main.py # Main application entry point
βββ web_dashboard_clean.py # Flask web dashboard
βββ link_validator.py # Affiliate link validation
βββ content_generator.py # AI content generation
βββ scheduler.py # Task scheduling
βββ database.py # PostgreSQL database manager
βββ database_simple.py # In-memory database (fallback)
βββ models.py # Data models
βββ static/ # Web dashboard static files
β βββ css/
β βββ js/
βββ templates/ # Web dashboard templates
β βββ base.html
β βββ dashboard.html
β βββ deals.html
β βββ users.html
βββ requirements.txt # Python dependencies
βββ example.env # Environment variables template
βββ README.md # This file
The bot automatically scrapes deals from multiple Amazon sources:
- Today's Deals
- Lightning Deals
- Best Deals
- Goldbox
Quality Filtering:
- Minimum 20% discount
- Minimum 4.0 star rating
- Minimum 50 reviews
- Deal freshness scoring
Search Amazon products by keyword:
products = await scraper.search_products_by_keyword(
keyword="wireless headphones",
max_results=20,
affiliate_id="one4allmarket-21"
)Features:
- Automatic affiliate tag appending
- Quality filtering (rating, reviews)
- Image extraction
- Complete product information
Products automatically include images:
- Extracted from Amazon product pages
- Full resolution URLs
- Fallback handling for missing images
- Displayed in Telegram messages
Ensures affiliate tags are correctly appended:
- Validates tag presence in URLs
- Verifies tags after redirects
- Logs warnings for missing tags
- Prevents revenue loss
Dedicated method for featured deals:
deal = await scraper.get_deal_of_the_day(
affiliate_id="one4allmarket-21"
)1. Bot not responding
- Check
TELEGRAM_BOT_TOKENin.env - Verify bot is running:
python main.py bot - Check logs:
tail -f dealbot.log
2. No deals found
- Amazon may be rate limiting - increase
RATE_LIMIT_DELAY - Check internet connection
- Verify Amazon pages are accessible
3. Affiliate links not working
- Verify
AMAZON_AFFILIATE_IDis correct - Check affiliate account status
- Review link validation logs
4. Database connection errors
- Verify PostgreSQL is running
- Check
DATABASE_URLformat - Ensure database exists
5. Images not displaying
- Check image URLs in logs
- Verify Amazon image CDN access
- Some images may expire (Amazon CDN limitation)
- Rate Limiting: Adjust
RATE_LIMIT_DELAYto balance speed vs. rate limits - Database: Use PostgreSQL for production (faster than in-memory)
- Caching: Consider caching deal results to reduce API calls
- Concurrent Requests: Adjust
max_concurrentin link validation
- Deal Scraping: 2-5 seconds per source
- Keyword Search: 3-8 seconds per search
- Link Validation: 1-3 seconds per link
- Image Extraction: <100ms per product
- Environment Variables: Never commit
.envfile - API Keys: Rotate keys regularly
- Database: Use strong passwords and SSL connections
- Input Validation: All user inputs are sanitized
- Rate Limiting: Prevents abuse and Amazon blocks
- Input sanitization in web dashboard
- URL validation before processing
- Affiliate tag format validation
- SQL injection protection (parameterized queries)
- XSS protection in web interface
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 guidelines
- Use type hints where possible
- Add docstrings to functions
- Write tests for new features
MIT License
Copyright (c) 2025 RafalW3bCraft
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- Amazon Associates Program
- Telegram Bot API
- OpenAI API
- BeautifulSoup for web scraping
- All contributors and users
For issues, questions, or contributions:
- Check the logs:
dealbot.log - Review the code documentation
- Open an issue on GitHub
- Contact the maintainer
- Amazon Product Advertising API (PA-API) integration
- Image caching and CDN support
- Advanced analytics dashboard
- Multi-language support
- Automated A/B testing for content
- Mobile app integration
- Webhook support for real-time updates
- β Image extraction implementation
- β Keyword search functionality
- β Affiliate tag verification
- β Deal of the Day integration
- β Enhanced error handling
- β Improved rate limiting
Track your affiliate performance:
- Total deals posted
- Total clicks
- Conversion rate
- Total earnings
- Active users
- Category breakdown
Access via:
- Telegram:
/stats - Web Dashboard:
/api/stats
Made with β€οΈ for Amazon Affiliate Marketers
Last Updated: 2025