Skip to main content

N8N automated Twitter reply bot workflow

Workflow preview

Workflow preview
100%
N8N automated Twitter reply bot workflow preview
Open on n8n.io

Important notice

This workflow is provided as-is. Please review and test before using in production.

1. Workflow Overview

N8N Automated Twitter Reply Bot Workflow ============================================ For latest version, check : dziura.online/automation Latest [documentation ...

Best for

  • Lead Nurturing automation workflows
  • AI Chatbot automation workflows
  • advanced n8n builders looking for reusable templates

Tools used

n8n-nodes-base.manualtrigger, n8n-nodes-base.if, n8n-nodes-base.mongodb, n8n-nodes-base.aggregate, n8n-nodes-base.scheduletrigger, n8n-nodes-base.code, n8n-nodes-base.noop, n8n-nodes-base.wait

Source and attribution

This workflow is cataloged by N8N Workflows and links back to its original n8n.io source page by Max.

Original n8n.io source

1.1 Workflow description

Title
N8N automated Twitter reply bot workflow
Workflow name
N8N automated Twitter reply bot workflow

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

  • Automated tweet scraping from Twitter/X using Apify actors

  • AI-powered reply generation using LLM (Large Language Model)

  • Duplicate prevention via MongoDB storage

  • Smart scheduling with timezone awareness and natural posting patterns

  • Retry mechanism with failure tracking

  • Telegram notifications for status updates

  • Manual trigger option via Telegram command

Required Credentials & Setup

1. Telegram Bot

  • Create a bot via @BotFather on Telegram

  • Get your Telegram chat ID to receive status messages

  • Credential needed: Telegram account (Bot token)

2. MongoDB Database

  • Set up a MongoDB database to store replied tweets and prevent duplicates

  • Create a collection (default name: collection_name)

  • Credential needed: MongoDB account (Connection string)

  • Tutorial: MongoDB Connection Guide

3. Apify Account

4. OpenRouter (LLM Provider)

  • Sign up at OpenRouter.ai

  • Used for AI-powered tweet analysis and reply generation

  • Model used: x-ai/grok-3 (configurable)

  • Credential needed: OpenRouter account (API key)

5. Twitter/X API

  • Set up developer account at developer.x.com

  • Note: Free tier limited to ~17 posts per day

  • Credential needed: X account (OAuth2 credentials)

Workflow Components

Trigger Nodes

1. Schedule Trigger
  • Purpose: Runs automatically every 20 minutes

  • Smart timing: Only active between 7 AM - 11:59 PM (configurable timezone)

  • Randomization: Built-in probability control (~28% execution chance) to mimic natural posting patterns

2. Manual Trigger
  • Purpose: Manual execution for testing
3. Telegram Trigger
  • Purpose: Manual execution via /reply command in Telegram

  • Usage: Send /reply to your bot to trigger the workflow manually

Data Processing Flow

1. MongoDB Query (Find documents)
  • Purpose: Retrieves previously replied tweet IDs to avoid duplicates

  • Collection: collection_name (configure to match your setup)

  • Projection: Only fetches tweet_id field for efficiency

2. Data Aggregation (Aggregate1)
  • Purpose: Consolidates tweet IDs into a single array for filtering
3. Keyword/Community Selection (Keyword/Community List)
  • Purpose: Defines search terms and communities

  • Configuration: Edit the JSON to include your keywords and Twitter community IDs

Format:{

  "keyword_community_list": [

    "SaaS",

    "Entrepreneur", 

    "1488663855127535616"  // Community ID (19-digit number)

  ],

  "failure": 0

}

4. Random Selection (Randomized community, keyword)
  • Purpose: Randomly selects one item from the list to ensure variety
5. Routing Logic (If4)
  • Purpose: Determines whether to use Community search or Keyword search

  • Logic: Uses regex to detect 19-digit community IDs vs keywords

Tweet Scraping (Apify Actors)

Community Search Actor
  • Actor: api-ninja/x-twitter-community-search-post-scraper

  • Purpose: Scrapes tweets from specific Twitter communities

Configuration:{

  "communityIds": ["COMMUNITY_ID"],

  "numberOfTweets": 40

}

Search Actor
  • Actor: api-ninja/x-twitter-advanced-search

  • Purpose: Scrapes tweets based on keywords

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:

  • Text length: >60 characters (substantial content)

  • Follower count: >100 followers (audience reach)

  • Engagement: >10 likes, >3 replies (proven engagement)

  • Language: English only

  • Views: >100 views (visibility)

  • Duplicate check: Not previously replied to

  • Recency: Within 2 days (configurable in actor settings)

AI-Powered Reply Generation

LLM Chain (Basic LLM Chain)
  • Purpose: Analyzes filtered tweets and generates contextually appropriate replies

  • Model: Grok-3 via OpenRouter (configurable)

  • Features:

    • Engagement potential scoring

    • User authority analysis

    • Timing optimization

    • Multiple reply styles (witty, informative, supportive, etc.)

    • <100 character limit for optimal engagement

Output Parser (Structured Output Parser)
  • Purpose: Ensures consistent JSON output format

Schema:{

  "selected_tweet_id": "tweet_id_here",

  "screen_name": "author_screen_name", 

  "reply": "generated_reply_here"

}

Posting & Notification System

Twitter Posting (Create Tweet)
  • Purpose: Posts the generated reply as a Twitter response

  • Error handling: Catches API limitations and rate limits

Status Notifications
  • Success: Notifies via Telegram with tweet link and reply text

  • Failure: Notifies about API limitations or errors

  • Format: HTML-formatted messages with clickable links

Database Storage (Insert documents)
  • Purpose: Saves successful replies to prevent future duplicates

  • Fields stored: tweet_id, screen_name, reply, tweet_url, timestamp

Retry Mechanism

The workflow includes intelligent retry logic:

Failure Counter (If5, Increment Failure Counter1)
  • Logic: If no suitable tweets found, increment failure counter

  • Retry limit: Maximum 3 retries with different random keywords

  • Wait time: 3-second delay between retries

Final Failure Notification
  • Trigger: After 4 failed attempts

  • Action: Sends Telegram notification about unsuccessful search

  • Recovery: Manual retry available via /reply command

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:

  • Minimum engagement thresholds

  • Text length requirements

  • Time windows

  • Language preferences

LLM Customization

Modify the AI prompt in Basic LLM Chain to:

  • Change reply style and tone

  • Adjust engagement criteria

  • Modify scoring algorithms

  • Set different character limits

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

  • Monitor your bot's replies for quality and appropriateness

  • Regularly update keywords to stay relevant

  • Keep an eye on engagement metrics

  • Adjust timing based on your audience's activity patterns

  • Maintain a balanced posting frequency to avoid appearing spammy

Documentation Links

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

1.2 Logical Blocks

This catalog entry is organized from the workflow JSON. The node-level section below shows the executable blocks available for review before importing the template.

2. Block-by-Block Analysis

Block 1 - When clicking ‘Execute workflow’

Type / Role
n8n-nodes-base.manualTrigger - manualTrigger
Config choices
Version 1

Block 2 - If

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 3 - Find documents

Type / Role
n8n-nodes-base.mongoDb - mongoDb
Config choices
Version 1.2

Block 4 - Aggregate1

Type / Role
n8n-nodes-base.aggregate - aggregate
Config choices
Version 1

Block 5 - Schedule Trigger

Type / Role
n8n-nodes-base.scheduleTrigger - scheduleTrigger
Config choices
Version 1.2

Block 6 - Code

Type / Role
n8n-nodes-base.code - code
Config choices
Version 2

Block 7 - If1

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 8 - No Operation, do nothing

Type / Role
n8n-nodes-base.noOp - noOp
Config choices
Version 1

Block 9 - Wait

Type / Role
n8n-nodes-base.wait - wait
Config choices
Version 1.1

Block 10 - If5

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 11 - When Executed by Another Workflow

Type / Role
n8n-nodes-base.executeWorkflowTrigger - executeWorkflowTrigger
Config choices
Version 1.1

Block 12 - If2

Type / Role
n8n-nodes-base.if - if
Config choices
Version 2.2

Block 13 - Execute Workflow

Type / Role
n8n-nodes-base.executeWorkflow - executeWorkflow
Config choices
Version 1.2

Block 14 - Get dataset items

Type / Role
@apify/n8n-nodes-apify.apify - apify
Config choices
Version 1

Block 15 - Sticky Note

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 16 - Sticky Note1

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 17 - Sticky Note2

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 18 - Sticky Note3

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 19 - Sticky Note4

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 20 - Sticky Note5

Type / Role
n8n-nodes-base.stickyNote - stickyNote
Config choices
Version 1

Block 21 - Basic LLM Chain

Type / Role
@n8n/n8n-nodes-langchain.chainLlm - chainLlm
Config choices
Version 1.7

Block 22 - OpenRouter Chat Model1

Type / Role
@n8n/n8n-nodes-langchain.lmChatOpenRouter - lmChatOpenRouter
Config choices
Version 1

Block 23 - Structured Output Parser

Type / Role
@n8n/n8n-nodes-langchain.outputParserStructured - outputParserStructured
Config choices
Version 1.3

Block 24 - Create Tweet

Type / Role
n8n-nodes-base.twitter - twitter
Config choices
Version 2

Showing the first 24 of 55 workflow blocks. Download the JSON for the full node graph.

3. Summary Table

Workflow N8N automated Twitter reply bot workflow
Complexity advanced
Nodes 55
Categories Lead Nurturing, AI Chatbot
Author Max
Published 09 Sept 2025

4. Reproducing the Workflow from Scratch

  1. 1. Download the workflow JSON

    Use the JSON export at /data/workflows/8410/8410.json as the source template for this automation.

  2. 2. Import the template into n8n

    Open n8n, import the downloaded JSON, and review each node before activating the workflow.

  3. 3. Configure credentials and variables

    Replace placeholder credentials, API keys, webhook URLs, account IDs, and environment-specific values with your own settings.

  4. 4. Test with sample data

    Run the workflow manually or in a staging workspace, inspect node output, and confirm downstream systems receive the expected data.

  5. 5. Activate and monitor

    Enable the workflow only after testing, then monitor executions, errors, and rate limits during the first production runs.

5. General Notes & Resources

Review imported nodes carefully before activation. This catalog entry is intended to help you inspect the workflow structure, understand required services, and find related templates faster.

Node names, credentials, schedules, webhook paths, and external service limits may need adjustment for your workspace.

Frequently asked questions

What does N8N automated Twitter reply bot workflow do?

N8N Automated Twitter Reply Bot Workflow ============================================ For latest version, check : dziura.online/automation Latest [documentation ...

What do I need before importing this workflow?

Review the workflow JSON, configure any required credentials in n8n, and test the automation in a safe workspace before using it in production.

Can I customize this workflow?

Yes. Use the block-by-block analysis and the downloadable JSON to inspect each node, then adjust credentials, prompts, schedules, filters, or destinations for your Lead Nurturing, AI Chatbot use case.