Introduction
Over the last few days, I built something I had always wanted to experiment with: a completely serverless, fully automated, AI-powered Twitter (X) bot that runs continuously, tweets on a customizable schedule, summarizes news using AI, manages its own history, and costs literally $0 to operate.
This article explains every technical detail of how the system works, how it is structured, and how the workflow remains stable without relying on a dedicated server.
If you are interested in automation, AI pipelines, APIs, GitHub Actions, or simply want to build your own bot, this article serves as a complete blueprint you can follow.
Demo
The role of low-complexity repeats in RNA–RNA interactions and a deep learning framework for duplex prediction. Interactions between long RNA molecules play essential roles in shaping gene regulation.#news #AI #tipshttps://t.co/0YBV0NKONS
— Taha (@seabasszealot) January 24, 2026
Overview
This project performs five core tasks:
1. Fetches Real-Time News Articles
Using a News API combined with user-defined keywords.
2. Summarizes Articles Using AI
A lightweight LLM condenses the information into concise tweet-sized summaries.
3. Tweets Automatically on a Schedule
Users can configure custom cron schedules to determine when tweets are posted.
4. Prevents Duplicate Tweets
The bot tracks both daily tweets and historical tweets to avoid reposting duplicate content.
5. Runs Entirely on GitHub Actions
- No server
- No VPS
- No cloud hosting
- No cron jobs running locally
- No operational costs
GitHub effectively becomes the server by executing workflows on a schedule and committing updated state back into the repository.
Project Architecture & Structure
Below is the final architecture of the bot:
[Scheduler/manual run]
|
v
main.py ─▶ fetcher.fetch_news() ─▶ summarizer.summarize_article()
| |
| └─▶ score_summary()
|
└─▶ storage.save_daily_tweets()
│
├─▶ storage.filter_duplicates()
|
└─▶ storage.save_tweets_to_history()
│
└─▶ tweeter.tweet_daily()
Project structure:
ai-twitter-bot/
├── architecture.txt # Textual architecture overview
├── config/
│ └── config.py # Keyword and limit configuration
├── data/
│ ├── daily_tweets.txt # Current cycle's tweets
│ └── tweets.txt # Long-term tweet history
├── fetcher.py # NewsAPI client
├── helper.py # Debug print helpers
├── main.py # Orchestrates the end-to-end workflow
├── requirements.txt # Python dependencies
├── storage.py # Disk persistence and deduplication helpers
├── summarizer.py # Hugging Face summarization pipeline
├── tweeter.py # X/Twitter posting utilities
└── README.md
Each component has a dedicated responsibility, making the architecture modular and maintainable.
Credentials & Environment Setup
Before execution, the bot loads the following credentials:
X_API_KEYX_API_KEY_SECRETACCESS_TOKENACCESS_TOKEN_SECRETNEWS_API_KEY
These credentials are securely stored inside GitHub repository secrets and injected into the workflow environment during execution.
News Fetching System
File: fetcher.py
This module retrieves real-time news articles using a News API based on topics specified by the user.
The topics are configured through the NICHE_KEYWORDS list located in config.py.
Example request:
url = f"https://newsapi.org/v2/top-headlines?q=AI&apiKey={key}"
The system extracts:
- Article titles
- Article content
- Article URLs
These articles are then passed into the summarization pipeline.
AI Summarization Engine
File: summarizer.py
Once the articles are fetched, the AI summarization pipeline processes them.
The summarization prompt is designed to:
- Condense articles into a single tweet-sized sentence
- Preserve factual accuracy
- Avoid unnecessary hashtags or emojis
- Remove repetition and irrelevant details
- Focus on the primary takeaway
Example summary:
"Meta unveils a new AI model designed to assist developers in building multimodal applications more efficiently."
The generated summaries are then filtered, cleaned, scored, and stored inside a top_summaries list for tweet selection.
Tweet Queue System
The bot uses two files to manage tweet history and deduplication.
daily_tweets.txt
Stores tweets sent during the current cycle or day.
This prevents duplicate tweets within the same execution window.
tweets.txt
Acts as a permanent archive of every tweet ever posted by the bot.
This provides:
- Historical tracking
- Predictable behavior
- Easier debugging
- Long-term deduplication
Twitter (X) API Integration
File: tweeter.py
The project uses the Twitter API v2, specifically:
client.create_tweet()
Why Twitter API v2?
Because the free Twitter API tier no longer supports posting through v1.1, while v2 still allows tweet creation with a valid application setup.
Example request:
response = client.create_tweet(text=tweet)
If tweet publishing fails, the system logs the error and safely stops execution to prevent corrupted or inconsistent state updates.
Core Pipeline Execution
File: main.py
The execution pipeline follows a simple but reliable sequence:
- Fetch news articles
- Generate AI summaries
- Score generated summaries
- Store the best summaries
- Post tweets while checking historical data
- Update:
daily_tweets.txttweets.txt
This guarantees consistency across executions while keeping the workflow deterministic.
Commit & Push Logic (Serverless Persistence)
Because GitHub Actions workflows execute in temporary environments, any generated data must be committed back into the repository after execution.
Workflow step:
- name: Commit updated data files
run: |
git add data/
git commit -m "Auto-update tweet history" || echo "No changes"
Then:
- name: Push changes
run: git push
This mechanism is what makes the bot stateful despite operating without a traditional server.
Scheduling with GitHub Actions
File: .github/workflows/tweet.yml
The workflow scheduler triggers the bot automatically using cron syntax.
Example:
on:
schedule:
- cron: "0 * * * *"
Meaning:
- Run every hour
- Fully customizable schedule
- No server required
- No hosting costs
GitHub Actions effectively behaves like a free serverless cron infrastructure.
Testing & Debugging Strategy
1. Local Testing
The entire workflow can be tested locally using:
python3.11 main.py
2. Remote Testing
GitHub Actions also supports manual workflow triggering using:
workflow_dispatch:
This allows testing directly from the GitHub interface.
3. Error Logging
The bot provides clear logs for:
- API failures
- Missing environment variables
- Invalid credentials
- Duplicate tweet attempts
This significantly simplifies debugging and maintenance.
Cost Breakdown
This entire infrastructure costs:
$0 per month
Because:
- Twitter API v2 posting is free
- GitHub Actions includes 2,000 free minutes per month
- News APIs provide free tiers
- AI summarization can use lightweight local or free models
- No VPS or dedicated server is required
What I Learned
Building this project taught me a great deal about designing complete AI-driven automation pipelines.
Key areas I explored include:
- Twitter API v2 integration
- OAuth authentication
- Posting automation
- API error handling
- Workflow automation with GitHub Actions
- Cron scheduling
- Repository persistence
- Environment variable management
- Python modular architecture
- Secure secret handling with
.envfiles and GitHub Secrets
This project also improved my understanding of designing scalable and maintainable automation systems.
Conclusion
This project originally started as a simple idea:
"What if I could automate the entire tweeting process using AI, completely for free?"
The answer turned out to be: absolutely.
The final system is:
- Scalable
- Customizable
- Fully automated
- Serverless
- Permanently running
- Free to operate
This architecture can easily be adapted for:
- AI-generated content
- News bots
- Personal branding
- Community automation
- Daily knowledge sharing
- Content pipelines
If you'd like to explore the full source code here, feel free to fork it, improve it, or reach out. I always enjoy connecting with other builders and discussing automation projects.
