TikBotX is a powerful library for automating TikTok interactions using Playwright.
It simulates human behavior to perform actions like uploading videos, liking posts, commenting, viewing stories, replying to DMs, and more.
The library includes a built-in Express server that exposes API endpoints for seamless integration and task control.
- 🤖 Human Simulation: Randomized delays, scrolling, and mouse movements for realistic behavior.
- 🔑 Persistent Login: Saves and reuses sessions automatically.
- 📂 Queue Management: Add videos to monitor or upload queues.
- 🔄 Automated Bot Loop: Processes tasks at intervals with minimal supervision.
- 🌐 Express API: Expose endpoints for external apps or scripts.
- 🧠 AI Replies: Automatically reply to comments and DMs with AI-generated responses.
- Node.js >= 20
- npm or yarn
- TikTok account
- Playwright library
fsmodule for session storage
Clone the repository and install dependencies:
git clone https://github.com/stackmorgan/tikbotx.git
cd tikbotxnpm install npx playwright install
🛠 Usage
- Login & Session Handling Start the Express server and visit the login route: Copy code Http GET http://localhost:4000/login Opens TikTok in a non-headless browser for manual login. Waits until the For You feed loads. Automatically saves the session to ./storage/session.json. Starts the bot loop automatically after login. Copy code Js app.get("/login", async (req, res) => { const result = await launchBrowser(false); // no session browser = result.browser; context = result.context; page = result.page;
res.send("Login page opened. Complete login manually. Bot will start automatically after login.");
await page.waitForURL("**/foryou*", { timeout: 0 }); await saveSession(context); runBotLoop(); });
- Queue Management via API 📺 Monitor video Copy code Http POST /monitor Content-Type: application/json
{ "videoUrl": "https://www.tiktok.com/@user/video/1234567890" } ⬆️ Upload video Copy code Http POST /upload Content-Type: application/json
{ "videoPath": "./videos/video1.mp4", "caption": "My new video" }
📊 Check status Copy code Http GET /status Response: Copy code Json { "monitoring": ["https://www.tiktok.com/@user/video/1234567890"], "uploading": [ { "file": "./videos/video1.mp4", "caption": "My new video" } ], "running": true } 3. Bot Loop Integration Copy code Js async function runBotLoop() { if (isRunning) return; isRunning = true;
if (!page || !context) { if (!fs.existsSync(SESSION_FILE)) return console.log("Visit /login first"); const result = await startBrowser(); browser = result.browser; context = result.context; page = result.page; }
while (true) { if (uploadQueue.length || monitorQueue.length) { await runTasks(page, { videosToPost: uploadQueue, videosToMonitor: monitorQueue }); } await new Promise(r => setTimeout(r, 30000)); // every 30s } } 4. Graceful Shutdown Copy code Js async function shutdown() { if (context) await saveSession(context); if (browser) await browser.close(); process.exit(0); }
process.on("SIGINT", shutdown); process.on("SIGTERM", shutdown); Ensures session and queue data are saved before exit. ✅ 5. Running the Server Copy code Bash
node server.js Server URL: http://localhost:4000 Visit /login if no session exists. Add videos via /monitor and /upload. Bot starts automatically after login or session load. 6. Config File (config.json) Initialize bot tasks at startup: Copy code Json { "videosToPost": [ { "file": "./videos/video1.mp4", "caption": "My first video" } ], "videosToMonitor": [ "https://www.tiktok.com/@user/video/1234567890" ] } Load with loadConfig() in tiktokActions.js.
📝 Notes Always run login with headless=false for OTP and captcha. Human-like behavior includes scrolls, mouse movements, and random delays. Session persistence prevents repeated logins. Easily extendable with AI, scheduling, or analytics.