Hinzufügen einer Benutzungsauthentifizierungsschicht für den Telegram-Bot sowie Administrator-Erinnerungen
Dies ist ein Content Creation, Multimodal AI-Bereich Automatisierungsworkflow mit 11 Nodes. Hauptsächlich werden If, Code, Telegram, TelegramTrigger und andere Nodes verwendet. Fügen Sie einer Telegram-Bot-Schicht für Benutzerberechtigungen sowie eine Erinnerung an Admins hinzu
- •Telegram Bot Token
Verwendete Nodes (11)
Kategorie
{
"meta": {
"instanceId": "82ee17baaf8f0713e544083c37cbe259962ad0fcd85204d3262a7dfafc166630",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "572073b3-d68a-45cb-9c60-cdf3c697b151",
"name": "Notiz - Einführung",
"type": "n8n-nodes-base.stickyNote",
"position": [
3328,
9664
],
"parameters": {
"color": 6,
"width": 676,
"height": 720,
"content": "# 🛡️ BotGuard - Why You Need This\n\n## ⚠️ The Problem\n\nMost Telegram bot examples assume **anyone can use your bot**. There's usually **no protection whatsoever**.\n\nThis is dangerous when your bot:\n- 🤖 Uses AI APIs (OpenAI, Claude) - **costs money per message**\n- 💰 Calls paid services - **drains your credits**\n- 🔐 Accesses sensitive data - **security risk**\n- 📊 Processes heavy workloads - **server overload**\n\n## ✅ The Solution\n\n**BotGuard** protects your bot by:\n\n1️⃣ **Whitelist Control** - Only allowed User IDs can use the bot\n2️⃣ **Admin Alerts** - Get notified of unauthorized access attempts\n3️⃣ **Flexible Messages** - Customize denied/success responses\n4️⃣ **Easy Setup** - Just add User IDs to the code\n\nThis is a **simple but effective** authorization layer that sits before your main workflow, preventing unauthorized usage and protecting your resources.\n\n💡 **Modify messages** to suggest users request access, or keep it restricted - your choice!"
},
"typeVersion": 1
},
{
"id": "635277cb-fa42-4c8c-aaac-373132606208",
"name": "Notiz - Schnellstart",
"type": "n8n-nodes-base.stickyNote",
"position": [
4064,
9664
],
"parameters": {
"color": 4,
"width": 520,
"height": 720,
"content": "# 🚀 Quick Start\n\n## 1️⃣ Configure Your Bot\nEdit **BotGuard Authorization** node:\n- Add your User ID to `AllowedUsers`\n- Add admin User IDs to `Administrators`\n\n## 2️⃣ Get User IDs\n- User sends message → Gets denied\n- Check denied message for User ID\n- Copy ID and add to arrays\n\n## 3️⃣ Test\n- Authorized user → Success message\n- Unauthorized user → Denied + Admin notification\n\n## 📊 Flow Overview\n```\nTelegram → BotGuard → Check Auth\n├─ TRUE → Send Success\n└─ FALSE → Send Denied + Notify Admins\n```"
},
"typeVersion": 1
},
{
"id": "b321fe86-fbf9-4ec6-b7e5-d00735d951ef",
"name": "Notiz1",
"type": "n8n-nodes-base.stickyNote",
"position": [
2432,
9136
],
"parameters": {
"color": 5,
"width": 853,
"height": 1259,
"content": "# 🛡️ BotGuard Authorization System\n\n## 📖 Complete Documentation\n\nThis workflow implements Telegram bot authorization with multi-admin notification system.\n\n## 🔑 Configuration Guide\n\n### Edit \"BotGuard Authorization\" Node:\n\n**Allowed Users (can use bot):**\n```javascript\nconst AllowedUsers = [\n { userId: 111111111, userName: 'john_doe', subscriptionType: 'basic' },\n { userId: 222222222, userName: 'jane_smith', subscriptionType: 'premium' },\n // Add your users here:\n { userId: YOUR_USER_ID, userName: 'username', subscriptionType: 'basic|premium|admin' }\n];\n```\n\n**Administrators (receive unauthorized access alerts):**\n```javascript\nconst Administrators = [\n { userId: 333333333, userName: 'admin_user', chatId: 333333333 },\n // Add admin users:\n { userId: ADMIN_ID, userName: 'admin_name', chatId: ADMIN_ID }\n];\n```\n\n## 📥 How to Get User IDs\n\n1. User sends message to bot → Gets denied\n2. Denied message shows: `Your User ID: 123456789`\n3. Copy ID and add to arrays above\n\n## 🔄 Export/Import\n\n**Export:** Workflow menu (⋮) → Download → Save JSON\n**Import:** New workflow → Menu (⋮) → Import from File → Configure Telegram credentials\n\n## 🚨 Admin Notifications\n\n**Triggers when:** Unauthorized user tries to access bot \n**Sends to:** All users in `Administrators` array \n**Includes:** Name, User ID, Language, Time, Message text\n\n## 🎯 Example Users (Replace with Real Data)\n\n- `111111111, 222222222, 333333333` - Mock placeholder IDs\n- `john_doe, jane_smith, admin_user` - Example usernames\n- Replace these with your actual users!"
},
"typeVersion": 1
},
{
"id": "aa9b6109-3e51-4005-802e-29e43fa3e887",
"name": "BotGuard-Autorisierung",
"type": "n8n-nodes-base.code",
"position": [
3504,
9168
],
"parameters": {
"jsCode": "// Configuration\nconst AllowedUsers = [\n { userId: 8032941945, userName: 'ruslan_elishev_eu', subscriptionType: 'admin' },\n { userId: 111111111, userName: 'john_doe', subscriptionType: 'basic' },\n { userId: 222222222, userName: 'jane_smith', subscriptionType: 'premium' }\n];\n\nconst Administrators = [\n { userId: 8032941945, userName: 'ruslan_elishev_eu', chatId: 8032941945 },\n { userId: 333333333, userName: 'admin_user', chatId: 333333333 }\n];\n\nconst ProcessingRequests = [];\n\ntry {\n const message = $input.item.json.message || {};\n const userId = (message.from && message.from.id) || null;\n const userName = (message.from && message.from.username) || (message.from && message.from.first_name) || 'Unknown';\n const chatId = (message.chat && message.chat.id) || null;\n const messageText = message.text || '';\n const languageCode = (message.from && message.from.language_code) || 'en';\n\n const isAuthorized = AllowedUsers.some(user => user.userId === userId);\n const isAdmin = Administrators.some(admin => admin.userId === userId);\n const isProcessingRequest = ProcessingRequests.some(req => req.userId === userId);\n const isRequestCommand = messageText.toLowerCase() === '/request';\n\n let allowEntry = isAuthorized || isAdmin;\n let blockReason = '';\n let userMessage = '';\n let adminMessage = '';\n let authorizedMessage = '';\n\n const currentTime = new Date().toISOString();\n const userInfo = AllowedUsers.find(user => user.userId === userId) || { subscriptionType: 'none' };\n\n if (allowEntry) {\n authorizedMessage = '✅ <b>Authorization Successful</b>\\n\\nWelcome back, ' + userName + '!\\nYour access level: ' + userInfo.subscriptionType + '\\n\\nProcessing your request...';\n } else if (isProcessingRequest) {\n blockReason = 'pending_approval';\n const req = ProcessingRequests.find(r => r.userId === userId);\n const reqTime = req && req.requestTime ? new Date(req.requestTime).toLocaleString() : 'Unknown';\n userMessage = '⏳ <b>Access Pending</b>\\n\\nHello ' + userName + ',\\n\\nYour access request is currently being reviewed by an administrator. You will be notified once a decision has been made.\\n\\nRequest status: <code>PENDING</code>\\nSubmitted: ' + reqTime;\n } else {\n blockReason = 'not_authorized';\n userMessage = '🚫 <b>Access Denied</b>\\n\\nHello ' + userName + ',\\n\\nYou are not authorized to use this bot. To request access, please use the /request command or contact an administrator.\\n\\nYour User ID: <code>' + userId + '</code>';\n \n if (!isRequestCommand) {\n adminMessage = '🔔 <b>Unauthorized Access Attempt</b>\\n\\n<b>User Details:</b>\\n• Name: ' + userName + '\\n• User ID: <code>' + userId + '</code>\\n• Language: ' + languageCode + '\\n• Time: ' + currentTime + '\\n• Message: ' + messageText + '\\n\\n<b>Action Required:</b>\\nReview and approve/deny access';\n }\n }\n\n const item = $input.item;\n item.json.botGuard = {\n allowEntry: allowEntry,\n blockReason: blockReason,\n userMessage: userMessage,\n adminMessage: adminMessage,\n authorizedMessage: authorizedMessage,\n isProcessingRequest: isProcessingRequest,\n isRequestCommand: isRequestCommand,\n userId: userId,\n userName: userName,\n chatId: chatId,\n messageText: messageText,\n languageCode: languageCode,\n accessAttemptTime: currentTime,\n AllowedUsers: AllowedUsers,\n Administrators: Administrators,\n originalMessage: item.json.message,\n userDetails: {\n subscriptionType: userInfo.subscriptionType,\n firstName: (message.from && message.from.first_name) || '',\n lastName: (message.from && message.from.last_name) || '',\n isBot: (message.from && message.from.is_bot) || false,\n isPremium: (message.from && message.from.is_premium) || false\n }\n };\n\n item.json.message = message;\n return item;\n} catch (error) {\n const item = $input.item;\n item.json.botGuard = {\n allowEntry: false,\n blockReason: 'error',\n userMessage: '❌ An error occurred during authorization. Please try again.',\n adminMessage: '',\n authorizedMessage: '',\n error: error.message\n };\n return item;\n}"
},
"typeVersion": 2
},
{
"id": "2957eeff-698e-4166-9c16-600b3adb1a45",
"name": "Autorisierung prüfen",
"type": "n8n-nodes-base.if",
"position": [
3712,
9168
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "auth-check",
"operator": {
"type": "boolean",
"operation": "true"
},
"leftValue": "={{ $json.botGuard.allowEntry }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2
},
{
"id": "b50e992a-4e69-4090-8859-68ca85338023",
"name": "Erfolg senden",
"type": "n8n-nodes-base.telegram",
"position": [
3984,
9152
],
"webhookId": "4ed06f4b-fd2b-4f5f-a49f-2a145abff92f",
"parameters": {
"text": "={{ $json.botGuard.authorizedMessage }}",
"chatId": "={{ $json.botGuard.chatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "j8EcZNDeFuDq9Cka",
"name": "ElishevFamilyBot"
}
},
"typeVersion": 1.2
},
{
"id": "a89c3bdf-8669-477d-a47b-0e8e8f1f6ed8",
"name": "Ablehnung senden",
"type": "n8n-nodes-base.telegram",
"position": [
3984,
9328
],
"webhookId": "4a8192ba-d5d0-4b32-9fe3-37ef8c163c52",
"parameters": {
"text": "={{ $json.botGuard.userMessage }}",
"chatId": "={{ $json.botGuard.chatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "j8EcZNDeFuDq9Cka",
"name": "ElishevFamilyBot"
}
},
"typeVersion": 1.2
},
{
"id": "778d438c-d052-4a1a-a110-0f222f537bf9",
"name": "Admin-Benachrichtigung prüfen",
"type": "n8n-nodes-base.if",
"position": [
4000,
9488
],
"parameters": {
"options": {},
"conditions": {
"options": {
"leftValue": "",
"caseSensitive": true,
"typeValidation": "loose"
},
"combinator": "and",
"conditions": [
{
"id": "has-admin-message",
"operator": {
"type": "string",
"operation": "notEmpty"
},
"leftValue": "={{ $('Check Authorization').item.json.botGuard.adminMessage }}",
"rightValue": ""
}
]
}
},
"typeVersion": 2.2
},
{
"id": "97b78d57-a2ea-4fe0-9b93-7b6d1a08ebab",
"name": "Admin-Benachrichtigungen vorbereiten",
"type": "n8n-nodes-base.code",
"position": [
4208,
9488
],
"parameters": {
"jsCode": "// Get data from Check Authorization node (before Telegram node)\nconst botGuardData = $('Check Authorization').item.json.botGuard;\nconst admins = botGuardData.Administrators;\nconst adminMessage = botGuardData.adminMessage;\n\n// Create output item for each admin\nconst items = admins.map(admin => ({\n json: {\n adminChatId: admin.chatId,\n adminUserName: admin.userName,\n adminMessage: adminMessage,\n originalData: botGuardData\n }\n}));\n\nreturn items;"
},
"typeVersion": 2
},
{
"id": "aa0b65d3-0f22-4f5b-8a09-c146f9fe8a15",
"name": "Telegram Trigger",
"type": "n8n-nodes-base.telegramTrigger",
"position": [
3312,
9168
],
"webhookId": "c4d1bcd6-c865-4b62-aa77-67aa9496f5c1",
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"id": "j8EcZNDeFuDq9Cka",
"name": "ElishevFamilyBot"
}
},
"typeVersion": 1.2
},
{
"id": "a9ad2dab-53e6-4381-a78c-7d1bb42e1b20",
"name": "Admin benachrichtigen",
"type": "n8n-nodes-base.telegram",
"position": [
4400,
9488
],
"webhookId": "1245219a-33f7-46e9-9a41-c9eef1a52b40",
"parameters": {
"text": "={{ $json.adminMessage }}",
"chatId": "={{ $json.adminChatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"id": "j8EcZNDeFuDq9Cka",
"name": "ElishevFamilyBot"
}
},
"typeVersion": 1.2
}
],
"pinData": {},
"connections": {
"aa0b65d3-0f22-4f5b-8a09-c146f9fe8a15": {
"main": [
[
{
"node": "aa9b6109-3e51-4005-802e-29e43fa3e887",
"type": "main",
"index": 0
}
]
]
},
"778d438c-d052-4a1a-a110-0f222f537bf9": {
"main": [
[
{
"node": "97b78d57-a2ea-4fe0-9b93-7b6d1a08ebab",
"type": "main",
"index": 0
}
]
]
},
"2957eeff-698e-4166-9c16-600b3adb1a45": {
"main": [
[
{
"node": "b50e992a-4e69-4090-8859-68ca85338023",
"type": "main",
"index": 0
}
],
[
{
"node": "a89c3bdf-8669-477d-a47b-0e8e8f1f6ed8",
"type": "main",
"index": 0
},
{
"node": "778d438c-d052-4a1a-a110-0f222f537bf9",
"type": "main",
"index": 0
}
]
]
},
"aa9b6109-3e51-4005-802e-29e43fa3e887": {
"main": [
[
{
"node": "2957eeff-698e-4166-9c16-600b3adb1a45",
"type": "main",
"index": 0
}
]
]
},
"97b78d57-a2ea-4fe0-9b93-7b6d1a08ebab": {
"main": [
[
{
"node": "a9ad2dab-53e6-4381-a78c-7d1bb42e1b20",
"type": "main",
"index": 0
}
]
]
}
}
}Wie verwende ich diesen Workflow?
Kopieren Sie den obigen JSON-Code, erstellen Sie einen neuen Workflow in Ihrer n8n-Instanz und wählen Sie "Aus JSON importieren". Fügen Sie die Konfiguration ein und passen Sie die Anmeldedaten nach Bedarf an.
Für welche Szenarien ist dieser Workflow geeignet?
Fortgeschritten - Content-Erstellung, Multimodales KI
Ist es kostenpflichtig?
Dieser Workflow ist völlig kostenlos. Beachten Sie jedoch, dass Drittanbieterdienste (wie OpenAI API), die im Workflow verwendet werden, möglicherweise kostenpflichtig sind.
Verwandte Workflows
Ruslan Elishev
@relishevProfessional Product Director that cought vibe of Automaion and Solo Programming and Context Aware AI Vibe coding.
Diesen Workflow teilen