AI-Powered Instagram Comment Auto-Reply System using Redis - n8n Workflow

Boost engagement instantly with this advanced n8n workflow. It uses the n8n trigger for polling, OpenAI for contextual replies, and Redis for duplicate prevention. Deploy this n8n template today.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?


  • Social Media Managers and Content Creators needing 24/7 engagement.

  • Developers looking for advanced n8n templates demonstrating AI and state management.

  • Businesses seeking to automate customer service interactions on social platforms.

  • Users who require a reliable n8n workflow for high-volume comment processing.

Overview

Maintaining high engagement on social media platforms like Instagram can be time-consuming, especially when dealing with hundreds of comments daily. This powerful n8n workflow provides a comprehensive, automated solution. It seamlessly integrates the Instagram Graph API with OpenAI’s intelligence and Redis’s speed for state tracking. The automation ensures that every new, non-spam comment receives a timely, contextual, and human-like response, drastically improving response rates and audience satisfaction. By utilizing Redis for duplicate checking and activity logging, this n8n template prevents redundant API calls and offers clear analytics on automated engagement. This robust n8n workflow acts as a virtual assistant, ensuring your channel remains highly active and engaged without manual intervention.

How it Works

This powerful n8n workflow operates on a scheduled polling mechanism, starting with the n8n trigger set to run periodically (e.g., every 5 minutes):


  1. Polling & Post Retrieval: The Schedule Trigger initiates the n8n workflow. The subsequent Get Recent Posts n8n node fetches the 10 most recent posts from your Instagram account using the Graph API.

  2. Comment Extraction: The workflow splits the posts and uses the Get Comments n8n node to retrieve all associated comments for each post.

  3. Context Merging: The Add Post Context n8n node merges the relevant post caption data back into the comment stream. This context is essential for the AI to generate relevant replies.

  4. Duplicate Prevention (Redis Check): The Check If Replied n8n node queries Redis using the comment ID as the key (replied{commentid}). The If n8n node then filters out any comment that already has a logged reply.

  5. Spam and Quality Filtering: A custom Code n8n node runs a Spam Filter, checking for keywords, extremely short comments, and emoji-only content, ensuring the system only proceeds with genuine engagement. It sets a shouldReply flag.

  6. AI Generation: If the comment passes the filter, the Generate AI Reply n8n node (powered by OpenAI) uses the provided context (post, comment text, and username) to craft a friendly and engaging response.

  7. Posting the Reply: The Post Reply n8n node sends the AI-generated text back to Instagram via the Graph API.

  8. State Management & Logging: Two subsequent Redis n8n node actions are critical: Mark As Replied sets the comment ID in Redis with a 30-day TTL to prevent duplicate replies, and Log Reply pushes a comprehensive interaction record into an analytics list.

Installation Guide

To deploy this comprehensive n8n template, follow these setup steps:


  1. Import the n8n workflow: Copy the provided JSON and paste it into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Instagram Graph API Credentials: You must configure credentials for the Instagram Graph API. This requires a Meta Developer account and obtaining an access token that is linked to your Business Account and Instagram Profile.

  3. OpenAI Credentials: Add your OpenAI API key. The workflow uses the Generate AI Reply n8n node, which requires a valid connection to utilize models like GPT-4o-mini.

  4. Redis Setup: Configure the Redis connection credentials (BjwucG92kWn0N0wC) used by the n8n workflow. This is mandatory for state management and logging.

  5. Activation: Ensure the n8n workflow is active, and the Schedule Trigger is set to your preferred polling interval.

Node Details

Schedule Trigger (n8n trigger): This initial n8n node defines the execution schedule, typically set to run every 5 minutes, ensuring real-time monitoring of comments.
Get Recent Posts (HTTP Request n8n node): Connects to the Instagram Graph API (/me/media) to fetch the most recent posts, providing post IDs necessary for fetching comments.
Add Post Context (Merge n8n node): Crucial for AI accuracy, this n8n node combines the context of the original Instagram post (e.g., caption) with the specific comment data.
Check If Replied (Redis n8n node): Performs a get operation in Redis using a dynamically generated key (replied_{{ $json.id }}) to detect if the n8n workflow has previously processed this comment.
Spam Filter (Code n8n node): A custom n8n node containing JavaScript logic to filter out common spam keywords, very short comments, and purely emoji comments before engaging the expensive AI generation step.
Generate AI Reply (OpenAI n8n node): The core intelligence of this n8n workflow. It utilizes OpenAI's chat resource with contextual system instructions to generate a human-like, friendly, and relevant reply.
Post Reply (HTTP Request n8n node): Submits the AI-generated message back to the Instagram API (/{comment-id}/replies) to finalize the engagement.
Mark As Replied (Redis n8n node): Uses a set operation with a 30-day TTL to save the comment ID, preventing duplicate replies upon subsequent runs of the n8n trigger.

Related n8n Workflows

Free

Nodes: 9 Nodes
Updated: December 26 2025
View all
Created by

The AI Squad Initiative is a pioneering effort to build, automate and scale AI-powered workflows using n8n.io. Our mission is to help individuals and businesses integrate AI agents seamlessly into their daily operations from automating tasks and enhancing productivity to creating innovative, intelligent solutions. We design modular, reusable AI workflow templates that empower creators, developers and teams to supercharge their automation with minimal effort and maximum impact.

Featured*