Automated AI Moderation for Facebook Comments with Knowledge Base Integration - n8n Workflow

Deploy this robust n8n workflow template to automatically moderate Facebook comments. Using Gemini AI, Notion KB, and custom n8n nodes, it ensures instant, context-aware, and professional responses.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Markdown-formatted text:
Social Media Managers needing 24/7 automated engagement.
E-commerce businesses that require fast, fact-checked product answers.
Developers looking for advanced AI Agent n8n templates combining external data (RAG) with social media APIs.
Anyone seeking to utilize the powerful scheduling features of an n8n trigger for routine checks.

Overview

Managing high volumes of social media comments, especially those requiring specific product information, is resource-intensive. This powerful n8n workflow solves this by creating a closed-loop, intelligent moderation system. It operates on a scheduled n8n trigger, constantly checking for new comments on a Facebook page. When a new comment is found, the n8n workflow consults a dedicated Notion Knowledge Base (KB). This KB data is fed directly into an AI Agent (powered by Google Gemini), ensuring that all replies are accurate, adhere to strict brand guidelines (tone, forbidden words, target language), and are posted immediately. This specific n8n workflow prevents duplicate replies by logging every processed comment ID back into a Notion database, making this one of the most efficient n8n templates for social media automation.

How it Works

The entire process is initiated by the Schedule Trigger, which acts as the primary n8n trigger, running the check every 10 seconds.


  1. Polling & Identification: The Posts Fetcher retrieves recent posts. The Last Post Fetcher isolates the most recent post and checks its comments.

  2. Deduplication Check: The CommentID Checker (Notion n8n node) checks a database of previously processed comments. This step ensures that the n8n workflow only proceeds if the comment is truly new.

  3. Knowledge Retrieval: Concurrently, the Knowledge Base (Notion n8n node) pulls all relevant product and service data.

  4. Data Preparation: The KB Arrange custom code n8n node sanitizes and structures the raw Notion data into a concatenated knowledgeContext string, making it ready for the AI model.

  5. Flow Control: The New Comment Conditioner (If n8n node) acts as a gate, allowing only new, unprocessed comments to continue down the automated path.

  6. AI Generation (RAG): The Latest Comment data is passed to the AI Agent n8n node. This node uses the structured prompt (defining persona and rules) and the knowledgeContext (Retrieval Augmented Generation, or RAG) to formulate a perfect, on-brand reply using the Gemini AI Chat Model.

  7. Action & Logging: The Reply Writer n8n node posts the generated response back to the Facebook thread. Finally, the CommentID to DB n8n node logs the comment ID in Notion, completing the n8n workflow cycle and preventing reprocessing.

Installation Guide

Markdown-formatted text:


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

  2. Credentials Setup:

Facebook Graph API: Configure credentials for the Posts Fetcher, Last Post Fetcher, and Reply Writer n8n nodes. Ensure the token has permissions to read posts and pages, and post replies.
Notion: Set up the Notion credential for access to both the Knowledge Base database and the Processed Comments log database.
AI Model: Configure the Google Gemini or equivalent AI service connection used by the AI Chat Model n8n node.

  1. Parameter Configuration:

Replace [FACEBOOKPAGEID], [KNOWLEDGEBASEDATABASEID], and [PROCESSEDCOMMENTSDATABASEID] placeholders in the appropriate n8n nodes with your actual IDs.
* Customize the lengthy prompt within the AI Agent n8n node to define your specific company name, tone, forbidden expressions, and target language.

  1. Activation: Once all credentials and IDs are updated, set the n8n workflow to 'Active' to start automatic monitoring.

Node Details

Markdown-formatted text:

Schedule Trigger: The starting n8n trigger. Configured to run every 10 seconds, ensuring near real-time comment detection.
Posts Fetcher (HTTP Request): Fetches the latest posts from the specified [FACEBOOKPAGEID] using the Facebook Graph API.
CommentID Checker (Notion n8n node): Checks the [PROCESSEDCOMMENTSDATABASE_ID] for the existence of the latest comment's ID, crucial for the deduplication logic of this n8n workflow.
Knowledge Base (Notion n8n node): Retrieves all entries from the specified product/service database. This forms the basis of the AI's factual knowledge.
KB Arrange (Code n8n node): A custom scripting block that takes the rich Notion properties (titles, descriptions, prices) and formats them into a simple, coherent string (knowledgeContext) that the AI Agent can easily consume.
New Comment Conditioner (If n8n node): The flow control gate. Checks if the comment ID property exists (indicating it's been processed). It is designed to only allow new comments to continue the n8n workflow execution path.
AI Agent (Langchain Agent n8n node): The core intelligence. It utilizes the complex prompt, the external knowledgeContext from the KB Arrange node, and the customer's comment to generate a compliant, context-aware response.
AI Chat Model (Google Gemini n8n node): Provides the language model capability for the AI Agent, configured with a low temperature (0.2) for predictable, factual responses.
Reply Writer (Facebook Graph API n8n node): Performs the final action, sending a POST request to the Facebook Graph API to publish the AI-generated reply message.
CommentID to DB (Notion n8n node): Logs the comment ID and 'Done' status back into the tracking database, preventing the n8n trigger from processing it again.

Related n8n Workflows

Free

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

🚀 Automation pro building AI-powered workflows with n8n. 💼 Special focus on real use cases 🔧 Love clean, flexible, and business-ready automations.

Featured*