{
  "name": "Nodbot - Telegram bot command router with roles",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message",
          "callback_query"
        ]
      },
      "id": "9741aadf-5411-48c1-8000-76c7aad4d442",
      "name": "Telegram Trigger",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 2,
      "position": [
        0,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const update = $json.message ? $json : ($json.body ?? $json);\nconst msg = update.message ?? update.callback_query?.message ?? {};\nconst text = String(update.callback_query?.data ?? msg.text ?? '').trim();\nconst userId = update.callback_query?.from?.id ?? msg.from?.id;\nconst allowedAdmins = new Set(($json.allowed_admins ?? []).map(String));\nconst [commandRaw, ...args] = text.split(/\\s+/);\nconst command = commandRaw.startsWith('/') ? commandRaw.split('@')[0].toLowerCase() : 'text';\nconst isAdmin = allowedAdmins.has(String(userId));\n\nconst routes = {\n  '/start': { action: 'send_public_help', requires_admin: false },\n  '/help': { action: 'send_public_help', requires_admin: false },\n  '/status': { action: 'check_order_status', requires_admin: false },\n  '/reload': { action: 'reload_cache', requires_admin: true },\n  '/broadcast': { action: 'broadcast_message', requires_admin: true }\n};\n\nconst route = routes[command] ?? { action: 'unknown_command', requires_admin: false };\nif (route.requires_admin && !isAdmin) {\n  return [{ json: { action: 'deny', reason: 'admin_required', command, user_id: userId } }];\n}\n\nreturn [{ json: { action: route.action, command, args, chat_id: msg.chat?.id, user_id: userId, is_admin: isAdmin } }];"
      },
      "id": "5404f8e1-2731-4139-8c57-b3ec485260d3",
      "name": "Route command and role",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "77e5b185-a902-4b30-956c-e12b6500c47d",
      "name": "Execute route API",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {
        "jsCode": "const update = $json.message ? $json : ($json.body ?? $json);\nconst msg = update.message ?? update.callback_query?.message ?? {};\nconst text = String(update.callback_query?.data ?? msg.text ?? '').trim();\nconst userId = update.callback_query?.from?.id ?? msg.from?.id;\nconst allowedAdmins = new Set(($json.allowed_admins ?? []).map(String));\nconst [commandRaw, ...args] = text.split(/\\s+/);\nconst command = commandRaw.startsWith('/') ? commandRaw.split('@')[0].toLowerCase() : 'text';\nconst isAdmin = allowedAdmins.has(String(userId));\n\nconst routes = {\n  '/start': { action: 'send_public_help', requires_admin: false },\n  '/help': { action: 'send_public_help', requires_admin: false },\n  '/status': { action: 'check_order_status', requires_admin: false },\n  '/reload': { action: 'reload_cache', requires_admin: true },\n  '/broadcast': { action: 'broadcast_message', requires_admin: true }\n};\n\nconst route = routes[command] ?? { action: 'unknown_command', requires_admin: false };\nif (route.requires_admin && !isAdmin) {\n  return [{ json: { action: 'deny', reason: 'admin_required', command, user_id: userId } }];\n}\n\nreturn [{ json: { action: route.action, command, args, chat_id: msg.chat?.id, user_id: userId, is_admin: isAdmin } }];"
      },
      "id": "826c653b-aa0c-4495-9931-98472bc284d8",
      "name": "Format safe reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "c72d8c54-27ee-4de7-b23f-ef05dadc3346",
      "name": "Send Telegram response",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Route command and role",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Route command and role": {
      "main": [
        [
          {
            "node": "Execute route API",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Execute route API": {
      "main": [
        [
          {
            "node": "Format safe reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format safe reply": {
      "main": [
        [
          {
            "node": "Send Telegram response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "210be1a3-556a-4ed2-9898-faa6f5f25d78",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}