{
  "name": "Nodbot - Telegram AI bot with human approval",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "message",
          "callback_query"
        ]
      },
      "id": "81d69734-ff38-4239-a7b6-425181b7ccd9",
      "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 ?? {};\nconst text = String(msg.text ?? '').trim();\nconst userId = msg.from?.id ?? msg.chat?.id;\nconst chatId = msg.chat?.id;\n\nif (!text) {\n  return [{ json: { action: 'ignore', reason: 'empty_or_non_text_message' } }];\n}\n\nconst risky = /(возврат|договор|претенз|персональн|паспорт|карта|оплат|юрид)/i.test(text);\nconst draft = `Черновик ответа: спасибо за обращение. Я проверю возможность переноса оплаты и вернусь с подтверждением.`;\nconst approvalId = `tg-ai:${chatId}:${msg.message_id}`;\n\nreturn [{\n  json: {\n    action: 'request_approval',\n    chat_id: chatId,\n    user_id: userId,\n    original_message_id: msg.message_id,\n    original_text: text,\n    risky,\n    approval_id: approvalId,\n    draft_text: draft,\n    moderator_text: `Нужен approve перед ответом пользователю\\n\\nВопрос: ${text}\\n\\n${draft}`,\n    callback_approve: `approve:${approvalId}`,\n    callback_reject: `reject:${approvalId}`\n  }\n}];"
      },
      "id": "de494319-81d4-41ce-9afb-02ef14e1166e",
      "name": "Prepare AI draft",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        280,
        260
      ]
    },
    {
      "parameters": {},
      "id": "77538680-543a-414b-87f9-50775dfd29b9",
      "name": "Send to moderator",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        560,
        260
      ]
    },
    {
      "parameters": {},
      "id": "4b7334e7-1b35-4891-b93a-e5eea89169fc",
      "name": "Approval gate",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        840,
        260
      ]
    },
    {
      "parameters": {},
      "id": "a2058e96-3244-4abe-89fe-1d42fe1c56e2",
      "name": "Send final answer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 2,
      "position": [
        1120,
        260
      ]
    }
  ],
  "connections": {
    "Telegram Trigger": {
      "main": [
        [
          {
            "node": "Prepare AI draft",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare AI draft": {
      "main": [
        [
          {
            "node": "Send to moderator",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send to moderator": {
      "main": [
        [
          {
            "node": "Approval gate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approval gate": {
      "main": [
        [
          {
            "node": "Send final answer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    "nodbot",
    "production",
    "template"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "b4806112-a7e0-46ab-83f8-70e0a182f72d",
  "meta": {
    "templateCredsSetupCompleted": false
  }
}