{
  "nodes": [
    {
      "id": "b6b07e6a-5605-4991-bc5d-bd108ee503e5",
      "name": "Insta Update",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -100,
        900
      ],
      "parameters": {
        "path": "instagram",
        "options": {},
        "httpMethod": "POST"
      },
      "typeVersion": 2
    },
    {
      "id": "ac3030e7-adda-4432-9846-fc214bfdda4a",
      "name": "Send Message for Comment",
      "type": "n8n-nodes-base.httpRequest",
      "onError": "continueRegularOutput",
      "position": [
        860,
        900
      ],
      "parameters": {
        "url": "=https://graph.instagram.com/v23.0/{{ $('Check if update is of comment?').item.json.body.entry[0].id }}/messages",
        "method": "POST",
        "options": {
          "redirect": {
            "redirect": {}
          }
        },
        "jsonBody": "={\n  \"recipient\": {\n    \"id\": \"{{ $('Check if update is of comment?').item.json.body.entry[0].changes[0].value.from.id }}\"\n  },\n  \"message\": {\n    \"text\": \"{{ $json.Message }}\"\n  }\n} ",
        "sendBody": true,
        "specifyBody": "json",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth"
      },
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": false,
      "typeVersion": 4.2,
      "waitBetweenTries": 3000
    },
    {
      "id": "800da6b1-b7e4-4939-8d3c-5af3a55fffca",
      "name": "Comment List",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        640,
        900
      ],
      "parameters": {
        "options": {
          "returnFirstMatch": true
        },
        "filtersUI": {
          "values": [
            {
              "lookupValue": "={{ $json.body.entry[0].changes[0].value.text.split()[0].toLowerCase() }}",
              "lookupColumn": "Comment"
            }
          ]
        },
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA/edit#gid=0",
          "cachedResultName": "Sheet1"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA/edit?usp=drivesdk",
          "cachedResultName": "IG Comment Reply"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6,
      "waitBetweenTries": 3000
    },
    {
      "id": "c7877403-33f3-4e3c-a490-6a4e6844ecf9",
      "name": "Get Verification",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -100,
        600
      ],
      "parameters": {
        "path": "instagram",
        "options": {},
        "responseMode": "responseNode"
      },
      "typeVersion": 2
    },
    {
      "id": "5cddd607-4639-48eb-922a-a743736de52b",
      "name": "Respond to Verfication Message",
      "type": "n8n-nodes-base.respondToWebhook",
      "position": [
        120,
        600
      ],
      "parameters": {
        "options": {},
        "respondWith": "text",
        "responseBody": "={{ $json.query[\"hub.challenge\"] }}"
      },
      "typeVersion": 1.4
    },
    {
      "id": "c87053c2-8508-4199-9c87-49d19b3b9cb1",
      "name": "Add Interation in Sheet (CRM)",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1120,
        900
      ],
      "parameters": {
        "columns": {
          "value": {
            "Note": "={{ $json?.error.message }}",
            "Time": "={{ $('Check if update is of comment?').item.json.body.entry[0].time }}",
            "User Id": "={{ $('Check if update is of comment?').item.json.body.entry[0].changes[0].value.from.id }}",
            "Username": "={{ $('Check if update is of comment?').item.json.body.entry[0].changes[0].value.from.username }}"
          },
          "schema": [
            {
              "id": "Time",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Time",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "User Id",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "User Id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Username",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Username",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Note",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Note",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {
          "useAppend": true
        },
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 76673878,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA/edit#gid=76673878",
          "cachedResultName": "Interation List"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1tQwit0eRrR5N-EoLX4dyXurjEDtthsr97Vny9kaIRdA/edit?usp=drivesdk",
          "cachedResultName": "IG Comment Reply"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 4.6,
      "waitBetweenTries": 3000
    },
    {
      "id": "45da4261-9d50-43e7-b76a-7abc49bb05c6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        500
      ],
      "parameters": {
        "color": 3,
        "width": 520,
        "height": 280,
        "content": "## Section 1"
      },
      "typeVersion": 1
    },
    {
      "id": "466854cc-015e-45e1-9df9-719b1c85f756",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        820
      ],
      "parameters": {
        "color": 5,
        "width": 1480,
        "height": 300,
        "content": "## Section 2\n"
      },
      "typeVersion": 1
    },
    {
      "id": "96d3b6a2-7c39-4df1-8320-c9112c9ce91b",
      "name": "Check if update is of comment?",
      "type": "n8n-nodes-base.switch",
      "position": [
        120,
        900
      ],
      "parameters": {
        "rules": {
          "values": [
            {
              "outputKey": "Comment",
              "conditions": {
                "options": {
                  "version": 2,
                  "leftValue": "",
                  "caseSensitive": true,
                  "typeValidation": "strict"
                },
                "combinator": "and",
                "conditions": [
                  {
                    "id": "46743704-1feb-42f4-ad31-586c7867bb8f",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "leftValue": "={{ $json.body.entry[0].changes[0].field }}",
                    "rightValue": "comments"
                  }
                ]
              },
              "renameOutput": true
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 3.2
    },
    {
      "id": "5cf8ac8a-5158-488b-9e75-3e1fcda4a96f",
      "name": "Comment if of other user",
      "type": "n8n-nodes-base.if",
      "position": [
        380,
        900
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "7ab85299-8fa9-4538-ab1f-a513e1f1fcc3",
              "operator": {
                "type": "string",
                "operation": "notEquals"
              },
              "leftValue": "={{ $json.body.entry[0].id }}",
              "rightValue": "={{ $json.body.entry[0].changes[0].value.from.id }}"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "63188fa2-cdbe-4434-8950-0397651f3681",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1180,
        -160
      ],
      "parameters": {
        "color": 4,
        "width": 2600,
        "height": 2020,
        "content": "## \ud83c\udfaf Overview\nThis n8n workflow template automates the process of monitoring Instagram comments and sending predefined responses based on specific comment keywords. It integrates Instagram's Graph API with Google Sheets to manage comment responses and maintains an interaction log for customer relationship management (CRM) purposes.\n\n## \ud83d\udd27 Workflow Components\nThe workflow consists of **9 main nodes** organized into two primary sections:\n\n### \ud83d\udce1 Section 1: Webhook Verification\n- \u2705 **Get Verification** (Webhook node)\n- \ud83d\udd04 **Respond to Verification Message** (Respond to Webhook node)\n\n### \ud83e\udd16 Section 2: Auto Comment Response\n- \ud83d\udcec **Insta Update** (Webhook node)\n- \u2753 **Check if update is of comment?** (Switch node)\n- \ud83d\udc64 **Comment if of other user** (If node)\n- \ud83d\udcca **Comment List** (Google Sheets node)\n- \ud83d\udcac **Send Message for Comment** (HTTP Request node)\n- \ud83d\udcdd **Add Interaction in Sheet (CRM)** (Google Sheets node)\n\n## \ud83d\udee0\ufe0f Prerequisites and Setup Requirements\n\n### 1. \ud83d\udd35 Meta/Facebook Developer Setup\n\n#### \ud83d\udcf1 Create Facebook App\n> \ud83d\udccb **Action Items:**\n> - [ ] Navigate to [Facebook Developers](https://developers.facebook.com/)\n> - [ ] Click \"Create App\" and select \"Business\" type\n> - [ ] Configure the following products:\n>   - \u2705 Instagram Graph API\n>   - \u2705 Facebook Login for Business  \n>   - \u2705 Webhooks\n\n#### \ud83d\udd10 Required Permissions\n\nConfigure the following permissions in your Meta app:\n| `instagram_basic` | \ud83d\udcd6 Read Instagram account profile info and media\n| `instagram_manage_comments` | \ud83d\udcac Create, delete, and manage comments\n| `instagram_manage_messages` | \ud83d\udce4 Send and receive Instagram messages \n| `pages_show_list` | \ud83d\udcc4 Access connected Facebook pages\n\n#### \ud83c\udfab Access Token Generation\n> \u26a0\ufe0f **Important Setup:**+\n> - [ ] Use Facebook's Graph API Explorer\n> - [ ] Generate a User Access Token with required permissions\n> - [ ] \u26a1 **Important**: Tokens expire periodically and need refreshing\n\n### 2. \ud83c\udf10 Webhook Configuration\n\n#### \ud83d\udd17 Setup Webhook URL\n> \ud83d\udccc **Configuration Checklist:**\n> - [ ] In Meta App Dashboard, navigate to **Products \u2192 Webhooks**\n> - [ ] Subscribe to **Instagram** object\n> - [ ] Configure webhook URL: `your-n8n-domain/webhook/instagram`\n> - [ ] Set verification token (use \"test\" or create secure token)\n> - [ ] Select webhook fields:\n>   - \u2705 **comments** - For comment notifications\n>   - \u2705 **messages** - For DM notifications (if needed)\n\n#### \u2705 Webhook Verification Process\nThe workflow handles Meta's webhook verification automatically:\n- \ud83d\udce1 Meta sends GET request with `hub.challenge` parameter\n- \ud83d\udd04 Workflow responds with the challenge value to confirm subscription\n\n### 3. \ud83d\udcca Google Sheets Setup\n\nExample - https://docs.google.com/spreadsheets/d/1ONPKJZOpQTSxbasVcCB7oBjbZcCyAm9gZ-UNPoXM21A/edit?usp=sharing \n\n#### \ud83d\udccb Create Response Management Sheet\nSet up a Google Sheets document with the following structure:\n\n**\ud83d\udcdd Sheet 1 - Comment Responses:**\n| Column | Description | Example |\n|--------|-------------|---------|\n| \ud83d\udcac Comment | Trigger keywords | `\"auto\", \"info\", \"help\"` |\n| \ud83d\udcdd Message | Corresponding response message | `\"Thanks for your comment! We'll get back to you soon.\"` |\n\n**\ud83d\udcc8 Sheet 2 - Interaction Log:**\n| Column | Description | Purpose |\n|--------|-------------|---------|\n| \u23f0 Time | Timestamp of interaction | Track when interactions occur |\n| \ud83c\udd94 User Id | Instagram user ID | Identify unique users |\n| \ud83d\udc64 Username | Instagram username | Human-readable identification |\n| \ud83d\udcdd Note | Additional notes or error messages | Debugging and analytics |\n\n---\n\n## \ud83d\udd27 Built By - akash@codescale.tech\n\n\n"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Comment List": {
      "main": [
        [
          {
            "node": "Send Message for Comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insta Update": {
      "main": [
        [
          {
            "node": "Check if update is of comment?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Verification": {
      "main": [
        [
          {
            "node": "Respond to Verfication Message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Comment if of other user": {
      "main": [
        [
          {
            "node": "Comment List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Message for Comment": {
      "main": [
        [
          {
            "node": "Add Interation in Sheet (CRM)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if update is of comment?": {
      "main": [
        [
          {
            "node": "Comment if of other user",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}