This workflow corresponds to n8n.io template #9203 — we link there as the canonical source.
This workflow follows the Telegram → Telegram Trigger recipe pattern — see all workflows that pair these two integrations.
The workflow JSON
Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →
{
"meta": {
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "572073b3-d68a-45cb-9c60-cdf3c697b151",
"name": "Sticky Note - Intro",
"type": "n8n-nodes-base.stickyNote",
"position": [
3328,
9664
],
"parameters": {
"color": 6,
"width": 676,
"height": 720,
"content": "# \ud83d\udee1\ufe0f BotGuard - Why You Need This\n\n## \u26a0\ufe0f 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- \ud83e\udd16 Uses AI APIs (OpenAI, Claude) - **costs money per message**\n- \ud83d\udcb0 Calls paid services - **drains your credits**\n- \ud83d\udd10 Accesses sensitive data - **security risk**\n- \ud83d\udcca Processes heavy workloads - **server overload**\n\n## \u2705 The Solution\n\n**BotGuard** protects your bot by:\n\n1\ufe0f\u20e3 **Whitelist Control** - Only allowed User IDs can use the bot\n2\ufe0f\u20e3 **Admin Alerts** - Get notified of unauthorized access attempts\n3\ufe0f\u20e3 **Flexible Messages** - Customize denied/success responses\n4\ufe0f\u20e3 **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\ud83d\udca1 **Modify messages** to suggest users request access, or keep it restricted - your choice!"
},
"typeVersion": 1
},
{
"id": "635277cb-fa42-4c8c-aaac-373132606208",
"name": "Sticky Note - Quick Start",
"type": "n8n-nodes-base.stickyNote",
"position": [
4064,
9664
],
"parameters": {
"color": 4,
"width": 520,
"height": 720,
"content": "# \ud83d\ude80 Quick Start\n\n## 1\ufe0f\u20e3 Configure Your Bot\nEdit **BotGuard Authorization** node:\n- Add your User ID to `AllowedUsers`\n- Add admin User IDs to `Administrators`\n\n## 2\ufe0f\u20e3 Get User IDs\n- User sends message \u2192 Gets denied\n- Check denied message for User ID\n- Copy ID and add to arrays\n\n## 3\ufe0f\u20e3 Test\n- Authorized user \u2192 Success message\n- Unauthorized user \u2192 Denied + Admin notification\n\n## \ud83d\udcca Flow Overview\n```\nTelegram \u2192 BotGuard \u2192 Check Auth\n\u251c\u2500 TRUE \u2192 Send Success\n\u2514\u2500 FALSE \u2192 Send Denied + Notify Admins\n```"
},
"typeVersion": 1
},
{
"id": "b321fe86-fbf9-4ec6-b7e5-d00735d951ef",
"name": "Sticky Note1",
"type": "n8n-nodes-base.stickyNote",
"position": [
2432,
9136
],
"parameters": {
"color": 5,
"width": 853,
"height": 1259,
"content": "# \ud83d\udee1\ufe0f BotGuard Authorization System\n\n## \ud83d\udcd6 Complete Documentation\n\nThis workflow implements Telegram bot authorization with multi-admin notification system.\n\n## \ud83d\udd11 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## \ud83d\udce5 How to Get User IDs\n\n1. User sends message to bot \u2192 Gets denied\n2. Denied message shows: `Your User ID: 123456789`\n3. Copy ID and add to arrays above\n\n## \ud83d\udd04 Export/Import\n\n**Export:** Workflow menu (\u22ee) \u2192 Download \u2192 Save JSON\n**Import:** New workflow \u2192 Menu (\u22ee) \u2192 Import from File \u2192 Configure Telegram credentials\n\n## \ud83d\udea8 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## \ud83c\udfaf 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 Authorization",
"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 = '\u2705 <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 = '\u23f3 <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 = '\ud83d\udeab <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 = '\ud83d\udd14 <b>Unauthorized Access Attempt</b>\\n\\n<b>User Details:</b>\\n\u2022 Name: ' + userName + '\\n\u2022 User ID: <code>' + userId + '</code>\\n\u2022 Language: ' + languageCode + '\\n\u2022 Time: ' + currentTime + '\\n\u2022 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: '\u274c 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": "Check Authorization",
"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": "Send Success",
"type": "n8n-nodes-base.telegram",
"position": [
3984,
9152
],
"parameters": {
"text": "={{ $json.botGuard.authorizedMessage }}",
"chatId": "={{ $json.botGuard.chatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "a89c3bdf-8669-477d-a47b-0e8e8f1f6ed8",
"name": "Send Denied",
"type": "n8n-nodes-base.telegram",
"position": [
3984,
9328
],
"parameters": {
"text": "={{ $json.botGuard.userMessage }}",
"chatId": "={{ $json.botGuard.chatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "778d438c-d052-4a1a-a110-0f222f537bf9",
"name": "Check Admin Notify",
"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": "Prepare Admin Notifications",
"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
],
"parameters": {
"updates": [
"message"
],
"additionalFields": {}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
},
{
"id": "a9ad2dab-53e6-4381-a78c-7d1bb42e1b20",
"name": "Notify Admin",
"type": "n8n-nodes-base.telegram",
"position": [
4400,
9488
],
"parameters": {
"text": "={{ $json.adminMessage }}",
"chatId": "={{ $json.adminChatId }}",
"additionalFields": {
"parse_mode": "HTML"
}
},
"credentials": {
"telegramApi": {
"name": "<your credential>"
}
},
"typeVersion": 1.2
}
],
"connections": {
"Telegram Trigger": {
"main": [
[
{
"node": "BotGuard Authorization",
"type": "main",
"index": 0
}
]
]
},
"Check Admin Notify": {
"main": [
[
{
"node": "Prepare Admin Notifications",
"type": "main",
"index": 0
}
]
]
},
"Check Authorization": {
"main": [
[
{
"node": "Send Success",
"type": "main",
"index": 0
}
],
[
{
"node": "Send Denied",
"type": "main",
"index": 0
},
{
"node": "Check Admin Notify",
"type": "main",
"index": 0
}
]
]
},
"BotGuard Authorization": {
"main": [
[
{
"node": "Check Authorization",
"type": "main",
"index": 0
}
]
]
},
"Prepare Admin Notifications": {
"main": [
[
{
"node": "Notify Admin",
"type": "main",
"index": 0
}
]
]
}
}
}
Credentials you'll need
Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.
telegramApi
For the full experience including quality scoring and batch install features for each workflow upgrade to Pro
About this workflow
Ever noticed how most Telegram bot tutorials assume everyone can just... use your bot? No questions asked, no protection, nothing. That's fine for a simple "Hello World" bot, but the moment you connect AI APIs, paid services, or sensitive operations - you're in trouble. Anyone…
Source: https://n8n.io/workflows/9203/ — original creator credit. Request a take-down →
Related workflows
Workflows that share integrations, category, or trigger type with this one. All free to copy and import.
This workflow contains community nodes that are only compatible with the self-hosted version of n8n.
This template is ideal for users managing Telegram channels who want to automate the process of posting messages, including text and images, directly from an bot.
This template is for developers and automation specialists looking to create a Telegram bot that enables users to select items from a predefined list and save their choices to a Postgres database.
This workflow is for Telegram bot developers or marketers who want to verify user subscriptions to specific Telegram channels and optionally reward them with downloadable files.
This workflow is ideal for businesses or individuals who want to run Telegram-based giveaways that require users to subscribe to certain channels in order to participate.