Skip to content

AminSS99/LensAI

Repository files navigation

LensAI Logo

πŸ”­ LensAI

We filter the noise to bring you the core of AI evolution.
Sharp analysis, organic design, zero filler.

Features β€’ Architecture β€’ Installation β€’ Deployment β€’ Usage β€’ Cost


🎯 What is LensAI?

LensAI is an AI-powered tech news aggregator that delivers personalized daily digests via Telegram. It scrapes top tech sources, summarizes them with AI, and sends you the most important stories β€” so you never miss what matters in AI and tech.

Key Highlights

  • πŸ“° Multi-source aggregation β€” Hacker News, TechCrunch, AI company blogs (Anthropic, DeepSeek, Qwen, Google AI, Mistral, DeepMind), The Verge, GitHub Trending
  • πŸ€– AI summarization β€” DeepSeek creates digestible, curated digests
  • πŸ”– Article saving β€” Save interesting articles to your personal collection
  • πŸ’¬ Q&A Chat β€” Ask any tech question and get AI-powered answers
  • ⏰ Scheduled delivery β€” Set your preferred daily digest time
  • 🌐 Multi-language β€” Full support for English, Russian, and Azerbaijani
  • ☁️ Cloud-native β€” Runs 24/7 on Google Cloud Functions with Firestore

✨ Features

Feature Description
πŸ“° News Scraping Fetches from Hacker News, TechCrunch, AI blogs (Anthropic, DeepSeek, Qwen, Google AI, Mistral, DeepMind), The Verge, GitHub Trending
🧠 AI Summarization Uses DeepSeek to create engaging, categorized news digests
πŸ›‘οΈ AI Fallback 3-tier degradation: AI β†’ Simple digest β†’ Raw list (never fails!)
πŸ”„ Retry Logic All scrapers retry 2x with exponential backoff for resilience
πŸ“¨ Smart Message Splitting UTF-8 safe splitting at natural boundaries (no emoji corruption)
πŸ”– Save Articles Save articles to Firestore with automatic categorization (AI, Security, Crypto, etc.)
πŸ“‚ Filter & Recap Filter saved articles by category, get weekly recaps
πŸ’¬ Interactive Q&A Ask questions about any tech topic and get AI responses
⚑ Smart Caching 15-minute cache prevents redundant API calls
πŸ”’ Distributed Lock Firestore-based locking prevents duplicate message sends
πŸŽ›οΈ Source Control Toggle news sources on/off via inline buttons
⏰ Custom Scheduling Set your preferred daily digest delivery time
🌐 Multi-language English, Russian, and Azerbaijani support

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    GOOGLE CLOUD                          β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                                                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                   β”‚
β”‚  β”‚ Cloud        │───▢│ Cloud        β”‚                   β”‚
β”‚  β”‚ Scheduler    β”‚    β”‚ Functions    β”‚                   β”‚
β”‚  β”‚ (your time)  β”‚    β”‚ (Python 3.11)β”‚                   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜                   β”‚
β”‚                             β”‚                           β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚  β”‚ Firestore    │◀─────────┼─────▢│ Telegram     β”‚     β”‚
β”‚  β”‚ Database     β”‚          β”‚      β”‚ Bot API      β”‚     β”‚
β”‚  β”‚ β€’ Users      β”‚          β”‚      β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚  β”‚ β€’ Articles   β”‚          β”‚             β”‚             β”‚
β”‚  β”‚ β€’ Locks      β”‚          β”‚             β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜          β”‚             β”‚             β”‚
β”‚                            β”‚             β”‚             β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”          β”‚             β”‚             β”‚
β”‚  β”‚ Secret       β”‚β—€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜             β”‚             β”‚
β”‚  β”‚ Manager      β”‚                        β”‚             β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                        β”‚             β”‚
β”‚                                          β”‚             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                           β”‚
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
    β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”                   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   News    β”‚                   β”‚     YOU      β”‚
    β”‚  Sources  β”‚                   β”‚  (Telegram)  β”‚
    β”‚ β€’ HN      β”‚                   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
    β”‚ β€’ TC      β”‚
    β”‚ β€’ AI      β”‚
    β”‚ β€’ Verge   β”‚
    β”‚ β€’ GitHub  β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

