{
  "name": "Community Hub - Compliance Snap & Lock Orchestrator",
  "nodes": [
    { "parameters": { "httpMethod": "POST", "path": "trigger-compliance-lock", "responseMode": "lastNode", "options": {} }, "name": "Webhook Trigger (Compliance Lock)", "type": "n8n-nodes-base.webhook", "typeVersion": 1, "id": "webhookTrigger" },
    { "parameters": { "authentication": "credentials", "credentials": { "mySql": { "id": "YOUR_MYSQL_CREDENTIAL_ID", "name": "MySQL Dev" } }, "query": "START TRANSACTION;\nUPDATE conversations SET status = 'locked', updated_at = NOW() WHERE id = {{ $json.body.conversation_id }};\n\nINSERT INTO compliance_snapshots (original_message_id, conversation_id, snapshot_conversation_status, sender_id, content, type, created_at, snapshot_at)\nSELECT id, conversation_id, 'locked', sender_id, content, type, created_at, NOW()\nFROM messages\nWHERE conversation_id = {{ $json.body.conversation_id }}\nORDER BY created_at DESC\nLIMIT 100;\n\nINSERT INTO participants (conversation_id, user_id, role, last_read_at)\nSELECT {{ $json.body.conversation_id }}, u.id, 'compliance_officer', NULL\nFROM users u\nWHERE u.role = 'compliance_officer' AND NOT EXISTS (\n    SELECT 1 FROM participants p WHERE p.conversation_id = {{ $json.body.conversation_id }} AND p.user_id = u.id\n) LIMIT 1;\n\nCOMMIT;", "options": {}, "includeQueryResults": true }, "name": "Atomic Lock & Snapshot Transaction", "type": "n8n-nodes-base.mySql", "typeVersion": 1, "id": "atomicLockSnapshot" },
    { "parameters": { "url": "YOUR_WEBSOCKET_SERVICE_API_ENDPOINT/broadcast", "method": "POST", "jsonParameters": true, "body": { "conversation_id": "={{$json.body.conversation_id}}", "event": "conversation_status_update", "status": "locked", "complianceOfficerBadge": true }, "sendOnlySetParameters": true, "options": {} }, "name": "WebSocket Broadcast (Lock Status)", "type": "n8n-nodes-base.httpRequest", "typeVersion": 3, "id": "wsBroadcastLockStatus" },
    { "parameters": { "authentication": "credentials", "credentials": { "mySql": { "id": "YOUR_MYSQL_CREDENTIAL_ID", "name": "MySQL Dev" } }, "query": "SELECT id, firebase_token FROM users WHERE role = 'compliance_officer' LIMIT 1;", "options": {} }, "name": "Get Compliance Officer Details", "type": "n8n-nodes-base.mySql", "typeVersion": 1, "id": "getOfficerDetails" },
    { "parameters": { "resource": "messages", "operation": "sendText", "chatId": "YOUR_ADMIN_TELEGRAM_CHAT_ID", "text": "Conversation {{ $json.body.conversation_id }} has been locked for compliance review. Compliance Officer: {{ $json.first().json.username || 'N/A' }}.", "allowHtml": false, "disableWebPagePreview": false, "disableNotification": false, "options": {} }, "name": "Notify Admin/Officer via Telegram", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "id": "notifyTelegram", "credentials": { "telegramApi": { "id": "WkHKUk8lgUqCv1PL", "name": "Telegram Bot" } }, "alwaysOutputData": true }
  ],
  "connections": {
    "Webhook Trigger (Compliance Lock)": { "main": [ [ { "node": "Atomic Lock & Snapshot Transaction", "type": "main", "index": 0 } ] ] },
    "Atomic Lock & Snapshot Transaction": { "main": [ [ { "node": "WebSocket Broadcast (Lock Status)", "type": "main", "index": 0 }, { "node": "Get Compliance Officer Details", "type": "main", "index": 0 } ] ] },
    "Get Compliance Officer Details": { "main": [ [ { "node": "Notify Admin/Officer via Telegram", "type": "main", "index": 0 } ] ] },
    "WebSocket Broadcast (Lock Status)": { "main": [ [ { "node": "Notify Admin/Officer via Telegram", "type": "main", "index": 0 } ] ] }
  },
  "settings": {},
  "staticData": {}
}
