Technical Deep-Dive of Building a Free Serverless AI Powered Twitter Bot
Over the last few days, I built something I’ve always wanted to experiment with a completely serverless, fully automated, AI-powered…
Technical Deep-Dive of Building a Free Serverless AI Powered Twitter Bot

Over the last few days, I built something I’ve always wanted to experiment with a completely serverless, fully automated, AI-powered Twitter (X) bot that runs forever, tweets on a customizable schedule, summarizes news using AI, manages its own history, and costs literally $0 to operate.
This article explains every boring technical detail of how it works, how it’s structured, and how the workflow stays stable without a server.
If you’re interested in automation, AI pipelines, APIs, GitHub Actions, or simply want to build your own bot, this is a full blueprint you can follow.
Demo
[embed]
Overview
This project does 5 core things:
1. Fetches real-time news articles
Using a News API + keywords of the user’s choice.
2. Summarizes these articles using AI
A lightweight LLM condenses the info into one tweet-sized message.
3. Tweets automatically on a schedule
User can choose its own defined cron schedule, for the tweets to be tweeted.
4. Prevents duplicate tweets
The bot keeps track of what it tweeted today and what it has tweeted historically so that there is no chances for duplicated tweets.
5. Runs entirely using GitHub Actions
No server. No VPS. No cloud hosting. No cron on your machine. No cent spent.
GitHub becomes the “server”, executing the bot on a schedule and committing updated data back to the repository.
Project Architecture & Structure
Here’s 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()
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 summarisation pipeline
├── tweeter.py # X/Twitter posting utilities
└── README.md
Each part has its job. Let’s dive into how every component works.
Credentials & Environment Setup
Before anything runs, the bot loads:
X_API_KEYX_API_KEY_SECRETACCESS_TOKENACCESS_TOKEN_SECRETNEWS_API_KEY
Which they need to be inputed into the GitHub repo environment.
News Fetching System
(File: fetcher.py)
This module hits a News API endpoint based on specified topics (e.g., AI, technology, business), these topics need to be inputed in the NICHE_KEYWORDS list located in the config.py file.
For example:
url = f"https://newsapi.org/v2/top-headlines?q=AI&apiKey={key}"
It extracts:
- article titles
- content
- url
AI Summarization Engine
(File: summarize.py)
Once the news articles are fetched, an AI model takes over.
What the summary prompt does:
- condenses article into 1 tweet-sized sentence
- keeps factual correctness
- avoids hashtags and emojis unless user wants them
- removes repeated words or irrelevant details
- includes the main takeaway of the article
Each summary looks like:
“Meta unveils a new AI model designed to assist developers in building multimodal applications more efficiently.”
These summaries are then filtered, cleaned, and stored into a top_summaries list for the user to choose in which ones to tweet.
Tweet Queue System
The bot uses two files to manage tweet flow:
1. daily_tweet.txt
Stores the tweet sent today. Prevents sending the same tweet again in the same run or same day.
2. tweets.txt
Permanent archive of everything that has ever been tweeted by the bot.
This ensures:
- Historical tracking
- Predictable behavior
- Debuggability
Twitter (X) API Integration
(File: tweeter.py)
This bot uses: Twitter API v2, specifically client.create_tweet()
Why v2?
Because free tier no longer allows v1.1 posting, but v2 posting works perfectly with a valid app.
Example request:
response = client.create_tweet(text=tweet)
If posting fails, the bot logs the error and stops — no corrupted data.
Core Pipeline Execution
(File: main.py)
The pipeline is simple but robust:
- Fetch news
- Generate summaries
- Scoring summaries
- Storing the top summaries
- Post tweets based on the history of tweeted tweets
- Update:
- daily_tweet.txt
- tweets.txt
This ensures the data stays consistent across runs.
Commit & Push Logic (Serverless Persistence)
Because GitHub Actions runs in a temporary environment, data needs to be committed back to the repo after each tweet.
Final workflow:
- 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 is what makes the bot stateful despite having no server.
Scheduling with GitHub Actions
(File: .github/workflows/tweet.yml)
Here is my core scheduler, so it triggers the GitHub workflow every hour to the whole process, and tweet:
on:
schedule:
- cron: "0 * * * *"
Meaning:
- run every hour
- and user can customize to any cron pattern
- no server required
- no hosting costs
GitHub Actions essentially becomes a free server that never sleeps.
Testing & Debugging Strategy
Local testing:
You can test by running:
python3.11 main.py
Remote testing:
Using:
workflow_dispatch:
Or you can just trigger the bot manually from GitHub.
Error Logging:
The bot prints clear error messages for:
- API failures
- missing env variables
- invalid credentials
- duplicated tweets attempts
Cost Breakdown
This entire system costs:
$0 per month
Because:
- Twitter API v2 posting is free
- GitHub Actions gives 2,000 minutes/mo for free
- News API has a free tier
- AI summarization uses a small and cheap model or free API
- No servers, no VPS, no cron jobs
What I Learned
Building this project taught me is designing an end-to-end AI pipeline.
I learnt how to use Twitter API v2, including OAuth credentials, App authentication, posting, and errors troubleshooting. Also automating full workflows with GitHub Actions (Cron jobs, environment variables, caching, committing from Actions). I also learned to write clean Python architecture (modularization) and credentials & secrets management, applying best practices with .env and GitHub Secrets.
Conclusion
This project started as a random idea… “What if I could automate the whole twitting process with a bot that writes for me and completely free (I’m still a student, so no income; idk if I should cry or laugh)?”
Turns out: Yes.
The system is:
- scalable
- customizable
- free
- fully automated
- permanently running
Anyone can use this architecture to build bots for:
- AI tweeting
- content generation
- news updates
- personal branding
- daily atomic notes
- community building
If you want to check the full code, here is the repo:
↳ **https://github.com/ThePhoenix77/ai-twitter-bot**
Feel free to fork it, improve it, or message me. I love meeting other builders.
I’ll be happy to connect, enjoy ;)
메타데이터
- post_id
- 1bce83d308f4
- slug
- building-a-free-serverless-ai-powered-twitter-bot-a-complete-technical-deep-dive-1bce83d308f4
- url
- https://medium.com/@tahaboussaden/building-a-free-serverless-ai-powered-twitter-bot-a-complete-technical-deep-dive-1bce83d308f4
- canonical_url
- https://medium.com/@tahaboussaden/building-a-free-serverless-ai-powered-twitter-bot-a-complete-technical-deep-dive-1bce83d308f4
- author_url
- https://medium.com/@tahaboussaden
- status
- ok
- fetched_at
- 2026-07-15 04:21:51