LensAI/
β”œβ”€β”€ functions/                    # Cloud Functions code
β”‚   β”œβ”€β”€ main.py                  # HTTP endpoints
β”‚   β”œβ”€β”€ telegram_bot.py          # Bot commands & handlers
β”‚   β”œβ”€β”€ summarizer.py            # DeepSeek AI integration
β”‚   β”œβ”€β”€ resilience.py            # Retry & backoff utilities (NEW)
β”‚   β”œβ”€β”€ fallback_digest.py       # Non-AI digest generator (NEW)
β”‚   β”œβ”€β”€ message_utils.py         # Smart message splitting (NEW)
β”‚   β”œβ”€β”€ cache.py                 # In-memory caching
β”‚   β”œβ”€β”€ database.py              # Firestore operations
β”‚   β”œβ”€β”€ distributed_lock.py      # Distributed locking
β”‚   β”œβ”€β”€ scrapers/
β”‚   β”‚   β”œβ”€β”€ hackernews.py        # Hacker News API
β”‚   β”‚   β”œβ”€β”€ techcrunch.py        # TechCrunch RSS
β”‚   β”‚   β”œβ”€β”€ ai_blogs.py          # AI company blogs
β”‚   β”‚   β”œβ”€β”€ theverge.py          # The Verge RSS
β”‚   β”‚   └── github_trending.py   # GitHub trending repos
β”‚   └── requirements.txt
β”œβ”€β”€ run_local.py                 # Local development runner
β”œβ”€β”€ test_scrapers.py             # Scraper tests
β”œβ”€β”€ .env.example                 # Environment template
β”œβ”€β”€ .gitignore                   # Security exclusions
β”œβ”€β”€ logo.jpg                     # Project logo
└── README.md                    # This file

πŸš€ Installation

Prerequisites

Local Development

# Clone the repository
git clone https://github.com/YOUR_USERNAME/LensAI.git
cd LensAI

# Create virtual environment
python -m venv venv
venv\Scripts\activate  # Windows
# source venv/bin/activate  # macOS/Linux

# Install dependencies
pip install -r functions/requirements.txt python-dotenv

# Set up environment variables
cp .env.example .env
# Edit .env with your API keys

# Run locally
python run_local.py

☁️ Deployment

Deploy to Google Cloud Functions

# 1. Login to Google Cloud
gcloud auth login

# 2. Set your project
gcloud config set project YOUR_PROJECT_ID

# 3. Enable required APIs
gcloud services enable cloudfunctions.googleapis.com cloudbuild.googleapis.com run.googleapis.com secretmanager.googleapis.com

# 4. Store secrets
gcloud secrets create TELEGRAM_BOT_TOKEN --replication-policy="automatic"
echo "YOUR_TOKEN" | gcloud secrets versions add TELEGRAM_BOT_TOKEN --data-file=-

gcloud secrets create DEEPSEEK_API_KEY --replication-policy="automatic"
echo "YOUR_KEY" | gcloud secrets versions add DEEPSEEK_API_KEY --data-file=-

# 5. Grant permissions
gcloud secrets add-iam-policy-binding TELEGRAM_BOT_TOKEN \
  --member="serviceAccount:YOUR_PROJECT_NUMBER-compute@developer.gserviceaccount.com" \
  --role="roles/secretmanager.secretAccessor"

gcloud secrets add-iam-policy-binding DEEPSEEK_API_KEY \
  --member="serviceAccount:YOUR_PROJECT_NUMBER-compute@developer.gserviceaccount.com" \
  --role="roles/secretmanager.secretAccessor"

# 6. Deploy function
gcloud functions deploy telegram_webhook \
  --gen2 \
  --runtime=python311 \
  --region=europe-west1 \
  --source=functions \
  --entry-point=telegram_webhook \
  --trigger-http \
  --allow-unauthenticated \
  --set-secrets="TELEGRAM_BOT_TOKEN=TELEGRAM_BOT_TOKEN:latest,DEEPSEEK_API_KEY=DEEPSEEK_API_KEY:latest" \
  --memory=512MB \
  --timeout=300s

# 7. Set Telegram webhook
curl "https://api.telegram.org/botYOUR_TOKEN/setWebhook?url=YOUR_FUNCTION_URL"

