How yugesh-003/whatsapp-news-sender works
Project Type and Purpose
• This is an open-source, command-line Python application that:
• Fetches news articles from News API
• Converts text to speech via AWS Polly
• Sends the resulting audio via WhatsApp using Twilio (with SMS/MMS fallback)
• The single-script structure (news_to_audio.py) and minimal file tree indicate it follows a simple pipeline pattern with external service integrations.
A. Configuration Module
• Reads environment variables from .env (API keys, AWS credentials, Twilio credentials).
• Handles CLI arguments (--category, --country, --count, --create-env).
B. News Fetcher
• Invokes News API REST endpoint.
• Parses JSON response into a list of articles.
C. Text-to-Speech Converter
• Sends article text to AWS Polly.
• Receives and stores audio file(s) in the output/ directory.
D. Messaging Sender
• Primary: Twilio WhatsApp API
• Fallback: Twilio SMS/MMS API
• Attaches or uploads the generated audio file.
E. Persistence
• Local file storage for audio (output folder)
• (Implicit) Temporary in-memory structures for article metadata.
Relationships & Data Flow
• Start → Configuration
• Load credentials & parse CLI arguments
• Configuration → News Fetcher
• Pass in category, country, count
• News Fetcher → Text-to-Speech Converter
• For each article text
• Text-to-Speech Converter → Persistence
• Write out .mp3 or .ogg files
• Persistence → Messaging Sender
• Retrieve file paths, feed into Twilio APIs
• Messaging Sender → External Services
• WhatsApp channel → if success: DONE
• else → SMS/MMS channel
• End
Architectural Patterns & Principles
• Pipeline Pattern: data flows through distinct stages (fetch → transform → deliver)
• Single Responsibility: each logical component has a focused role
• External Integration Points: clearly separate wrappers for News API, AWS Polly, Twilio
• Fail-fast and Fallback: WhatsApp primary, SMS/MMS fallback