Twitter AI Bot — Autonomous Growth Engine
The Twitter AI Bot is a Node.js automation engine that maintains a consistent, on-brand Twitter presence without manual effort. It uses Playwright with the stealth plugin to operate through a browser session (cookie-based auth), bypassing the need for Twitter API credentials entirely. A local Ollama LLM (llama3 by default, configurable) generates all content guided by a personality.json profile and a weighted rotation across five content pillars: backend systems, AI/LLMs, dev productivity, career/remote, and hot takes. Each tweet is also assigned one of five format types — short take, numbered insight, hot take, Gen-Z tone, or CTA — using a weighted random selection to keep the feed varied. A portfolio scraper fetches live content from buildwithkulshresth.com and triggers showcase tweets 20% of the time to surface real project work. Rate limiting enforced via JSON state files caps daily output and prevents aggressive posting patterns. A reply engine handles two engagement flows: home feed replies (contextual responses to people the account follows) and search-based replies (discovery via keyword tracking). Four cron schedules coordinate everything: tweets every hour 8am–10pm IST, home feed replies at 10am, search replies at 2pm and 7pm.
$ Architecture
- →Browser automation layer — Playwright + playwright-extra + puppeteer-extra-plugin-stealth. Persistent cookies.json session maintained via import-cookies.js. No official Twitter API credentials required; all interactions go through the browser DOM.
- →AI generation (ollama.js) — Ollama HTTP API at configurable endpoint (default localhost:11434). Weighted pillar selection (backend 25%, AI/LLMs 20%, dev productivity 20%, career 20%, hot takes 15%). Weighted format selection (short take 35%, numbered insight 25%, hot take 20%, Gen-Z 15%, CTA 5%). Prompt constructed from personality.json + pillar + format instruction. Startup health check aborts if Ollama is unreachable.
- →Posting pipeline (twitter.js) — Playwright navigates to Twitter compose, fills the tweet text, and clicks post. Random 1–4 minute pre-post delay jitter added after generation to avoid predictable timing patterns. 20–30% random skip rate per cron window for organic cadence.
- →Rate limiting (rateLimit.js) — daily tweet count stored in JSON state file. configurable maxPerDay cap enforced before every post attempt.
- →Topic tracker (topicTracker.js) — topic bank loaded from topics.json. Tracks which topics have been used in the current cycle; rotates to next cycle when all are exhausted. Cycle count and remaining count logged on each run.
- →Reply engine (replyBot.js) — runHomeFeedReplySession scans home feed for recent posts from followed accounts and generates contextual replies. runReplySession runs keyword-based search to discover and reply to relevant conversations outside the follow graph.
- →Portfolio scraper (portfolioScraper.js) — fetches live content from buildwithkulshresth.com, extracts project/blog items, feeds a random item into generateShowcaseTweet for a 20% chance on each posting cycle.