{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "195a03c5-5c16-4c64-9ef0-636bb7b8c407",
      "name": "Run an Actor",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        -144,
        -16
      ],
      "parameters": {
        "memory": 16384,
        "actorId": {
          "__rl": true,
          "mode": "id",
          "value": "AtBpiepuIUNs2k2ku"
        },
        "timeout": {},
        "customBody": "={\n    \"count\": {{ $json.post }},\n    \"maxDelay\": 10,\n    \"minDelay\": 1,\n    \"proxy\": {\n        \"useApifyProxy\": true\n    },\n    \"scrapeGroupPosts.groupUrl\": \"{{ $json.url }}\",\n    \"sortType\": \"new_posts\"\n}",
        "actorSource": "store"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8a566033-d318-404d-874b-97b57c8475be",
      "name": "Get dataset items",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        32,
        -16
      ],
      "parameters": {
        "offset": {},
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1,
      "alwaysOutputData": false
    },
    {
      "id": "00562fcd-15e5-469c-9e21-bc4b1fa32576",
      "name": "Get dataset items1",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        -224,
        544
      ],
      "parameters": {
        "offset": "=",
        "resource": "Datasets",
        "datasetId": "={{ $json.defaultDatasetId }}"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bedf32a9-4bbe-47ea-bbaa-b64b362a1516",
      "name": "Add A Post",
      "type": "n8n-nodes-base.supabase",
      "position": [
        240,
        -16
      ],
      "parameters": {
        "tableId": "posts",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "createdat",
              "fieldValue": "={{ new Date($json.createdAt * 1000).getDate() }}, \n{{ new Date($json.createdAt * 1000).toLocaleString('default', { month: 'long' }) }}, \n{{ new Date($json.createdAt * 1000).getFullYear() }}"
            },
            {
              "fieldId": "url",
              "fieldValue": "={{ $json.url || null }}"
            },
            {
              "fieldId": "user_name",
              "fieldValue": "={{ $json.user.name || null }}"
            },
            {
              "fieldId": "text",
              "fieldValue": "={{ $json.text || null }}"
            },
            {
              "fieldId": "reactioncount",
              "fieldValue": "={{ $json.reactionCount || null }}"
            },
            {
              "fieldId": "sharecount",
              "fieldValue": "={{ $json.shareCount || null }}"
            },
            {
              "fieldId": "commentcount",
              "fieldValue": "={{ $json.commentCount || null }}"
            },
            {
              "fieldId": "attachments",
              "fieldValue": "={{ $json.attachments.map(a => a.url) || null }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "ba23b7a1-8897-4578-b8de-058ff17dd8fd",
      "name": "Edit Fields",
      "type": "n8n-nodes-base.set",
      "position": [
        912,
        192
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "f7f291fd-7341-422b-8b92-68c35fda4342",
              "name": "comments",
              "type": "array",
              "value": "={{ $('Get dataset items1').item.json.comments }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "4f190127-8305-4320-be5c-eb16dcf8aa73",
      "name": "Create a row",
      "type": "n8n-nodes-base.supabase",
      "position": [
        1312,
        192
      ],
      "parameters": {
        "tableId": "replies",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "parent_comment",
              "fieldValue": "={{ $('Get dataset items1').item.json.commentUrl || null }}"
            },
            {
              "fieldId": "parent_text",
              "fieldValue": "={{ $('Get dataset items1').item.json.text || null }}"
            },
            {
              "fieldId": "commenturl",
              "fieldValue": "={{ $json.commentUrl || null }}"
            },
            {
              "fieldId": "text",
              "fieldValue": "={{ $json.text || null }}"
            },
            {
              "fieldId": "profileurl",
              "fieldValue": "={{ $json.profileUrl || null }}"
            },
            {
              "fieldId": "profilename",
              "fieldValue": "={{ $json.profileName || null }}"
            },
            {
              "fieldId": "post_text",
              "fieldValue": "={{ $('Add A Comment').item.json.post_title }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "8d25c50b-b1ee-4936-a892-a607c90178c7",
      "name": "Add A Comment",
      "type": "n8n-nodes-base.supabase",
      "position": [
        -32,
        528
      ],
      "parameters": {
        "tableId": "comments",
        "fieldsUi": {
          "fieldValues": [
            {
              "fieldId": "group_title",
              "fieldValue": "={{$('Edit Fields1').first().json.url.split(\"/\").filter(Boolean).pop() || null }}"
            },
            {
              "fieldId": "post_title",
              "fieldValue": "={{ $json.postTitle || null }}"
            },
            {
              "fieldId": "facebookurl",
              "fieldValue": "={{ $json.inputUrl || null }}"
            },
            {
              "fieldId": "commenturl",
              "fieldValue": "={{ $json.commentUrl || null }}"
            },
            {
              "fieldId": "post_text",
              "fieldValue": "={{ $('Add A Post').first().json.text }}"
            },
            {
              "fieldId": "text",
              "fieldValue": "={{ $json.text || null }}"
            },
            {
              "fieldId": "profilename",
              "fieldValue": "={{ $json.profileName || null }}"
            },
            {
              "fieldId": "likescount",
              "fieldValue": "={{ $json.likesCount || null }}"
            },
            {
              "fieldId": "commentscount",
              "fieldValue": "={{ $json.commentsCount || null }}"
            },
            {
              "fieldId": "Attachments",
              "fieldValue": "={{ $json.attachments\n  ? $json.attachments\n      .map(att => {\n        const imageField = Object.values(att).find(v => v?.uri);\n        return imageField?.uri || null;\n      })\n      .filter(Boolean)\n  : null }}"
            }
          ]
        }
      },
      "credentials": {
        "supabaseApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "0ae1e6c9-ebcf-403a-a371-89e62b4bec6a",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "position": [
        704,
        208
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "f24586a4-f73d-4f25-a230-3f43bac011d7",
              "operator": {
                "type": "number",
                "operation": "gt"
              },
              "leftValue": "={{ $('Get dataset items1').item.json.commentsCount || null }}",
              "rightValue": 0
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "9e7f0a82-d0fe-4a34-ac10-676978667eb7",
      "name": "ScrapeComments",
      "type": "@apify/n8n-nodes-apify.apify",
      "position": [
        -400,
        544
      ],
      "parameters": {
        "memory": 8192,
        "actorId": {
          "__rl": true,
          "mode": "id",
          "value": "us5srxAYnsrkgUv2v"
        },
        "timeout": {},
        "customBody": "={\n  \"includeNestedComments\": false,\n  \"startUrls\": [\n    {\n      \"url\": \"{{ $json.url }}\"\n    }\n  ],\n  \"viewOption\": \"RANKED_UNFILTERED\"\n}",
        "actorSource": "store"
      },
      "credentials": {
        "apifyApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4b60b801-e1c3-462f-9ae7-54bd5ad31deb",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1136,
        192
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "comments"
      },
      "typeVersion": 1
    },
    {
      "id": "2710e260-7821-4124-a8ca-bbf141d0c66a",
      "name": "Edit Fields1",
      "type": "n8n-nodes-base.set",
      "position": [
        -288,
        -16
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c2352de0-2c8d-43da-a6d9-f37694dfcdc2",
              "name": "url",
              "type": "string",
              "value": "={{ $json.url }}"
            },
            {
              "id": "f6d0ed60-52c5-4140-97fd-db155bd20214",
              "name": "post",
              "type": "number",
              "value": 11
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "c6787660-b758-4488-ad6f-8f79e8700c23",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -256
      ],
      "parameters": {
        "width": 1280,
        "height": 448,
        "content": "## Facebook Scraping Automation  \n**Automation**: This workflow scrapes posts from a Facebook group and inserts them into a **Supabase** database.  \n**Step-by-Step**:  \n1. **Facebook Group Scraping**: Posts are scraped from the group using the Apify node.  \n2. **Data Formatting**: Scraped posts are cleaned and processed before being stored in Supabase Post table  \n\n**Features**:\n- Automated scraping of posts.\n- Real-time data syncing with Supabase."
      },
      "typeVersion": 1
    },
    {
      "id": "5e7c4255-54d3-4386-a6c5-cb3b4bd4b141",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -528,
        272
      ],
      "parameters": {
        "width": 1104,
        "height": 416,
        "content": "## Scraping Comments for Previous Posts  \n**Automation**: In this part of the workflow, we scrape the **comments** for the posts that were scraped earlier from the Facebook group.  \n**Step-by-Step**:  \n1. **Fetching Post Comments**: For each post scraped earlier, the workflow fetches its comments using the Apify node.  \n2. **Data Processing**: The comments are processed and formatted before being stored in **Supabase** comments table along with the original post data.  \n\n\n**Features**:\n- Automated scraping of post comments.\n- Real-time syncing with Supabase.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a9e0e2f7-797c-45b2-9ea9-9f32cbeff241",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        640,
        -64
      ],
      "parameters": {
        "width": 896,
        "height": 544,
        "content": "## Scraping Comments on Comments (Sub-comments)  \n**Automation**: In this step, the workflow scrapes **sub-comments** (comments on the previously scraped comments) and stores them in a **separate table** in **Supabase**.  \n**Step-by-Step**:  \n1. **Fetching Sub-comments**: For each comment that was scraped earlier, the workflow fetches any replies or sub-comments.  \n2. **Data Processing**: The sub-comments are processed, cleaned, and formatted before being stored in a different **Supabase table**.  \n\n**Features**:\n- Automated scraping of sub-comments.\n- Real-time syncing with a different Supabase table.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "5344a691-bf58-4ae5-a099-cf338472b4d2",
      "name": "On form submission",
      "type": "n8n-nodes-base.formTrigger",
      "position": [
        -448,
        -16
      ],
      "parameters": {
        "options": {},
        "formTitle": "URL",
        "formFields": {
          "values": [
            {
              "fieldLabel": "url",
              "placeholder": "Enter URL",
              "requiredField": true
            },
            {
              "fieldType": "number",
              "fieldLabel": "Number of posts",
              "placeholder": "Enter number of posts to scrape other wise it will scrape all the posts"
            }
          ]
        }
      },
      "typeVersion": 2.3
    }
  ],
  "connections": {
    "If1": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Create a row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add A Post": {
      "main": [
        [
          {
            "node": "ScrapeComments",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create a row": {
      "main": [
        []
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Run an Actor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run an Actor": {
      "main": [
        [
          {
            "node": "Get dataset items",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add A Comment": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ScrapeComments": {
      "main": [
        [
          {
            "node": "Get dataset items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get dataset items": {
      "main": [
        [
          {
            "node": "Add A Post",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get dataset items1": {
      "main": [
        [
          {
            "node": "Add A Comment",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On form submission": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}