πŸ“± Usage

Bot Commands

Command Description
/start Welcome message with quick action buttons
/news Get your personalized news digest
/settime HH:MM Set daily digest time (24h format)
/sources Toggle news sources on/off
/status View your current settings
/help Show all commands
Any text Ask a question β€” AI will answer!

Quick Action Buttons

The bot provides persistent keyboard buttons for fast access:

  • πŸ“° Get News β€” Fetch latest digest
  • βš™οΈ Settings β€” Manage sources
  • πŸ“Š Status β€” View settings
  • ❓ Help β€” Show help

πŸ’° Cost

LensAI is designed to be extremely cost-effective:

Service Monthly Cost
DeepSeek API ~$1-3
Google Cloud Functions Free tier (2M invocations)
Secret Manager Free tier
Total ~$1-5/month

πŸ”’ Security

  • βœ… API keys stored in Google Cloud Secret Manager
  • βœ… .env files excluded from version control
  • βœ… No hardcoded credentials in source code
  • βœ… HTTPS-only webhook communication

πŸ”§ DevOps \u0026 Monitoring

Current Setup

LensAI is production-ready with:

  • βœ… Auto-scaling via Cloud Functions (0 to 6 instances)
  • βœ… Secrets management via Google Secret Manager
  • βœ… Distributed locking to prevent race conditions
  • βœ… Retry logic with exponential backoff
  • βœ… AI fallback for 100% uptime
  • βœ… Smart caching to reduce costs

Recommended DevOps Additions

1. Monitoring & Alerts

# Set up Cloud Monitoring alerts
gcloud alpha monitoring policies create \
  --notification-channels=YOUR_CHANNEL_ID \
  --display-name="LensAI Function Errors" \
  --condition-display-name="Error rate \u003e 5%" \
  --condition-threshold-value=0.05 \
  --condition-threshold-duration=300s

What to monitor:

  • Function error rate
  • Function execution time
  • DeepSeek API latency
  • Scraper success/failure rates
  • Message queue length

2. Logging

# Already implemented in code:
print(f"⚠️ {function_name} attempt {retry} failed")  # Retry logs
print(f"AI summarization failed: {e}")               # Fallback logs

View logs:

gcloud functions logs read telegram_webhook --region=europe-west1

3. Cost Optimization

Current optimizations:

  • 15-min cache reduces API calls
  • Smart message splitting prevents rate limits
  • Retry logic prevents wasted invocations

Additional recommendations:

  • Set up billing alerts at $5, $10, $20
  • Monitor DeepSeek API usage
  • Consider caching scraper results for 30min

4. Backup \u0026 Recovery

Firestore backups:

# Enable automatic backups
gcloud firestore backups schedules create \
  --database='(default)' \
  --recurrence=weekly \
  --retention=4w

Secret rotation:

# Rotate API keys every 90 days
gcloud secrets versions add DEEPSEEK_API_KEY --data-file=new_key.txt

5. CI/CD Pipeline

Recommended GitHub Actions workflow:

name: Deploy to GCP
on:
  push:
    branches: [main]

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: google-github-actions/setup-gcloud@v1
      - run: |
          gcloud functions deploy telegram_webhook \
            --gen2 --runtime=python311 ...

6. Health Checks

Set up health endpoint:

# Test function health
curl https://YOUR_FUNCTION_URL/health

Response:

{
  "status": "healthy",
  "timestamp": "2025-12-26T11:50:00Z"
}

Performance Metrics

Metric Target Current
Function cold start \u003c 3s ~2s
Digest generation \u003c 60s ~30-45s
Message delivery \u003c 5s ~2-3s
Scraper success rate \u003e 95% ~98%
AI fallback rate \u003c 5% ~1-2%

πŸ› οΈ Tech Stack

  • Language: Python 3.11
  • Bot Framework: python-telegram-bot
  • AI: DeepSeek API (OpenAI-compatible)
  • Cloud: Google Cloud Functions (Gen 2)
  • Scraping: httpx, BeautifulSoup, feedparser

πŸ“„ License

MIT License β€” feel free to use, modify, and distribute.


🀝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.


Made with ❀️ by Amin Sobor

About

We filter the noise to bring you the core of AI evolution. Sharp analysis, organic design, zero filler.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages