đź’¬ N8N automated Twitter reply bot workflow

⚡ 1,425 views · 💬 Lead Nurturing & AI Sales Agents

💡 Pro Tip — Twitter’s API is paid now, which makes simple data pulls expensive. ScraperNode is a community node that scrapes Twitter profiles and posts without needing API access.

View All Scrapers

Description

N8N Automated Twitter Reply Bot Workflow

For latest version, check: dziura.online/automation

Latest documentation can be find here

You must have Apify community node installed before pasting the JSON to your workflow. 

Overview

This n8n workflow creates an intelligent Twitter/X reply bot that automatically scrapes tweets based on keywords or communities, analyzes them using AI, generates contextually appropriate replies, and posts them while avoiding duplicates. The bot operates on a schedule with intelligent timing and retry mechanisms.

Key Features

Required Credentials & Setup

1. Telegram Bot

2. MongoDB Database

3. Apify Account

4. OpenRouter (LLM Provider)

5. Twitter/X API

Workflow Components

Trigger Nodes

1. Schedule Trigger

2. Manual Trigger

3. Telegram Trigger

Data Processing Flow

1. MongoDB Query (Find documents)

2. Data Aggregation (Aggregate1)

3. Keyword/Community Selection (Keyword/Community List)

Format:{

  “keyword_community_list”: [

    “SaaS”,

    “Entrepreneur”, 

    “1488663855127535616”  // Community ID (19-digit number)

  ],

  “failure”: 0

}

4. Random Selection (Randomized community, keyword)

5. Routing Logic (If4)

Tweet Scraping (Apify Actors)

Community Search Actor

Configuration:{

  “communityIds”: [“COMMUNITY_ID”],

  “numberOfTweets”: 40

}

Search Actor

Configuration:{

  “contentLanguage”: “en”,

  “engagementMinLikes”: 10,

  “engagementMinReplies”: 5,

  “numberOfTweets”: 20,

  “query”: “KEYWORD”,

  “timeWithinTime”: “2d”,

  “tweetTypes”: [“original”],

  “usersBlueVerifiedOnly”: true

}

Filtering System (Community filter)

The workflow applies multiple filters to ensure high-quality replies:

AI-Powered Reply Generation

LLM Chain (Basic LLM Chain)

Output Parser (Structured Output Parser)

Schema:{

  “selected_tweet_id”: “tweet_id_here”,

  “screen_name”: “author_screen_name”, 

  “reply”: “generated_reply_here”

}

Posting & Notification System

Twitter Posting (Create Tweet)

Status Notifications

Database Storage (Insert documents)

Retry Mechanism

The workflow includes intelligent retry logic:

Failure Counter (If5, Increment Failure Counter1)

Final Failure Notification

Configuration Guide

Essential Settings to Modify

  1. MongoDB Collection Name: Update collection_name in MongoDB nodes

  2. Telegram Chat ID: Replace 11111111111 with your actual chat ID

  3. Keywords/Communities: Edit the list in Keyword/Community List node

  4. Timezone: Update timezone in Code node (currently set to Europe/Kyiv)

  5. Actor Selection: Enable only one actor (Community OR Search) based on your needs

Filter Customization

Adjust filters in Community filter node based on your requirements:

LLM Customization

Modify the AI prompt in Basic LLM Chain to:

Usage Tips

  1. Start small: Begin with a few high-quality keywords/communities

  2. Monitor performance: Use Telegram notifications to track success rates

  3. Adjust filters: Fine-tune based on the quality of generated replies

  4. Respect limits: Twitter’s free tier allows ~17 posts/day

  5. Test manually: Use /reply command for testing before scheduling

Troubleshooting

Common Issues

  1. No tweets found: Adjust filter criteria or check keywords

  2. API rate limits: Reduce posting frequency or upgrade Twitter API plan

  3. MongoDB connection: Verify connection string and collection name

  4. Apify quota: Monitor Apify usage limits

  5. LLM failures: Check OpenRouter credits and model availability

Best Practices

This workflow provides a comprehensive solution for automated, intelligent Twitter engagement while maintaining quality and avoiding spam-like behavior.

đź”— Nodes Used

Telegram, Telegram Trigger, MongoDB, Execute Sub-workflow, X (Formerly Twitter), Execute Workflow Trigger

📥 Import

Download workflow.json and import into n8n: Workflow menu → Import from File

📖 Importing guide · 🔑 Credential setup