A Python automation script that monitors Amul's Protein Lassi products for stock availability and sends WhatsApp notifications when items are in stock (quantity > 100). Can be adapted to track any product available on shop.amul.com.
- Overview
- Features
- Architecture
- Technical Challenges
- Deployment Options
- Setup & Installation
- Environment Variables
- Usage
- Learning Journey
- Troubleshooting
- Future Improvements
This is a personal convenience project to track availability of Amul's Protein Lassi products, which often go out of stock quickly. The bot automatically checks stock levels every hour and sends WhatsApp notifications when items are available.
Note: This is a personal project and not ready for production use. It's specifically designed for my needs but can be adapted for other Amul products.
- Automated Stock Monitoring: Checks Amul's internal API for Protein Lassi availability
- Smart Filtering: Focuses specifically on products with "lassi" in their alias
- WhatsApp Notifications: Sends formatted messages via Twilio WhatsApp API
- Multi-Region Support: Includes substore IDs for Delhi, Bangalore, and Mumbai regions
- Threshold-Based Alerts: Only alerts when stock quantity exceeds 100 units
- Multiple Deployment Options: Supports local execution, Vercel, GitHub Actions, and AWS Lambda
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
β Scheduler βββββΆβ Stock Bot βββββΆβ Twilio API β
β (Cron/Lambda) β β β β (WhatsApp) β
βββββββββββββββββββ β 1. API Call β βββββββββββββββββββ
β 2. Parse Data β β
βββββββββββββββββββ β 3. Filter Items β βΌ
β Amul API ββββββ 4. Send Alerts β βββββββββββββββββββ
β (shop.amul.com) β β β β Your Phone β
βββββββββββββββββββ ββββββββββββββββββββ βββββββββββββββββββ
Problem: Amul's website doesn't publicly document their API and uses JavaScript blockers
- Main website is hard to scrape due to pincode requirements and JS blocking
- Tried cookie copying methods but didn't work
- Solution: Used browser dev tools Network tab, filtered by Fetch/XHR to find the actual API endpoint they hit
Problem: Amul's API blocks requests from cloud service IP ranges (AWS Lambda, Vercel, GitHub Actions)
- Works fine locally with simple curl requests
- Fails silently on cloud platforms, returning empty
data
arrays - API returns valid JSON structure but with no actual product data
Solutions:
- Added browser-like headers (User-Agent, Referer, etc.)
- Implemented retry logic with exponential backoff
- Tested different AWS regions - only ap-south-1 (Mumbai) worked consistently
- GitHub Actions worked rarely, mostly returned empty data
Problem: Default 3-second Lambda timeout insufficient for API call + Twilio messaging Solution: Increased timeout to 10 seconds and added proper error handling
- Local Success: curl worked perfectly in local environment
- Library Issues: Python
requests
library faced same IP blocking issues - Subprocess Approach: Using
subprocess.run()
with curl provided better reliability - Header Control: Easier to replicate exact browser behavior with curl
To use this bot for your region, you need to find your substore ID:
- Go to shop.amul.com
- Navigate to protein section
- Open browser dev tools (F12)
- Go to Network tab, filter by Fetch/XHR
- Reload the page
- Look for the API call to
/api/1/entity/ms.products
- The substore ID will be at the end of the URL
Current substore IDs included:
- Delhi:
66505ff5145c16635e6cc74d
- Bangalore:
66505ff0998183e1b1935c75
- Mumbai:
66506004a7cddee1b8adb014
- Pros: Serverless, automatic scaling, integrated with EventBridge for scheduling
- Cons: Only works in ap-south-1 region
- Reality: Only ap-south-1 (Mumbai) region works consistently - other regions get blocked
- Pros: Easy deployment, webhook-triggered execution
- Cons: Not ideal for scheduled tasks, IP blocking issues
- Reality: Hit or miss due to IP blocking
- Pros: Free, version controlled, scheduled execution
- Cons: IP blocking, limited to public repositories for free tier
- Reality: Rarely works - mostly returns empty data due to IP blocking
- Pros: No IP restrictions, full control, works every time
- Cons: Requires dedicated server, manual maintenance
- Best For: Personal use, guaranteed reliability
- Python 3.8+
- Twilio Account with WhatsApp Business API
- Environment variables configuration
# Clone the repository
git clone https://github.com/yourusername/amulstockbot.git
cd amulstockbot
# Install dependencies
pip install -r requirements.txt
# Set up environment variables
cp .env.example .env
# Edit .env with your credentials
# Run locally
python main.py
# Create deployment package
mkdir deployment
pip install twilio -t deployment/
cp main.py deployment/
cd deployment
zip -r ../amul-stock-bot.zip .
# Upload to Lambda and set handler to: main.lambda_handler, make sure to create a lambda_handler function.
Create a .env
file with the following variables:
# Twilio Configuration
ACCOUNT_SID=your_twilio_account_sid
AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE=your_twilio_whatsapp_number
MY_PHONE=your_phone_number
# Optional: For Vercel webhook protection
WEBHOOK_KEY=your_secret_key
python main.py
# Add to crontab for hourly execution
0 * * * * /usr/bin/python3 /path/to/amulstockbot/main.py
curl "https://your-vercel-app.vercel.app/run?key=your_webhook_key"
This project was a good way to learn several technologies:
- AWS Lambda: Serverless functions, event triggers, and deployment packages
- EventBridge: Cron-like scheduling in AWS
- Vercel: Serverless deployment for Python Flask applications
- Cron Jobs: Unix cron syntax and scheduling
- GitHub Actions: YAML workflow configuration and scheduled triggers
- Event-Driven Architecture: Triggers and automated responses
- Rate Limiting: API rate limiting issues
- IP Whitelisting: Cloud provider IP blocking by e-commerce sites
- Header Manipulation: Proper HTTP headers for API access
- Error Handling: Retry mechanisms and timeout handling
- Twilio WhatsApp API: Business messaging capabilities
- Content Templates: Twilio's message templates for structured notifications
- Webhook Security: Basic authentication for webhook endpoints
- CloudWatch Logs: Debug serverless functions using AWS logs
- Environment-Specific Issues: Differences between local and cloud execution
- Timeout Management: Execution time vs. cost optimization
-
Empty Data Response
- Check if running from cloud provider IP
- Try different AWS regions
- Consider using proxy services
-
Lambda Timeout
- Increase function timeout (default 3s β 10s)
- Optimize API call timeouts
- Add proper error handling
-
Twilio Authentication Errors
- Verify ACCOUNT_SID and AUTH_TOKEN
- Check WhatsApp number format (+country_code)
- Ensure Content Template ID is correct
Since this is a personal project, these are more like "maybe someday" ideas:
- Proxy Integration: Add residential proxy support for IP blocking
- Database Storage: Track stock history and price changes
- Multiple Products: Expand beyond Protein Lassi to other Amul products
- Smart Notifications: Avoid spam by tracking previous alerts
- Price Alerts: Notify on price drops or offers
- Multiple Recipients: Support family/friend groups
- Custom Thresholds: User-configurable stock quantity limits
- Web Dashboard: Simple UI to view stock status
- Monitoring: Add health checks and alerting
- CI/CD Pipeline: Automated testing and deployment
- Cost Optimization: Fine-tune Lambda execution time
This project uses Amul's internal API found through browser dev tools. The API is not publicly documented. This is for personal/educational use only. Please respect Amul's terms of service and don't abuse their API.
This is a personal convenience project, but feel free to fork it for your own use!
Built while learning cloud technologies and trying to get protein lassi