{
  "name": "Automated discord spam moderation with AI and human-in-the-loop",
  "nodes": [
    {
      "id": "59b7eed3-8622-4722-b93f-f225cc0aa4e0",
      "name": "Spam Detection",
      "type": "@n8n/n8n-nodes-langchain.textClassifier",
      "position": [
        260,
        100
      ]
    },
    {
      "id": "74420874-d831-4ff0-a8f4-e7c3b6551c57",
      "name": "Get Recent Messages",
      "type": "n8n-nodes-base.discord",
      "position": [
        -1020,
        40
      ]
    },
    {
      "id": "6db26c7e-f1eb-45b8-a444-01270fab157f",
      "name": "Only Once",
      "type": "n8n-nodes-base.removeDuplicates",
      "position": [
        -820,
        40
      ]
    },
    {
      "id": "36923da1-5ebc-40fc-9780-74845ff2b268",
      "name": "Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        240,
        260
      ]
    },
    {
      "id": "af01bb60-fdef-4fa1-bf33-1862a18ebc99",
      "name": "Warn User",
      "type": "n8n-nodes-base.discord",
      "position": [
        2880,
        20
      ]
    },
    {
      "id": "04e9f167-f816-4056-813a-3168dc22f209",
      "name": "Warn User Only",
      "type": "n8n-nodes-base.discord",
      "position": [
        2540,
        180
      ]
    },
    {
      "id": "41240c95-c5c1-4ac2-81e7-782ff8f3511b",
      "name": "Group By User",
      "type": "n8n-nodes-base.code",
      "position": [
        -540,
        100
      ]
    },
    {
      "id": "03d56683-c307-455d-bd03-84107d30f328",
      "name": "For Each User...",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -160,
        100
      ]
    },
    {
      "id": "e7eb71a8-cfe5-4e3b-81c1-66ea18cc55ec",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        -360,
        100
      ]
    },
    {
      "id": "b74a7092-2b51-452b-bf29-6620969b3efb",
      "name": "Message to List",
      "type": "n8n-nodes-base.code",
      "position": [
        100,
        100
      ]
    },
    {
      "id": "762e3a5e-e013-4ca3-a2a9-cf7d5b0dd3f4",
      "name": "Notify Moderators with Send & Wait",
      "type": "n8n-nodes-base.discord",
      "position": [
        1980,
        180
      ]
    },
    {
      "id": "f35bc6b0-855c-451b-aee7-e2af4e268893",
      "name": "Flag as Spam",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        0
      ]
    },
    {
      "id": "f77a0101-d209-4d3c-ab4a-405579a1f539",
      "name": "Flag as Not Spam",
      "type": "n8n-nodes-base.set",
      "position": [
        620,
        200
      ]
    },
    {
      "id": "eefe79e2-603f-4f12-a385-fab4b8bdbc65",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        800,
        100
      ]
    },
    {
      "id": "f7d6cccc-0d4a-4353-bc30-9a760196361f",
      "name": "Spam Messages Only",
      "type": "n8n-nodes-base.filter",
      "position": [
        1060,
        100
      ]
    },
    {
      "id": "7b4257b9-a5d3-4542-b4e2-563bf5634aa5",
      "name": "Has Flagged Messages?",
      "type": "n8n-nodes-base.if",
      "position": [
        1240,
        180
      ]
    },
    {
      "id": "0282a8bf-ab06-427f-b58b-83131205b26c",
      "name": "Get Message IDs",
      "type": "n8n-nodes-base.code",
      "position": [
        2540,
        20
      ]
    },
    {
      "id": "fc43a315-6b81-4d93-8e11-7955b7650b94",
      "name": "Delete Messages",
      "type": "n8n-nodes-base.discord",
      "position": [
        2720,
        20
      ]
    },
    {
      "id": "3868754b-26df-4f06-b27b-dba3959cb365",
      "name": "Receive Instructions",
      "type": "n8n-nodes-base.switch",
      "position": [
        2180,
        180
      ]
    },
    {
      "id": "27ea2dd8-07f0-438a-bee8-8c4a6ee7b5f7",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1280,
        -160
      ],
      "parameters": {
        "width": 620,
        "height": 520,
        "content": "## 1. Get Channel Messages\n[Read more about the scheduled Trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/)\n\nThe scheduled trigger is used to execute this w"
      }
    },
    {
      "id": "66e770ab-4eaa-40b6-be73-c36bad254c2a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -160
      ],
      "parameters": {
        "width": 640,
        "height": 520,
        "content": "## 2. Group Messages By User\n[Learn more about the loop node](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.splitinbatches/)\n\nWhen dealing with nested data such as user and messag"
      }
    },
    {
      "id": "963074bf-91e5-4a47-886d-0dbcbbba8fc4",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        20,
        -160
      ],
      "parameters": {
        "width": 960,
        "height": 620,
        "content": "## 3. Spam Detection using AI-powered Text Classification\n[Learn more about the text classification node](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.text-cla"
      }
    },
    {
      "id": "0cbcfe9d-7f66-423c-b930-a3c700636bd8",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1680,
        -160
      ],
      "parameters": {
        "width": 740,
        "height": 620,
        "content": "## 5. Moderation using Human-in-the-Loop\n[Read more about n8n's human-fallback functionality](https://docs.n8n.io/advanced-ai/examples/human-fallback/)\n\nIn this step, we can use the \"Send and Wait for"
      }
    },
    {
      "id": "c808c1a9-818e-4652-a92b-b6be1cb12706",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        2440,
        -160
      ],
      "parameters": {
        "width": 660,
        "height": 680,
        "content": "## 6. Execute Moderation Actions\n[Learn more about the Discord node](https://docs.n8n.io/integrations/builtin/app-nodes/n8n-nodes-base.discord/)\n\nFinally, moderation actions can be executed on behalf "
      }
    },
    {
      "id": "c08416cb-a477-4ccc-b682-85c35d9c2cd6",
      "name": "Moderation Subworkflow",
      "type": "n8n-nodes-base.executeWorkflow",
      "position": [
        1460,
        200
      ]
    },
    {
      "id": "f130b908-1653-4cb4-a72d-ae539c7a08dc",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1000,
        -160
      ],
      "parameters": {
        "width": 660,
        "height": 620,
        "content": "## 4. Concurrent Processing using Subworkflows\n[Learn more about Subworkflow Trigger](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.executeworkflow)\n\nOne issue we might come acros"
      }
    },
    {
      "id": "dc5e79f1-1ed9-4171-a787-a6b9dfee71f2",
      "name": "When Executed by Another Workflow",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "position": [
        1780,
        180
      ]
    },
    {
      "id": "df28cb07-a4fe-4edf-afd0-18f4fa12521d",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1700,
        -580
      ],
      "parameters": {
        "width": 380,
        "height": 940,
        "content": "## Try it out\n### This n8n template demonstrates how you can automate community moderation using human-in-the-loop functionality for Discord.\n\nThe use-case is for detecting and dealing with spam messa"
      }
    },
    {
      "id": "a437d4f3-af31-4677-b853-99832ff6c051",
      "name": "No Action Taken",
      "type": "n8n-nodes-base.noOp",
      "position": [
        2540,
        340
      ]
    },
    {
      "id": "82a5b512-296b-4ad7-aa50-2f34ff2cf681",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1220,
        40
      ]
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Spam Messages Only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Model": {
      "ai_languageModel": [
        [
          {
            "node": "Spam Detection",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Only Once": {
      "main": [
        [
          {
            "node": "Group By User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Warn User": {
      "main": [
        []
      ]
    },
    "Flag as Spam": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group By User": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spam Detection": {
      "main": [
        [
          {
            "node": "Flag as Spam",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Flag as Not Spam",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Warn User Only": {
      "main": [
        []
      ]
    },
    "Delete Messages": {
      "main": [
        [
          {
            "node": "Warn User",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Message IDs": {
      "main": [
        [
          {
            "node": "Delete Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message to List": {
      "main": [
        [
          {
            "node": "Spam Detection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Flag as Not Spam": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "For Each User...": {
      "main": [
        [],
        [
          {
            "node": "Message to List",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Get Recent Messages",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Spam Messages Only": {
      "main": [
        [
          {
            "node": "Has Flagged Messages?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Recent Messages": {
      "main": [
        [
          {
            "node": "Only Once",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Receive Instructions": {
      "main": [
        [
          {
            "node": "Get Message IDs",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Warn User Only",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Action Taken",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Has Flagged Messages?": {
      "main": [
        [
          {
            "node": "Moderation Subworkflow",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Moderation Subworkflow": {
      "main": [
        [
          {
            "node": "For Each User...",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When Executed by Another Workflow": {
      "main": [
        [
          {
            "node": "Notify Moderators with Send & Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notify Moderators with Send & Wait": {
      "main": [
        [
          {
            "node": "Receive Instructions",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}