Files
n8n/backups/2025-12-27/Remnawave Final Loop Fix.json

1 line
12 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"updatedAt":"2025-12-20T09:44:00.286Z","createdAt":"2025-12-20T08:24:59.964Z","id":"IUYOCZtINnHMUhWI","name":"Remnawave Final Loop Fix","active":true,"isArchived":false,"nodes":[{"parameters":{"updates":["message"],"additionalFields":{}},"id":"eb97aa49-b1b6-4249-8a9d-60254966b59d","name":"Telegram Trigger","type":"n8n-nodes-base.telegramTrigger","typeVersion":1,"position":[-528,160],"webhookId":"remnawave-add-user","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"jsCode":"// Получаем текст\nconst text = $('Telegram Trigger').first().json.message.text;\n\n// Настройки времени\nlet days = 30;\nlet durationMultiplier = 24 * 60 * 60 * 1000;\n\n// Парсим срок (30d, 1m, 24h)\nconst durationRegex = /\\b(\\d+)([dmh])\\b/i;\nconst durationMatch = text.match(durationRegex);\n\nif (durationMatch) {\n const value = parseInt(durationMatch[1]);\n const unit = durationMatch[2].toLowerCase();\n if (unit === 'd') days = value;\n if (unit === 'm') days = value * 30;\n if (unit === 'h') days = value / 24;\n}\n\n// Считаем дату окончания\nconst expireDateSec = Math.floor((Date.now() + (days * durationMultiplier)) / 1000);\n\n// Ищем юзеров\nconst lines = text.split(/[\\n\\s]+/);\nconst users = [];\n\nfor (const line of lines) {\n const cleanLine = line.trim();\n if (!cleanLine) continue;\n if (cleanLine.startsWith('/')) continue;\n if (cleanLine.match(durationRegex)) continue;\n \n users.push(cleanLine);\n}\n\nreturn users.map(user => ({\n json: {\n username: user,\n expireDateSec: expireDateSec,\n days: days\n }\n}));"},"id":"f135a0a1-f751-4e59-866f-1e617b61ae3c","name":"Parse Input","type":"n8n-nodes-base.code","typeVersion":2,"position":[-96,160]},{"parameters":{"batchSize":1,"options":{}},"id":"6e21712b-51fc-454d-a744-e05feccfeee0","name":"Split In Batches","type":"n8n-nodes-base.splitInBatches","typeVersion":2,"position":[128,160]},{"parameters":{"method":"POST","url":"={{ $('Config').item.json.BASE_URL }}/api/users","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ 'Bearer ' + $('Config').item.json.API_TOKEN }}"}]},"sendBody":true,"bodyParameters":{"parameters":[{"name":"username","value":"={{ $json.username }}"},{"name":"expireAt","value":"={{ new Date($json.expireDateSec * 1000).toISOString() }}"},{"name":"externalSquadUuid","value":"={{ $('Config').item.json.EXTERNAL_SQUAD_ID ? $('Config').item.json.EXTERNAL_SQUAD_ID : null }}"},{"name":"trafficLimitBytes","value":0},{"name":"trafficLimitStrategy","value":"NO_RESET"}]},"options":{}},"id":"0bac5c3d-d051-4da9-ada2-2ce2bd883127","name":"1. Create User","type":"n8n-nodes-base.httpRequest","typeVersion":4.1,"position":[368,48],"onError":"continueErrorOutput"},{"parameters":{"method":"POST","url":"={{ $('Config').item.json.BASE_URL }}/api/internal-squads/{{ $('Config').item.json.INTERNAL_SQUAD_ID }}/bulk-actions/add-users","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ 'Bearer ' + $('Config').item.json.API_TOKEN }}"}]},"sendBody":true,"bodyParameters":{"parameters":[{"name":"uuids","value":"={{ [ $json.uuid ] }}"}]},"options":{}},"id":"d13903c8-4292-4a22-8be0-c4b1b7cda704","name":"2. Add to Squad","type":"n8n-nodes-base.httpRequest","typeVersion":4.1,"position":[576,48],"onError":"continueErrorOutput"},{"parameters":{"chatId":"={{ $('Telegram Trigger').item.json.message.chat.id }}","text":"={{ $('Split In Batches').item.json.username }} — ✅ Создан и добавлен в группу\nего подписка:\n{{ $('1. Create User').item.json.response.subscriptionUrl }}","additionalFields":{"parse_mode":"HTML"}},"id":"0a9103c9-928d-4982-9692-734b4a841bee","name":"Reply Success","type":"n8n-nodes-base.telegram","typeVersion":1,"position":[800,48],"webhookId":"aa2109f8-e48b-4d2f-b557-509cea0428f7","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"chatId":"={{ $('Telegram Trigger').item.json.message.chat.id }}","text":"={{ $('Split In Batches').item.json.username }} — ❌ Ошибка: {{ $input.item.json.message || JSON.stringify($input.item.json) }}","additionalFields":{}},"id":"825fa336-4485-40cf-a132-60ad0adef891","name":"Reply Error","type":"n8n-nodes-base.telegram","typeVersion":1,"position":[800,256],"webhookId":"9719e5da-0945-4e1a-8c15-82e88b89e91d","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"fields":{"values":[{"name":"BASE_URL","stringValue":"https://panel.infra.pet"},{"name":"API_TOKEN","stringValue":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiNDQ4NDNmNjAtYzY3YS00OWM3LWJkOWMtMzEwOGE4ZTkxYjM2IiwidXNlcm5hbWUiOm51bGwsInJvbGUiOiJBUEkiLCJpYXQiOjE3NjYyMTkwMjUsImV4cCI6MTA0MDYxMzI2MjV9.QTcYdHeCYegiFbodTy6Q0VPExvso8ui-7kujxEjl1D0"},{"name":"INTERNAL_SQUAD_ID","stringValue":"77e82a2f-b15b-4678-9cdc-425f6f8e1dcc"},{"name":"EXTERNAL_SQUAD_ID","stringValue":"55f91437-419a-4412-bcfc-6d43c775a997"}]},"options":{}},"id":"3201251d-293c-48b2-aeb1-05bceeb60e00","name":"Config","type":"n8n-nodes-base.set","typeVersion":3.2,"position":[-304,160]}],"connections":{"Telegram Trigger":{"main":[[{"node":"Config","type":"main","index":0}]]},"Parse Input":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]},"Split In Batches":{"main":[[{"node":"1. Create User","type":"main","index":0}]]},"1. Create User":{"main":[[{"node":"2. Add to Squad","type":"main","index":0}],[{"node":"Reply Error","type":"main","index":0}]]},"2. Add to Squad":{"main":[[{"node":"Reply Success","type":"main","index":0}],[{"node":"Reply Error","type":"main","index":0}]]},"Config":{"main":[[{"node":"Parse Input","type":"main","index":0}]]},"Reply Error":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]},"Reply Success":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]}},"settings":{"executionOrder":"v1","availableInMCP":false},"staticData":null,"meta":{"templateCredsSetupCompleted":true},"pinData":{},"versionId":"d8941967-e5cd-4649-8165-efff8c698045","activeVersionId":"d8941967-e5cd-4649-8165-efff8c698045","triggerCount":1,"shared":[{"updatedAt":"2025-12-20T08:24:59.964Z","createdAt":"2025-12-20T08:24:59.964Z","role":"workflow:owner","workflowId":"IUYOCZtINnHMUhWI","projectId":"sYuiFAb87pAir6jV"}],"activeVersion":{"updatedAt":"2025-12-21T11:47:18.050Z","createdAt":"2025-12-20T09:44:00.288Z","versionId":"d8941967-e5cd-4649-8165-efff8c698045","workflowId":"IUYOCZtINnHMUhWI","nodes":[{"parameters":{"updates":["message"],"additionalFields":{}},"id":"eb97aa49-b1b6-4249-8a9d-60254966b59d","name":"Telegram Trigger","type":"n8n-nodes-base.telegramTrigger","typeVersion":1,"position":[-528,160],"webhookId":"remnawave-add-user","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"jsCode":"// Получаем текст\nconst text = $('Telegram Trigger').first().json.message.text;\n\n// Настройки времени\nlet days = 30;\nlet durationMultiplier = 24 * 60 * 60 * 1000;\n\n// Парсим срок (30d, 1m, 24h)\nconst durationRegex = /\\b(\\d+)([dmh])\\b/i;\nconst durationMatch = text.match(durationRegex);\n\nif (durationMatch) {\n const value = parseInt(durationMatch[1]);\n const unit = durationMatch[2].toLowerCase();\n if (unit === 'd') days = value;\n if (unit === 'm') days = value * 30;\n if (unit === 'h') days = value / 24;\n}\n\n// Считаем дату окончания\nconst expireDateSec = Math.floor((Date.now() + (days * durationMultiplier)) / 1000);\n\n// Ищем юзеров\nconst lines = text.split(/[\\n\\s]+/);\nconst users = [];\n\nfor (const line of lines) {\n const cleanLine = line.trim();\n if (!cleanLine) continue;\n if (cleanLine.startsWith('/')) continue;\n if (cleanLine.match(durationRegex)) continue;\n \n users.push(cleanLine);\n}\n\nreturn users.map(user => ({\n json: {\n username: user,\n expireDateSec: expireDateSec,\n days: days\n }\n}));"},"id":"f135a0a1-f751-4e59-866f-1e617b61ae3c","name":"Parse Input","type":"n8n-nodes-base.code","typeVersion":2,"position":[-96,160]},{"parameters":{"batchSize":1,"options":{}},"id":"6e21712b-51fc-454d-a744-e05feccfeee0","name":"Split In Batches","type":"n8n-nodes-base.splitInBatches","typeVersion":2,"position":[128,160]},{"parameters":{"method":"POST","url":"={{ $('Config').item.json.BASE_URL }}/api/users","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ 'Bearer ' + $('Config').item.json.API_TOKEN }}"}]},"sendBody":true,"bodyParameters":{"parameters":[{"name":"username","value":"={{ $json.username }}"},{"name":"expireAt","value":"={{ new Date($json.expireDateSec * 1000).toISOString() }}"},{"name":"externalSquadUuid","value":"={{ $('Config').item.json.EXTERNAL_SQUAD_ID ? $('Config').item.json.EXTERNAL_SQUAD_ID : null }}"},{"name":"trafficLimitBytes","value":0},{"name":"trafficLimitStrategy","value":"NO_RESET"}]},"options":{}},"id":"0bac5c3d-d051-4da9-ada2-2ce2bd883127","name":"1. Create User","type":"n8n-nodes-base.httpRequest","typeVersion":4.1,"position":[368,48],"onError":"continueErrorOutput"},{"parameters":{"method":"POST","url":"={{ $('Config').item.json.BASE_URL }}/api/internal-squads/{{ $('Config').item.json.INTERNAL_SQUAD_ID }}/bulk-actions/add-users","sendHeaders":true,"headerParameters":{"parameters":[{"name":"Authorization","value":"={{ 'Bearer ' + $('Config').item.json.API_TOKEN }}"}]},"sendBody":true,"bodyParameters":{"parameters":[{"name":"uuids","value":"={{ [ $json.uuid ] }}"}]},"options":{}},"id":"d13903c8-4292-4a22-8be0-c4b1b7cda704","name":"2. Add to Squad","type":"n8n-nodes-base.httpRequest","typeVersion":4.1,"position":[576,48],"onError":"continueErrorOutput"},{"parameters":{"chatId":"={{ $('Telegram Trigger').item.json.message.chat.id }}","text":"={{ $('Split In Batches').item.json.username }} — ✅ Создан и добавлен в группу\nего подписка:\n{{ $('1. Create User').item.json.response.subscriptionUrl }}","additionalFields":{"parse_mode":"HTML"}},"id":"0a9103c9-928d-4982-9692-734b4a841bee","name":"Reply Success","type":"n8n-nodes-base.telegram","typeVersion":1,"position":[800,48],"webhookId":"aa2109f8-e48b-4d2f-b557-509cea0428f7","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"chatId":"={{ $('Telegram Trigger').item.json.message.chat.id }}","text":"={{ $('Split In Batches').item.json.username }} — ❌ Ошибка: {{ $input.item.json.message || JSON.stringify($input.item.json) }}","additionalFields":{}},"id":"825fa336-4485-40cf-a132-60ad0adef891","name":"Reply Error","type":"n8n-nodes-base.telegram","typeVersion":1,"position":[800,256],"webhookId":"9719e5da-0945-4e1a-8c15-82e88b89e91d","credentials":{"telegramApi":{"id":"XfLtzJeW8r1QKw4d","name":"Telegram pomoshnik_monster"}}},{"parameters":{"fields":{"values":[{"name":"BASE_URL","stringValue":"https://panel.infra.pet"},{"name":"API_TOKEN","stringValue":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1dWlkIjoiNDQ4NDNmNjAtYzY3YS00OWM3LWJkOWMtMzEwOGE4ZTkxYjM2IiwidXNlcm5hbWUiOm51bGwsInJvbGUiOiJBUEkiLCJpYXQiOjE3NjYyMTkwMjUsImV4cCI6MTA0MDYxMzI2MjV9.QTcYdHeCYegiFbodTy6Q0VPExvso8ui-7kujxEjl1D0"},{"name":"INTERNAL_SQUAD_ID","stringValue":"77e82a2f-b15b-4678-9cdc-425f6f8e1dcc"},{"name":"EXTERNAL_SQUAD_ID","stringValue":"55f91437-419a-4412-bcfc-6d43c775a997"}]},"options":{}},"id":"3201251d-293c-48b2-aeb1-05bceeb60e00","name":"Config","type":"n8n-nodes-base.set","typeVersion":3.2,"position":[-304,160]}],"connections":{"Telegram Trigger":{"main":[[{"node":"Config","type":"main","index":0}]]},"Parse Input":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]},"Split In Batches":{"main":[[{"node":"1. Create User","type":"main","index":0}]]},"1. Create User":{"main":[[{"node":"2. Add to Squad","type":"main","index":0}],[{"node":"Reply Error","type":"main","index":0}]]},"2. Add to Squad":{"main":[[{"node":"Reply Success","type":"main","index":0}],[{"node":"Reply Error","type":"main","index":0}]]},"Config":{"main":[[{"node":"Parse Input","type":"main","index":0}]]},"Reply Error":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]},"Reply Success":{"main":[[{"node":"Split In Batches","type":"main","index":0}]]}},"authors":"Oleg Grechko","name":"Version d8941967","description":"","autosaved":false},"tags":[]}