{
  "name": "Community Hub - Automated Conversation Archiver",
  "nodes": [
    { "parameters": { "mode": "every", "value": "1", "unit": "days", "atHour": "03", "atMinute": "00", "timezone": "Europe/Dublin" }, "name": "Daily Schedule", "type": "n8n-nodes-base.cron", "typeVersion": 1, "id": "cronTrigger" },
    { "parameters": { "authentication": "credentials", "credentials": { "mySql": { "id": "YOUR_MYSQL_CREDENTIAL_ID", "name": "MySQL Dev" } }, "query": "SELECT c.id FROM conversations c JOIN competitions comp ON JSON_EXTRACT(c.metadata, '$.competition_id') = comp.id WHERE c.type = 'automated' AND comp.end_date < DATE_SUB(CURDATE(), INTERVAL 30 DAY) AND c.status != 'archived';", "options": {} }, "name": "Find Archivable Conversations", "type": "n8n-nodes-base.mySql", "typeVersion": 1, "id": "findArchivable" },
    { "parameters": { "resource": "messages", "operation": "sendText", "chatId": "YOUR_ADMIN_TELEGRAM_CHAT_ID", "text": "=If($json['conversations_to_archive'].length > 0, 'Archived ' + $json['conversations_to_archive'].length + ' conversations.', 'No conversations to archive today.')", "allowHtml": false, "disableWebPagePreview": false, "disableNotification": false, "options": {} }, "name": "Notify Admin", "type": "n8n-nodes-base.telegram", "typeVersion": 1, "id": "notifyAdmin", "credentials": { "telegramApi": { "id": "WkHKUk8lgUqCv1PL", "name": "Telegram Bot" } }, "alwaysOutputData": true },
    { "parameters": { "conditions": { "string": [ { "value1": "={{$json.length}}", "operator": "notEquals", "value2": "0" } ] } }, "name": "If Conversations Found", "type": "n8n-nodes-base.if", "typeVersion": 1, "id": "ifConversations" },
    { "parameters": { "authentication": "credentials", "credentials": { "mySql": { "id": "YOUR_MYSQL_CREDENTIAL_ID", "name": "MySQL Dev" } }, "query": "UPDATE conversations SET status = 'archived', updated_at = NOW() WHERE id = {{ $json.id }};", "options": {} }, "name": "Archive Conversation", "type": "n8n-nodes-base.mySql", "typeVersion": 1, "id": "archiveConversation" }
  ],
  "connections": {
    "Daily Schedule": { "main": [ [ { "node": "Find Archivable Conversations", "type": "main", "index": 0 } ] ] },
    "Find Archivable Conversations": { "main": [ [ { "node": "If Conversations Found", "type": "main", "index": 0 } ] ] },
    "If Conversations Found": { "main": [ [ { "node": "Archive Conversation", "type": "main", "index": 0 } ] ] },
    "Archive Conversation": { "main": [ [ { "node": "Notify Admin", "type": "main", "index": 0 } ] ] }
  },
  "settings": {},
  "staticData": {}
}
