{
  "name": "Nodbot - Email → n8n → задача в Битрикс24: обработка входящих обращений",
  "nodes": [
    {
      "parameters": {
        "content": "Шаблон Nodbot: Email → n8n → задача в Битрикс24: обработка входящих обращений\n\n1) Импортируйте JSON в n8n.\n2) Замените TARGET_API_URL и TARGET_API_TOKEN на реальные значения или настройте credentials в n8n.\n3) Отправьте тестовый payload из статьи.\n4) В production добавьте реальные credentials, подпись webhook и идемпотентность.",
        "height": 240,
        "width": 460
      },
      "id": "fee1a568-9155-41f3-9d2a-de49e981f763",
      "name": "Как использовать шаблон",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -540,
        -260
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "bitrix24-task-from-email",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "810e08cb-39da-44cf-a203-12bfc597ea47",
      "name": "Webhook input",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -520,
        40
      ],
      "webhookId": "bitrix24-task-from-email"
    },
    {
      "parameters": {
        "jsCode": "const input = $json.body || $json;\nconst required = [\"from\", \"subject\"];\nconst missing = required.filter((field) => {\n  const value = input[field] ?? input[field.toLowerCase()] ?? input[field.toUpperCase()];\n  return value === undefined || value === null || value === '';\n});\nconst normalized = {\n  \"from\": input[\"from\"] ?? input[\"From\"] ?? input[\"FROM\"] ?? '',\n  \"subject\": input[\"subject\"] ?? input[\"Subject\"] ?? input[\"SUBJECT\"] ?? '',\n  \"body\": input[\"body\"] ?? input[\"Body\"] ?? input[\"BODY\"] ?? '',\n  \"priority\": input[\"priority\"] ?? input[\"Priority\"] ?? input[\"PRIORITY\"] ?? '',\n  \"deadline\": input[\"deadline\"] ?? input[\"Deadline\"] ?? input[\"DEADLINE\"] ?? '',\n  \"responsible_id\": input[\"responsible_id\"] ?? input[\"Responsible_Id\"] ?? input[\"RESPONSIBLE_ID\"] ?? '',\n};\nreturn [{\n  json: {\n    ok: missing.length === 0,\n    template: \"bitrix24-task-from-email\",\n    source: \"Email/Gmail\",\n    target: \"Битрикс24 task\",\n    event_id: input.event_id || input.lead_id || input.object_id || input.order_id || input.id || `${Date.now()}-${Math.random().toString(16).slice(2)}`,\n    received_at: new Date().toISOString(),\n    required_missing: missing,\n    normalized,\n    original: input\n  }\n}];"
      },
      "id": "f81bede1-27e8-437d-80b8-fb6220ca7f94",
      "name": "Normalize payload and validate",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -220,
        40
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $env.TARGET_API_URL || \"https://YOUR_SERVICE_API/replace-me\" }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{$env.TARGET_API_TOKEN || \"REPLACE_TARGET_TOKEN\"}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ JSON.stringify($json.normalized) }}",
        "options": {
          "timeout": 10000
        }
      },
      "id": "ddf0871c-4fdc-4b1f-a11f-97890100d3f4",
      "name": "Call external API - fill credentials",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        100,
        40
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "jsCode": "const api = $json;\nreturn [{ json: {\n  ok: true,\n  note: 'Template executed. Replace placeholder HTTP Request with real service credentials before production.',\n  result: api\n}}];"
      },
      "id": "d5ce84da-9aa9-4e61-90a2-8ac92770ad42",
      "name": "Build safe response",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        420,
        40
      ]
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ $json }}",
        "options": {}
      },
      "id": "047da33b-791d-400f-98cd-34e54d5ad82c",
      "name": "Respond to Webhook",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1.1,
      "position": [
        720,
        40
      ]
    }
  ],
  "connections": {
    "Webhook input": {
      "main": [
        [
          {
            "node": "Normalize payload and validate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize payload and validate": {
      "main": [
        [
          {
            "node": "Call external API - fill credentials",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Call external API - fill credentials": {
      "main": [
        [
          {
            "node": "Build safe response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build safe response": {
      "main": [
        [
          {
            "node": "Respond to Webhook",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {
    "Webhook input": [
      {
        "json": {
          "body": {
            "from": "client@example.ru",
            "subject": "Нужен счет",
            "body": "Просьба выставить счет по КП-55",
            "priority": "high"
          }
        }
      }
    ]
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [
    {
      "name": "nodbot"
    },
    {
      "name": "russia"
    },
    {
      "name": "template"
    }
  ],
  "triggerCount": 1,
  "updatedAt": "2026-05-30T00:00:00.000Z",
  "versionId": "96b435f3-c9f0-4eac-a02e-1371032f46b2",
  "meta": {
    "nodbot_phase13_generic_placeholder_cleaned": true
  },
  "notes": "Problem/Solution-мануал по созданию задач Битрикс24 из входящих писем через n8n: IMAP/Gmail trigger, парсинг темы и отправителя, дедупликация по Message-ID, SLA-дедлайн, вложения и task.add. Replace credentials, endpoints, IDs and business rules before production."
}