{
  "active": false,
  "connections": {
    "recebe agendamento": {
      "main": [
        [
          {
            "node": "Trata campos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "novo": {
      "main": [
        [
          {
            "node": "Trata payload1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cria contato": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "att contact": {
      "main": [
        [
          {
            "node": "add tag2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "existe": {
      "main": [
        [
          {
            "node": "busca contato",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "busca contato": {
      "main": [
        [
          {
            "node": "If1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If": {
      "main": [
        [
          {
            "node": "existe",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "novo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "sem nono digito": {
      "main": [
        [
          {
            "node": "busca contato1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "busca contato1": {
      "main": [
        [
          {
            "node": "Trata payload2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If1": {
      "main": [
        [
          {
            "node": "sem nono digito",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Trata payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add tag": {
      "main": [
        [
          {
            "node": "envia fluxo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add tag1": {
      "main": [
        [
          {
            "node": "envia fluxo1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "add tag2": {
      "main": [
        [
          {
            "node": "envia fluxo3",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trata campos": {
      "main": [
        [
          {
            "node": "Formata Telefone1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Formata Telefone1": {
      "main": [
        [
          {
            "node": "Cria contato",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "att contact1": {
      "main": [
        [
          {
            "node": "add tag",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "att contact2": {
      "main": [
        [
          {
            "node": "add tag1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trata payload": {
      "main": [
        [
          {
            "node": "att contact1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trata payload1": {
      "main": [
        [
          {
            "node": "att contact",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Trata payload2": {
      "main": [
        [
          {
            "node": "att contact2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2026-03-02T08:43:39.160Z",
  "id": "s82MNZSHJPKFP2Ua",
  "isArchived": false,
  "meta": null,
  "name": "PRECALL",
  "nodes": [
    {
      "parameters": {
        "inputSource": "passthrough"
      },
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1.1,
      "position": [
        -4112,
        -224
      ],
      "id": "6b6bb3dd-9407-401f-baa7-ca280a7a9848",
      "name": "recebe agendamento"
    },
    {
      "parameters": {
        "jsCode": "const item = $input.first().json;\nconst startTime = new Date(item.agendamento.collection[0].start_time);\nconst now = new Date();\n\nconst h = 60 * 60 * 1000;\nconst morningOfDay = new Date(startTime);\nmorningOfDay.setUTCHours(11, 0, 0, 0); // 08:00 BRT\n\nif (morningOfDay >= startTime) {\n  morningOfDay.setTime(startTime.getTime() - 1 * h);\n}\n\nconst targets = {\n  delay_msg1: now,                                          // Imediata\n  delay_msg2: new Date(startTime.getTime() - 12 * h),      // 12h antes\n  delay_msg3: morningOfDay,                                 // Manh\u00e3 do dia (08h BRT)\n  delay_msg4: new Date(startTime.getTime() + 6 * h),       // 6h depois\n  delay_msg5: new Date(startTime.getTime() + 24 * h),      // 24h depois\n  delay_msg6: new Date(startTime.getTime() + 36 * h),      // 36h depois\n  delay_msg7: new Date(startTime.getTime() + 48 * h),      // 48h depois\n  delay_msg8: new Date(startTime.getTime() + 72 * h),      // 72h depois\n};\n\nconst result = {\n  telefone: item.telefone,\n  nome: item.nome,\n  start_time: startTime.toISOString(),\n  now_brt: new Date(now.getTime() - 3 * h).toISOString(),\n};\n\nfor (const [key, target] of Object.entries(targets)) {\n  const diffMinutes = Math.round((target.getTime() - now.getTime()) / 60000);\n  result[key] = Math.max(0, diffMinutes);\n}\n\nreturn [{ json: result }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -3888,
        -224
      ],
      "id": "2e1016a5-6a43-4d86-9997-f5af8dbdb3b8",
      "name": "Trata campos"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -2992,
        -32
      ],
      "id": "d038ca5e-738d-43a0-b3de-22d564f8f66c",
      "name": "novo"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/createSubscriber",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"phone\": \"{{\"+\"+ $json.numerosFormatados.comNonoDigito }}\",\n  \"whatsapp_phone\": \"{{\"+\"+ $json.numerosFormatados.comNonoDigito }}\",\n  \"has_opt_in_sms\": false,\n  \"has_opt_in_email\": false,\n  \"consent_phrase\": \"string\"\n} ",
        "options": {}
      },
      "id": "4e6b064f-e325-4ce8-86a9-44fd63a81450",
      "name": "Cria contato",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -3440,
        -224
      ],
      "retryOnFail": false,
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/setCustomFields",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {}
      },
      "id": "ee902802-553d-4f02-96a0-4e47d2d7f661",
      "name": "att contact",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2544,
        -32
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -2992,
        -320
      ],
      "id": "0f65a7d0-2b95-4db3-98bf-60ff4ac3271f",
      "name": "existe"
    },
    {
      "parameters": {
        "url": "=https://api.manychat.com/fb/subscriber/findByCustomField?field_id=13000729&field_value={{ $item(\"0\").$node[\"Formata Telefone1\"].json[\"numerosFormatados\"][\"comNonoDigito\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "67ef12eb-49fa-4896-ae33-41833a4f7dd5",
      "name": "busca contato",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2768,
        -320
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "4b47ac03-1259-4e8c-9e8e-22786f6bf427",
              "leftValue": "={{ $json.error.message }}",
              "rightValue": "This WhatsApp ID already exists",
              "operator": {
                "type": "string",
                "operation": "contains"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "71a62abd-ee0e-4f0e-a979-b833b7038390",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [
        -3216,
        -224
      ]
    },
    {
      "parameters": {
        "jsCode": "function formataTelefone(number) {\n    number = number.toString().replace(/[^\\d]/g, \"\");\n    let ddi = \"55\";\n    let ddd, telefone;\n\n    if (number.length === 13) {\n        ddi = number.substring(0, 2);\n        ddd = number.substring(2, 4);\n        telefone = number.substring(4);\n    } else if (number.length === 12) {\n        if (number.startsWith(\"55\")) {\n            ddd = number.substring(2, 4);\n            telefone = number.substring(4);\n        } else if (number.startsWith(\"0\")) {\n            return formataTelefone(number.substring(1));\n        } else {\n            return { comNonoDigito: number, semNonoDigito: number };\n        }\n    } else if (number.length === 11) {\n        ddd = number.substring(0, 2);\n        telefone = number.substring(2);\n    } else if (number.length === 10) {\n        ddd = number.substring(0, 2);\n        telefone = \"9\" + number.substring(2);\n    } else {\n        return { comNonoDigito: number, semNonoDigito: number };\n    }\n\n    let telefoneComNono = telefone.length === 8 ? \"9\" + telefone : telefone;\n    let telefoneSemNono = telefoneComNono.startsWith(\"9\") ? telefoneComNono.substring(1) : telefoneComNono;\n\n    return {\n        comNonoDigito: ddi + ddd + telefoneComNono,\n        semNonoDigito: ddi + ddd + telefoneSemNono\n    };\n}\n\nlet numerosFormatados = formataTelefone($input.all()[0].json[\"telefone\"]);\n\n$input.all()[0].json[\"numerosFormatados\"] = numerosFormatados\nreturn $input.all();\n"
      },
      "id": "e783b746-3b66-47f3-9d83-8f09b3bd2b33",
      "name": "Formata Telefone1",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        -3664,
        -224
      ]
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        -2320,
        -416
      ],
      "id": "e99659a2-7a41-4622-ac75-cabe885bc09d",
      "name": "sem nono digito"
    },
    {
      "parameters": {
        "url": "=https://api.manychat.com/fb/subscriber/findByCustomField?field_id=13000729&field_value={{$node[\"Formata Telefone1\"].json[\"numerosFormatados\"][\"semNonoDigito\"] }}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "options": {}
      },
      "id": "e7151c3d-d249-4131-b9bd-82de3156420f",
      "name": "busca contato1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2096,
        -416
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 1
          },
          "conditions": [
            {
              "id": "49a86e22-a9c4-4d6a-b179-2a4335dbb72e",
              "leftValue": "={{ $json.data }}",
              "rightValue": "",
              "operator": {
                "type": "array",
                "operation": "empty",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "f26850c4-ef4b-4114-ae2e-6b40c49ef0d5",
      "name": "If1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.1,
      "position": [
        -2544,
        -320
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/addTag",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $item(\"0\").$node[\"busca contato\"].json[\"data\"][\"0\"][\"id\"] }}"
            },
            {
              "name": "tag_id",
              "value": "82540130"
            }
          ]
        },
        "options": {}
      },
      "id": "aa566fb1-194b-4a40-9e62-10c2196627cd",
      "name": "add tag",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -1872,
        -224
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/addTag",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $json.data[0].id }}"
            },
            {
              "name": "tag_id",
              "value": "82540130"
            }
          ]
        },
        "options": {}
      },
      "id": "1be71663-1bee-4714-a873-a81b68ce95c7",
      "name": "add tag1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -1424,
        -416
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/addTag",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $node[\"Cria contato\"].json[\"data\"][\"id\"] }}"
            },
            {
              "name": "tag_id",
              "value": "82540130"
            }
          ]
        },
        "options": {}
      },
      "id": "33813d35-ec51-4dc6-8d97-e493acd232f0",
      "name": "add tag2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2320,
        -32
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/sending/sendFlow",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $node[\"busca contato1\"].json[\"data\"][\"0\"][\"id\"] }}"
            },
            {
              "name": "flow_ns",
              "value": "={{ $item(\"0\").$node[\"recebe agendamento\"].json[\"fluxo\"] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "c9f75bb1-4c06-4851-a40c-da039bb3bb8d",
      "name": "envia fluxo1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -1200,
        -416
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/sending/sendFlow",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $node[\"busca contato\"].json[\"data\"][\"0\"][\"id\"] }}"
            },
            {
              "name": "flow_ns",
              "value": "={{ $item(\"0\").$node[\"recebe agendamento\"].json[\"fluxo\"] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "84e99bfd-29bd-4e79-8af2-d58ff37e75cf",
      "name": "envia fluxo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -1648,
        -224
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/sending/sendFlow",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "subscriber_id",
              "value": "={{ $node[\"Cria contato\"].json[\"data\"][\"id\"] }}"
            },
            {
              "name": "flow_ns",
              "value": "={{ $item(\"0\").$node[\"recebe agendamento\"].json[\"fluxo\"] }}"
            }
          ]
        },
        "options": {}
      },
      "id": "55ea4065-1ea7-4f9c-88b8-c2bc3a446c6e",
      "name": "envia fluxo3",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2096,
        -32
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/setCustomFields",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {}
      },
      "id": "86dbfb3f-43b1-4030-afb3-e17244b593b5",
      "name": "att contact1",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -2096,
        -224
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.manychat.com/fb/subscriber/setCustomFields",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "Bearer 512512:8e9b483799228930ff553e82c3e11514"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ $json }}",
        "options": {}
      },
      "id": "2e04dbbf-177e-422f-a537-40b792bb8d85",
      "name": "att contact2",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        -1648,
        -416
      ],
      "retryOnFail": false,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "const subscriber_id = $item(0).$node[\"busca contato\"].json[\"data\"][0][\"id\"];\nconst tel = $node[\"Formata Telefone1\"].json[\"numerosFormatados\"][\"comNonoDigito\"];\nconst campos = $item(0).$node[\"Trata campos\"].json;\n\nconst v = (val) => {\n  const n = Number(val);\n  return isNaN(n) ? val : n;\n};\n\n// Converte start_time para BRT (UTC-3)\nconst startUtc = new Date(campos.start_time);\nconst startBrt = new Date(startUtc.getTime() - 3 * 60 * 60 * 1000);\n\nconst dia  = String(startBrt.getUTCDate()).padStart(2, \"0\");\nconst mes  = String(startBrt.getUTCMonth() + 1).padStart(2, \"0\");\nconst ano  = startBrt.getUTCFullYear();\nconst hora = String(startBrt.getUTCHours()).padStart(2, \"0\");\nconst min  = String(startBrt.getUTCMinutes()).padStart(2, \"0\");\n\nconst dataBrt = `${dia}/${mes}/${ano}`;\nconst horaBrt = `${hora}:${min}`;\n\nreturn [{\n  json: {\n    subscriber_id: subscriber_id,\n    fields: [\n      { field_id: 13000729, field_value: tel },\n      { field_id: 14333282, field_value: v(campos.delay_msg1) },\n      { field_id: 14322130, field_value: v(campos.delay_msg2) },\n      { field_id: 14333283, field_value: v(campos.delay_msg3) },\n      { field_id: 14333305, field_value: v(campos.delay_msg4) },\n      { field_id: 14333306, field_value: v(campos.delay_msg5) },\n      { field_id: 14333307, field_value: v(campos.delay_msg6) },\n      { field_id: 14333309, field_value: v(campos.delay_msg7) },\n      { field_id: 14333311, field_value: v(campos.delay_msg8) },\n      { field_id: 14316473, field_value: dataBrt },\n      { field_id: 14316474, field_value: horaBrt }\n    ]\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2320,
        -224
      ],
      "id": "5c4922c8-fcb7-4702-8340-44ed131b37fc",
      "name": "Trata payload"
    },
    {
      "parameters": {
        "jsCode": "const subscriber_id = $node[\"Cria contato\"].json[\"data\"][\"id\"];\nconst tel = $node[\"Formata Telefone1\"].json[\"numerosFormatados\"][\"comNonoDigito\"];\nconst campos = $item(0).$node[\"Trata campos\"].json;\n\nconst v = (val) => {\n  const n = Number(val);\n  return isNaN(n) ? val : n;\n};\n\n// Converte start_time para BRT (UTC-3)\nconst startUtc = new Date(campos.start_time);\nconst startBrt = new Date(startUtc.getTime() - 3 * 60 * 60 * 1000);\n\nconst dia  = String(startBrt.getUTCDate()).padStart(2, \"0\");\nconst mes  = String(startBrt.getUTCMonth() + 1).padStart(2, \"0\");\nconst ano  = startBrt.getUTCFullYear();\nconst hora = String(startBrt.getUTCHours()).padStart(2, \"0\");\nconst min  = String(startBrt.getUTCMinutes()).padStart(2, \"0\");\n\nconst dataBrt = `${dia}/${mes}/${ano}`;\nconst horaBrt = `${hora}:${min}`;\n\nreturn [{\n  json: {\n    subscriber_id: subscriber_id,\n    fields: [\n      { field_id: 13000729, field_value: tel },\n      { field_id: 14333282, field_value: v(campos.delay_msg1) },\n      { field_id: 14322130, field_value: v(campos.delay_msg2) },\n      { field_id: 14333283, field_value: v(campos.delay_msg3) },\n      { field_id: 14333305, field_value: v(campos.delay_msg4) },\n      { field_id: 14333306, field_value: v(campos.delay_msg5) },\n      { field_id: 14333307, field_value: v(campos.delay_msg6) },\n      { field_id: 14333309, field_value: v(campos.delay_msg7) },\n      { field_id: 14333311, field_value: v(campos.delay_msg8) },\n      { field_id: 14316473, field_value: dataBrt },\n      { field_id: 14316474, field_value: horaBrt }\n    ]\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -2768,
        -32
      ],
      "id": "f607b90d-4173-4520-9503-b7832540c3e3",
      "name": "Trata payload1"
    },
    {
      "parameters": {
        "jsCode": "const subscriber_id = $item(0).$node[\"busca contato1\"].json[\"data\"][0][\"id\"];\nconst tel = $node[\"Formata Telefone1\"].json[\"numerosFormatados\"][\"semNonoDigito\"];\nconst campos = $item(0).$node[\"Trata campos\"].json;\n\nconst v = (val) => {\n  const n = Number(val);\n  return isNaN(n) ? val : n;\n};\n\n// Converte start_time para BRT (UTC-3)\nconst startUtc = new Date(campos.start_time);\nconst startBrt = new Date(startUtc.getTime() - 3 * 60 * 60 * 1000);\n\nconst dia  = String(startBrt.getUTCDate()).padStart(2, \"0\");\nconst mes  = String(startBrt.getUTCMonth() + 1).padStart(2, \"0\");\nconst ano  = startBrt.getUTCFullYear();\nconst hora = String(startBrt.getUTCHours()).padStart(2, \"0\");\nconst min  = String(startBrt.getUTCMinutes()).padStart(2, \"0\");\n\nconst dataBrt = `${dia}/${mes}/${ano}`;\nconst horaBrt = `${hora}:${min}`;\n\nreturn [{\n  json: {\n    subscriber_id: subscriber_id,\n    fields: [\n      { field_id: 13000729, field_value: tel },\n      { field_id: 14333282, field_value: v(campos.delay_msg1) },\n      { field_id: 14322130, field_value: v(campos.delay_msg2) },\n      { field_id: 14333283, field_value: v(campos.delay_msg3) },\n      { field_id: 14333305, field_value: v(campos.delay_msg4) },\n      { field_id: 14333306, field_value: v(campos.delay_msg5) },\n      { field_id: 14333307, field_value: v(campos.delay_msg6) },\n      { field_id: 14333309, field_value: v(campos.delay_msg7) },\n      { field_id: 14333311, field_value: v(campos.delay_msg8) },\n      { field_id: 14316473, field_value: dataBrt },\n      { field_id: 14316474, field_value: horaBrt }\n    ]\n  }\n}];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -1872,
        -416
      ],
      "id": "dce08e3e-0938-4fbd-b12a-d713a3dfdf50",
      "name": "Trata payload2"
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "shared": [
    {
      "updatedAt": "2026-03-02T08:43:39.160Z",
      "createdAt": "2026-03-02T08:43:39.160Z",
      "role": "workflow:owner",
      "workflowId": "s82MNZSHJPKFP2Ua",
      "projectId": "AxNpta0sA2v4gJ2a"
    }
  ],
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2026-03-14T04:40:46.151Z",
  "versionId": "5d1a9a0a-078d-40b4-9dff-325d8e7519a2"
}