feat(f6-2/self-service): implement user registration via Telegram and Authentik

- Added canonical n8n workflow to workflows/n8n/ (SSOT compliance).
- Integrated Telegram Bot API for admin approval/denial via inline keyboards.
- Implemented Authentik Core API integration to dynamically create active users.
- Resolved critical technical constraints for audit compliance:
  * Fixed Telegram 'callback_data' 64-byte limit by optimizing payload format.
  * Resolved Authentik API 405 errors by enforcing trailing slash in endpoint URL.
  * Explicitly defined HTTP headers to prevent n8n import stripping.

Definition of Done (F6-2) Met:
- [x] Test user created via self-service flow.
- [x] Owner received enrollment link and instructions in Telegram.
- [x] Workflow committed to Git (workflows-as-code).

Closes #F6-2
Related: Sprint F6 v2, Phase 4.1 Automation Roadmap
This commit is contained in:
root committed 2026-10-13 12:10:36 +03:00
1 parent 2bbcf61803
commit 5515e26462
1 file changed
+119
@@ -0,0 +1,119 @@
{
"name": "F6-2: Self-Service Registration",
"nodes": [
{
"parameters": { "httpMethod": "POST", "path": "register-request" },
"name": "Webhook: Заявка",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [-400, 200],
"webhookId": "f6-2-register"
},
{
"parameters": {
"jsCode": "const d = $json.body || $json;\nconst u = d.username || 'user';\nconst n = d.name || 'User';\nconst e = d.email || 'u@b.ru';\nconst g = d.groups || 'gitea';\nconst approve = 'approve:' + u + ':' + e;\nconst deny = 'deny:' + u;\nreturn { json: { username: u, name: n, email: e, groups: g, approve_callback: approve, deny_callback: deny } };"
},
"name": "Code: Prepare Data",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [-150, 200]
},
{
"parameters": {
"method": "POST",
"url": "https://193.233.210.184/tg-api/bot8653974364:AAHHM4adpj1Slwi0qcPDm5IgIt6l7gl2Sxo/sendMessage",
"sendHeaders": true,
"headerParameters": { "parameters": [{ "name": "Content-Type", "value": "application/json" }] },
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"chat_id\": 273442500,\n \"text\": \"🆕 <b>Новая заявка</b>\\n\\n👤 Имя: {{ $json.name }}\\n👤 Логин: {{ $json.username }}\\n📧 Email: {{ $json.email }}\\n🔑 Группы: {{ $json.groups }}\\n\\nВыберите действие:\",\n \"parse_mode\": \"HTML\",\n \"reply_markup\": {\n \"inline_keyboard\": [\n [\n {\"text\": \"✅ Одобрить\", \"callback_data\": \"{{ $json.approve_callback }}\"},\n {\"text\": \"❌ Отклонить\", \"callback_data\": \"{{ $json.deny_callback }}\"}\n ]\n ]\n }\n}",
"options": { "allowUnauthorizedCerts": true }
},
"name": "HTTP: Отправить Admin",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [100, 200]
},
{
"parameters": { "httpMethod": "POST", "path": "tg-callback" },
"name": "Webhook: Callback TG",
"type": "n8n-nodes-base.webhook",
"typeVersion": 2,
"position": [-400, 500],
"webhookId": "f6-2-callback"
},
{
"parameters": {
"conditions": {
"conditions": [
{ "leftValue": "={{ $json.body?.callback_query?.data || $json.data }}", "rightValue": "approve:", "operator": { "type": "string", "operation": "startsWith" } }
]
}
},
"name": "IF: Одобрено?",
"type": "n8n-nodes-base.if",
"typeVersion": 2.2,
"position": [-150, 500]
},
{
"parameters": {
"method": "POST",
"url": "http://192.168.1.114:9000/api/v3/core/users/",
"sendHeaders": true,
"headerParameters": {
"parameters": [
{ "name": "Authorization", "value": "Bearer 1feyihg2W65EZv8MlreEooS7I8F6HJmXaBtY1bWhTr5AmDBkfkI14ndb8Ttk" },
{ "name": "Content-Type", "value": "application/json" }
]
},
"sendBody": true,
"specifyBody": "json",
"jsonBody": "{\n \"username\": \"{{ ($json.body?.callback_query?.data || $json.data).split(':')[1] }}\",\n \"name\": \"{{ ($json.body?.callback_query?.data || $json.data).split(':')[1] }}\",\n \"email\": \"{{ ($json.body?.callback_query?.data || $json.data).split(':')[2] }}\",\n \"is_active\": true\n}",
"options": {}
},
"name": "Authentik: Создать",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [100, 400]
},
{
"parameters": {
"method": "POST",
"url": "https://193.233.210.184/tg-api/bot8653974364:AAHHM4adpj1Slwi0qcPDm5IgIt6l7gl2Sxo/sendMessage",
"sendHeaders": true,
"headerParameters": { "parameters": [{ "name": "Content-Type", "value": "application/json" }] },
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"chat_id\": 273442500,\n \"text\": \"✅ <b>Создан!</b>\\n\\n👤 {{ ($json.body?.callback_query?.data || $json.data).split(':')[1] }}\\n🔗 <a href=\\\"https://authentik.buryans.ru/if/flow/default-provider-enrollment-flow/\\\">Enrollment (24ч)</a>\",\n \"parse_mode\": \"HTML\"\n}",
"options": { "allowUnauthorizedCerts": true }
},
"name": "HTTP: Ссылка Admin",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [350, 400]
},
{
"parameters": {
"method": "POST",
"url": "https://193.233.210.184/tg-api/bot8653974364:AAHHM4adpj1Slwi0qcPDm5IgIt6l7gl2Sxo/sendMessage",
"sendHeaders": true,
"headerParameters": { "parameters": [{ "name": "Content-Type", "value": "application/json" }] },
"sendBody": true,
"specifyBody": "json",
"jsonBody": "={\n \"chat_id\": 273442500,\n \"text\": \"❌ <b>Отклонено</b>\\n\\nПользователь {{ ($json.body?.callback_query?.data || $json.data).split(':')[1] }} не был создан.\",\n \"parse_mode\": \"HTML\"\n}",
"options": { "allowUnauthorizedCerts": true }
},
"name": "HTTP: Отказ Admin",
"type": "n8n-nodes-base.httpRequest",
"typeVersion": 4.2,
"position": [100, 600]
}
],
"connections": {
"Webhook: Заявка": { "main": [[{ "node": "Code: Prepare Data", "type": "main", "index": 0 }]] },
"Code: Prepare Data": { "main": [[{ "node": "HTTP: Отправить Admin", "type": "main", "index": 0 }]] },
"Webhook: Callback TG": { "main": [[{ "node": "IF: Одобрено?", "type": "main", "index": 0 }]] },
"IF: Одобрено?": { "main": [[{ "node": "Authentik: Создать", "type": "main", "index": 0 }], [{ "node": "HTTP: Отказ Admin", "type": "main", "index": 0 }]] },
"Authentik: Создать": { "main": [[{ "node": "HTTP: Ссылка Admin", "type": "main", "index": 0 }]] }
}
}