This workflow corresponds to n8n.io template #14893 — we link there as the canonical source.
This workflow follows the Agent → Googledocstool recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "d136c605-b544-40a4-96ca-de25a63bb588",
"name": "Filter",
"type": "n8n-nodes-base.filter",
"position": [
-48,
16
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "04588ffc-3323-4794-8d75-7e2820ea39d1",
"operator": {
"type": "string",
"operation": "notEquals"
},
"leftValue": "={{ $json.body.entry[0].changes[0].value.from.username }}",
"rightValue": "YOUR PAGE ID"
},
{
"id": "154fc83b-cbef-477b-adce-02a233b5a9e1",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.body.entry[0].changes[0].field }}",
"rightValue": "comments"
},
{
"id": "1b2aef0f-02de-4883-9a63-dbc4a8edfdf7",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.body.entry[0].changes[0].value.media.media_product_type }}",
"rightValue": "AD"
}
]
}
},
"typeVersion": 2.3
},
{
"id": "f8d8f2d9-a530-4b25-8113-129c83823a76",
"name": "Trigger on Instagram Comment",
"type": "n8n-nodes-base.webhook",
"position": [
-256,
16
],
"parameters": {
"path": "ecc03c31-5ab4-4261-84fb-c774e06fd579",
"options": {},
"httpMethod": "POST"
},
"typeVersion": 2.1
},
{
"id": "663ae510-584c-4fd9-9572-e6354d994c49",
"name": "If",
"type": "n8n-nodes-base.if",
"position": [
368,
16
],
"parameters": {
"options": {},
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "6c011997-5288-42ca-bc30-f5b22310951a",
"operator": {
"type": "string",
"operation": "exists",
"singleValue": true
},
"leftValue": "={{ $json.text }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.3
},
{
"id": "d0dc6713-966d-4d24-b7db-badef5115099",
"name": "Clean Data",
"type": "n8n-nodes-base.set",
"position": [
816,
0
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "18dbc49c-012a-406c-9ca6-c0a50075c30c",
"name": "post_text",
"type": "string",
"value": "={{ $json.caption }}"
},
{
"id": "e776ff33-0112-44b0-b9ed-71f77c6bf81f",
"name": "post_permalink",
"type": "string",
"value": "={{ $json.permalink }}"
},
{
"id": "db8ce601-2ad9-4fa8-9459-c1006d3d528b",
"name": "comment_text",
"type": "string",
"value": "={{ $('Get Commnet Details').item.json.text }}"
},
{
"id": "5d390e42-c777-40a9-bf1a-b3802e6a9b82",
"name": "comment_id",
"type": "string",
"value": "={{ $('Get Commnet Details').item.json.id }}"
},
{
"id": "d5f4f6d4-3f36-4c36-bf16-ae16e2b74d2c",
"name": "commentator_nusername",
"type": "string",
"value": "={{ $('Get Commnet Details').item.json.from.username }}"
}
]
}
},
"typeVersion": 3.4
},
{
"id": "c2cee3df-af99-4ffa-b30e-7d97d4caba26",
"name": "Comment Classifier",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1024,
0
],
"parameters": {
"text": "=Post Text: {{ $json.post_text }}\nComment Text: {{ $json.comment_text }}\n\nClassify this comment now.",
"options": {
"systemMessage": "=# Role\nYou are a professional comment classifier for a business \nrunning service ads on Facebook and Instagram.\nYou have one job only \u2014 read a comment and classify it \ninto exactly one category.\n\n# Goal\nAnalyze the post text to understand what service or product \nis being advertised. Then analyze the comment to understand \nthe commenter's intention. Return a classification based on \nboth pieces of information together.\n\n# Classification Categories\n\nQUERY\nThe person is asking a question or requesting information.\nExamples:\n- Asking about price or packages\n- Asking how the service works\n- Asking about results or timeline\n- Asking for contact details\n- Asking if the service works for their niche or business\n\nPOSITIVE_REVIEW\nThe person is expressing satisfaction or giving a compliment.\nExamples:\n- Saying the service is good or recommended\n- Sharing a positive personal experience\n- Tagging someone to look at a good service\n- Saying masha Allah, bohat acha, great work\n\nNEGATIVE_REVIEW\nThe person is complaining or expressing dissatisfaction.\nExamples:\n- Calling the service fake or scam\n- Sharing a bad personal experience\n- Warning others not to use the service\n- Expressing anger or frustration about results\n\nSPAM\nThe comment is irrelevant or promotional.\nExamples:\n- Random emojis with no meaning\n- Someone promoting their own service or profile\n- Completely unrelated comment\n- Bot like repetitive text\n\n# Rules\n- Always read the post text first to understand context\n- Then read the comment to understand intention\n- Works for comments in Urdu, English, or mixed language\n- If comment is very short like \"nice\" or \"good\" \n classify as POSITIVE_REVIEW\n- If comment is very short like \"?\" classify as QUERY\n- If you cannot determine clearly choose the more \n serious category\n- Never classify based on comment alone without \n considering post context\n- Return ONLY the JSON below with no extra text \n no explanation no markdown\n\n# Output Format\n{\n \"classification\": \"QUERY\" or \"POSITIVE_REVIEW\" \n or \"NEGATIVE_REVIEW\" or \"SPAM\",\n \"confidence\": \"LOW\" or \"MEDIUM\" or \"HIGH\"\n}\n\n# Confidence Guide\nHIGH \u2014 comment intention is very clear and obvious\nMEDIUM \u2014 comment intention is mostly clear \n but has some ambiguity\nLOW \u2014 comment intention is unclear or could mean \n multiple things"
},
"promptType": "define",
"hasOutputParser": true
},
"typeVersion": 3.1
},
{
"id": "2d593bae-c454-4464-a70a-cd9be75fd09c",
"name": "Structured Output Parser",
"type": "@n8n/n8n-nodes-langchain.outputParserStructured",
"position": [
1152,
224
],
"parameters": {
"jsonSchemaExample": "{\n\t\"classification\": \"string\",\n \"confidence\": \"string\"\n}"
},
"typeVersion": 1.3
},
{
"id": "7bfc711e-ec2b-4736-8887-f534f22e83cd",
"name": "OpenRouter Chat Model",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
"position": [
1440,
224
],
"parameters": {
"model": "openai/gpt-4o",
"options": {}
},
"credentials": {
"openRouterApi": {
"name": "<your credential>"
}
},
"typeVersion": 1
},
{
"id": "0a66a8ff-f7d8-442f-87d1-0982d7611669",
"name": "Get Ad Data",
"type": "n8n-nodes-base.httpRequest",
"position": [
608,
0
],
"parameters": {
"url": "=https://graph.facebook.com/v25.0/{{ $('Filter').item.json.body.entry[0].changes[0].value.media.id }}",
"options": {},
"sendQuery": true,
"authentication": "genericCredentialType",
"genericAuthType": "httpQueryAuth",
"queryParameters": {
"parameters": [
{
"name": "fields",
"value": "alt_text,caption,id,media_type,permalink"
}
]
}
},
"credentials": {
"httpQueryAuth": {
"name": "<your credential>"
}
},
"typeVersion": 4.3
},
{
"id": "1b5654d8-eb29-44f1-a774-e6bdec4eb224",
"name": "Switch",
"type": "n8n-nodes-base.switch",
"position": [
1680,
-48
],
"parameters": {
"rules": {
"values": [
{
"outputKey": "POSITIVE_REVIEW",
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "449a4c2a-b65a-4216-9309-0549aa6e48ec",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.classification }}",
"rightValue": "POSITIVE_REVIEW"
}
]
},
"renameOutput": true
},
{
"outputKey": "NEGATIVE_REVIEW",
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "68de3120-4bf9-4889-8244-1f00db5aaf4b",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.classification }}",
"rightValue": "NEGATIVE_REVIEW"
}
]
},
"renameOutput": true
},
{
"outputKey": "QUERY",
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "b6052353-4759-47c0-9ff4-7ee5fabbbf45",
"operator": {
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.classification }}",
"rightValue": "QUERY"
}
]
},
"renameOutput": true
},
{
"outputKey": "SPAM",
"conditions": {
"options": {
"version": 3,
"leftValue": "",
"caseSensitive": true,
"typeValidation": "strict"
},
"combinator": "and",
"conditions": [
{
"id": "e1cd3422-a952-4896-9600-2247dc13f54d",
"operator": {
"name": "filter.operator.equals",
"type": "string",
"operation": "equals"
},
"leftValue": "={{ $json.output.classification }}",
"rightValue": "SPAM"
}
]
},
"renameOutput": true
}
]
},
"options": {}
},
"typeVersion": 3.4
},
{
"id": "bfc8174b-ee23-46e7-a97d-666b29736584",
"name": "Knowledge Base",
"type": "n8n-nodes-base.googleDocsTool",
"position": [
2288,
160
],
"parameters": {
"operation": "get",
"documentURL": "1iJH4TTrQgnzu8FTErlprGH-Hm4-wp7o9IFBIvPLkUeA"
},
"credentials": {
"googleDocsOAuth2Api": {
"name": "<your credential>"
}
},
"typeVersion": 2
},
{
"id": "1434aae7-9c91-42a6-a859-733ae6b978b4",
"name": "Comment Generator",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
2048,
-112
],
"parameters": {
"text": "=Post Text: {{ $('Clean Data').first().json.post_text }}\n\nComment Text: {{ $('Clean Data').first().json.comment_text}}\n\nComment Classification: {{ $json.output.classification }}\nConfidence: {{ $json.output.confidence }}\n\nWrite a public reply to this comment now.",
"options": {
"systemMessage": "=# Role\nYou are a professional and friendly social media reply \nagent for RankFlow Digital Agency. You write public \nreplies to comments on Facebook and Instagram posts \non behalf of the agency.\n\n# Goal\nWrite a short, warm, human sounding public reply to \nthe comment. The reply will be published directly \nas a comment \u2014 so output ONLY the reply text and \nnothing else.\n\n# Tool Usage\nYou have access to one tool: Knowledge Base\n\nUse the Knowledge Base tool ONLY when the comment \nis a QUERY and you need to find specific information \nlike prices, services, timelines or FAQs.\n\nDo NOT use the Knowledge Base tool when the comment \nis a POSITIVE_REVIEW. You already know how to reply \nto positive feedback.\n\n# How to Handle QUERY Comments\nStep 1 \u2014 Search the Knowledge Base for the answer\nStep 2 \u2014 If answer is found write a clear helpful reply\nStep 3 \u2014 End with a soft invitation to contact us\n\nIf the answer is NOT found in the Knowledge Base:\nDo not make up information.\nReply with this instead:\n\"Please DM us we will \nanswer all your questions personally.\"\nAdjust the language to match the comment language.\n\n# How to Handle POSITIVE_REVIEW Comments\nStep 1 \u2014 Do not use the Knowledge Base tool\nStep 2 \u2014 Thank the person warmly and genuinely\nStep 3 \u2014 Keep it to 2 sentences maximum\nStep 4 \u2014 Subtly encourage others to try the service\n\n# Reply Rules\n- Reply in the SAME language as the comment\n- Urdu comment \u2192 reply in Urdu\n- English comment \u2192 reply in English\n- Mixed comment \u2192 reply in mixed\n- Keep reply between 2 to 4 sentences\n- Sound human and warm \u2014 never robotic\n- Never start with Hello or Dear Customer\n- Use commenter first name if provided\n- Never mention you are an AI\n- Maximum 1 emoji per reply\n- Never use quotation marks in the reply\n- Never add any label or prefix like \"Reply:\" \n or \"Response:\" before the text\n\n# Critical Output Rule\nOutput ONLY the reply text that will be posted \nas a public comment. No explanation. No JSON. \nNo markdown. No extra words. Just the reply."
},
"promptType": "define"
},
"typeVersion": 3.1
},
{
"id": "2d5f9903-930e-4731-96e2-f8e93c5ba922",
"name": "Reply to Comment",
"type": "n8n-nodes-base.httpRequest",
"position": [
2368,
-112
],
"parameters": {
"url": "=https://graph.facebook.com/v25.0/{{ $('Clean Data').first().json.comment_id }}/replies",
"method": "POST",
"options": {},
"sendBody": true,
"contentType": "form-urlencoded",
"authentication": "genericCredentialType",
"bodyParameters": {
"parameters": [
{
"name": "message",
"value": "={{ $json.output }}"
}
]
},
"genericAuthType": "httpQueryAuth"
},
"credentials": {
"httpBasicAuth": {
"name": "<your credential>"
},
"httpQueryAuth": {
"name": "<your credential>"
}
},
"typeVersion": 4.3
},
{
"id": "ce07596d-065e-4271-aee4-68bc9170ac70",
"name": "Inform User",
"type": "n8n-nodes-base.slack",
"position": [
2048,
240
],
"parameters": {
"text": "=\ud83d\udea8 NEGATIVE REVIEW ALERT\n\n\ud83d\udc64 Commenter: {{ $('Clean Data').first().json.commentator_nusername}}\n\ud83d\udcac Comment: {{ $('Clean Data').first().json.comment_text }}\n\n\u2757 Please review and reply manually on Facebook.",
"user": {
"__rl": true,
"mode": "list",
"value": "U09C6U7038V",
"cachedResultName": "salmanmehboob1947"
},
"select": "user",
"otherOptions": {}
},
"credentials": {
"slackApi": {
"name": "<your credential>"
}
},
"typeVersion": 2.4
},
{
"id": "66c127f6-f0cd-421d-8221-78dcbeccd4dd",
"name": "Get Commnet Details",
"type": "n8n-nodes-base.httpRequest",
"position": [
176,
16
],
"parameters": {
"url": "=https://graph.facebook.com/v25.0/{{ $json.body.entry[0].changes[0].value.id }}",
"options": {},
"sendQuery": true,
"authentication": "genericCredentialType",
"genericAuthType": "httpQueryAuth",
"queryParameters": {
"parameters": [
{
"name": "fields",
"value": "from,text,id"
}
]
}
},
"credentials": {
"httpQueryAuth": {
"name": "<your credential>"
}
},
"typeVersion": 4.3
},
{
"id": "5e9b5acf-5520-4b12-9209-36558033a829",
"name": "Sticky Note",
"type": "n8n-nodes-base.stickyNote",
"position": [
-816,
-368
],
"parameters": {
"width": 480,
"height": 800,
"content": "## AI Instagram Comment Automation for Ads | Auto Reply & Lead Capture\n\n### How it works\n\n1. Triggers on an Instagram comment using a webhook.\n2. Filters and retrieves additional comment details.\n3. Evaluates conditions and fetches ad data if necessary.\n4. Processes the data using an AI model for sentiment classification.\n5. Based on classification, either replies to the comment or informs a user via Slack.\n\n### Setup steps\n\n- [ ] Set up Instagram webhook integration.\n- [ ] Configure API access for Facebook Graph API.\n- [ ] Prepare AI model for comment classification and generation.\n- [ ] Ensure Slack credentials are set up for notifications.\n\n### Customization\n\nYou can modify the AI model used for classification and the types of responses generated based on different comment types."
},
"typeVersion": 1
},
{
"id": "6de43bca-7f6c-4d5c-9a6d-5c4338a86ba3",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
-304,
-112
],
"parameters": {
"color": 7,
"width": 400,
"height": 304,
"content": "## Trigger and initial filter\n\nInitiates workflow on new Instagram comment and applies basic filtering."
},
"typeVersion": 1
},
{
"id": "e89a2362-cab3-46a3-9976-cdd5d036c924",
"name": "Sticky Note2",
"type": "n8n-nodes-base.stickyNote",
"position": [
144,
-224
],
"parameters": {
"color": 7,
"width": 150,
"height": 384,
"content": "## Fetch comment details\n\nRetrieves detailed information about the Instagram comment."
},
"typeVersion": 1
},
{
"id": "84bca318-4a80-4456-ad2a-b45b903167ec",
"name": "Sticky Note3",
"type": "n8n-nodes-base.stickyNote",
"position": [
320,
-160
],
"parameters": {
"color": 7,
"width": 432,
"height": 320,
"content": "## Evaluate conditions\n\nChecks conditions and decides to fetch ad data for further processing."
},
"typeVersion": 1
},
{
"id": "3dbcd037-8ff8-4a53-9590-63f17cc0c444",
"name": "Sticky Note4",
"type": "n8n-nodes-base.stickyNote",
"position": [
768,
-224
],
"parameters": {
"color": 7,
"width": 816,
"height": 576,
"content": "## Data cleaning and classification\n\nCleans data and classifies comment using AI to determine sentiment or intent."
},
"typeVersion": 1
},
{
"id": "d35f44a2-54bb-4b96-b432-37001bcf7a2e",
"name": "Sticky Note5",
"type": "n8n-nodes-base.stickyNote",
"position": [
1632,
-320
],
"parameters": {
"color": 7,
"width": 896,
"height": 800,
"content": "## Conditional response branching\n\nBranches based on classification result: generates automated responses or sends alerts."
},
"typeVersion": 1
}
],
"connections": {
"If": {
"main": [
[
{
"node": "Get Ad Data",
"type": "main",
"index": 0
}
]
]
},
"Filter": {
"main": [
[
{
"node": "Get Commnet Details",
"type": "main",
"index": 0
}
]
]
},
"Switch": {
"main": [
[
{
"node": "Comment Generator",
"type": "main",
"index": 0
}
],
[
{
"node": "Inform User",
"type": "main",
"index": 0
}
],
[
{
"node": "Comment Generator",
"type": "main",
"index": 0
}
],
[]
]
},
"Clean Data": {
"main": [
[
{
"node": "Comment Classifier",
"type": "main",
"index": 0
}
]
]
},
"Get Ad Data": {
"main": [
[
{
"node": "Clean Data",
"type": "main",
"index": 0
}
]
]
},
"Knowledge Base": {
"ai_tool": [
[
{
"node": "Comment Generator",
"type": "ai_tool",
"index": 0
}
]
]
},
"Comment Generator": {
"main": [
[
{
"node": "Reply to Comment",
"type": "main",
"index": 0
}
]
]
},
"Comment Classifier": {
"main": [
[
{
"node": "Switch",
"type": "main",
"index": 0
}
]
]
},
"Get Commnet Details": {
"main": [
[
{
"node": "If",
"type": "main",
"index": 0
}
]
]
},
"OpenRouter Chat Model": {
"ai_languageModel": [
[
{
"node": "Comment Classifier",
"type": "ai_languageModel",
"index": 0
},
{
"node": "Comment Generator",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Structured Output Parser": {
"ai_outputParser": [
[
{
"node": "Comment Classifier",
"type": "ai_outputParser",
"index": 0
}
]
]
},
"Trigger on Instagram Comment": {
"main": [
[
{
"node": "Filter",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
googleDocsOAuth2ApihttpBasicAuthhttpQueryAuthopenRouterApislackApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Never miss a lead from your Instagram ads again. This workflow automatically monitors every comment on your Instagram ad posts in real time, classifies the comment using AI, and takes the right action instantly — whether that is replying with accurate information from your…
Source: https://n8n.io/workflows/14893/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
Every comment on your Facebook ad is a sales opportunity. But manually replying to dozens of comments every day - in the right tone, in the right language, at the right speed - is simply not scalable.
This template is perfect for: Market Researchers tracking industry trends. Tech Teams wanting to stay updated on specific technologies (e.g., "AI", "Cybersecurity"). Content Creators looking for curat
Who is this for? Agencies, consultants, and service providers who conduct discovery calls and need to quickly turn conversations into professional proposals.
leads. Uses supabase, gmail, formTrigger, httpRequest. Webhook trigger; 62 nodes.
Fully automates your service order pipeline from incoming booking to supplier confirmation — with built-in SLA enforcement and automatic escalation if a supplier goes silent. 📥 Receives orders via web