{
  "name": "HookCloud Partner API Simulator v35 - Templates e Saúde de Entregas",
  "nodes": [
    {
      "parameters": {
        "content": "# HookCloud Partner API Simulator — v21\n\nWorkflow atualizado com os endpoints atuais do Partner.\n\n## Configure no n8n\n- `HOOKCLOUD_PARTNER_API_KEY` = chave completa `hc_partner_live_...`\n- `HOOKCLOUD_API_URL` = opcional; padrão `https://api.hookcloud.app/functions/v1/swift-worker`\n- `HOOKCLOUD_PUBLISHABLE_KEY` = opcional; padrão já preenchido\n\nVocê também pode editar os nodes **Config** manualmente.\n\nExecute apenas o gatilho da chamada que deseja testar. As rotas de inativação alteram dados reais. O teste de envio Meta envia uma mensagem real.\n\n## Identificadores\nNo GET de instância, `INSTANCE_ID` é UUID. Não use o `external_customer_id` numérico nesse campo.",
        "height": 500,
        "width": 950
      },
      "id": "98306cd2-716d-475a-996d-29363a921ddb",
      "name": "Instruções v21",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1180,
        -360
      ]
    },
    {
      "parameters": {
        "content": "## Segurança\n\nA rota de token Meta devolve um segredo sensível. Use apenas no backend do partner.\n\nO n8n pode salvar entradas e saídas no histórico de execuções. Proteja o acesso ao workflow e ajuste a retenção de dados conforme sua política.\n\nEste arquivo foi sanitizado: nenhuma Partner API Key real foi mantida.",
        "height": 500,
        "width": 760
      },
      "id": "ba929d5a-d5e8-4703-a42a-381df6afec5f",
      "name": "Segurança",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -170,
        -360
      ]
    },
    {
      "parameters": {},
      "id": "439ab221-6e02-49e9-a3fc-7b2b58546f85",
      "name": "▶ 1. Criar ou atualizar cliente",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        220
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "93c95d9b-636e-43cb-9de6-bd0e92902625",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "2dfced16-15c0-4d36-bf23-c9b6e05e2092",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "4efccda6-eae3-4c71-9e1b-08727b6f9d58",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "87fda8a9-2970-4f4f-9bca-4e515f06f5a5",
              "name": "EXTERNAL_CUSTOMER_ID",
              "value": "56790",
              "type": "string"
            },
            {
              "id": "d54aee44-7b6d-4a89-876e-9a269be3c0ab",
              "name": "CUSTOMER_NAME",
              "value": "Clínica Mais Vida",
              "type": "string"
            },
            {
              "id": "55d2310f-6902-4453-bb5d-e12cda72d4da",
              "name": "CUSTOMER_EMAIL",
              "value": "contato@maisvida.com",
              "type": "string"
            },
            {
              "id": "97bae8c1-a56a-40c1-a523-4359ecba98f5",
              "name": "CUSTOMER_PHONE",
              "value": "5511999999999",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "ce48cc3a-2851-4e3e-8ee0-9bd7ceb22f35",
      "name": "Config - Cliente",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        220
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "upsert-partner-customer"
            },
            {
              "name": "external_customer_id",
              "value": "={{$json.EXTERNAL_CUSTOMER_ID}}"
            },
            {
              "name": "customer_name",
              "value": "={{$json.CUSTOMER_NAME}}"
            },
            {
              "name": "customer_email",
              "value": "={{$json.CUSTOMER_EMAIL}}"
            },
            {
              "name": "customer_phone",
              "value": "={{$json.CUSTOMER_PHONE}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "fb49deab-4f84-4efc-9151-6e9f7a4b254a",
      "name": "API - upsert-partner-customer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        220
      ],
      "notesInFlow": true,
      "notes": "Cria ou atualiza o cliente final pelo external_customer_id."
    },
    {
      "parameters": {},
      "id": "a3305125-4e32-4e9c-8a7a-d4edf53a6913",
      "name": "▶ 2. Criar instância e connect_url",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        540
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "facf1392-5ac1-4475-85b3-d32804b4bc1f",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "a6c1ff5e-5267-4147-bf7d-fc2e7ac355a8",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "9344b478-156d-4f34-a056-378096a85dfc",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "3640c6e9-1051-497b-b969-f6bb73702f34",
              "name": "EXTERNAL_CUSTOMER_ID",
              "value": "56790",
              "type": "string"
            },
            {
              "id": "ef63ff8d-a2f6-468b-aaa9-4e4425e9b069",
              "name": "INSTANCE_KEY",
              "value": "56790-whatsapp-principal",
              "type": "string"
            },
            {
              "id": "91324629-27b0-4273-ac4a-34f96134f2fb",
              "name": "INSTANCE_NAME",
              "value": "WhatsApp principal (apelido interno)",
              "type": "string"
            },
            {
              "id": "6ddefeb9-5778-4268-942a-8b745fd4ae7c",
              "name": "RETURN_URL",
              "value": "https://app.saasdoparceiro.com/integracoes/whatsapp",
              "type": "string"
            },
            {
              "id": "5b6a539f-15ad-48af-a226-99df0be6cf1c",
              "name": "CANCEL_URL",
              "value": "https://app.saasdoparceiro.com/integracoes/whatsapp",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "74796fbf-c506-45e8-95ef-06cacc09bf02",
      "name": "Config - Criar instancia",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        540
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "create-customer-instance"
            },
            {
              "name": "external_customer_id",
              "value": "={{$json.EXTERNAL_CUSTOMER_ID}}"
            },
            {
              "name": "instance_key",
              "value": "={{$json.INSTANCE_KEY}}"
            },
            {
              "name": "instance_name",
              "value": "={{$json.INSTANCE_NAME}}"
            },
            {
              "name": "create_connect_session",
              "value": "={{true}}"
            },
            {
              "name": "return_url",
              "value": "={{$json.RETURN_URL}}"
            },
            {
              "name": "cancel_url",
              "value": "={{$json.CANCEL_URL}}"
            },
            {
              "name": "success_url",
              "value": "https://partner-connect.hookcloud.app/connect/success"
            },
            {
              "name": "error_url",
              "value": "https://partner-connect.hookcloud.app/connect/error"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "ddb5a36e-3a46-481e-a93b-3ccfd1fac1fd",
      "name": "API - create-customer-instance",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        540
      ],
      "notesInFlow": true,
      "notes": "Cria/reutiliza uma instância e retorna connect_url. instance_name é apenas apelido interno; verified_name vem da Meta."
    },
    {
      "parameters": {},
      "id": "355d542b-0d96-48ad-a58f-92654a169ebd",
      "name": "▶ 3. Gerar reconnect",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        860
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "82fa3202-c613-4465-ae7f-92e70b0f16d1",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "04f23e41-1ed5-4969-868d-22db20726428",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "30bbaba2-8d4a-4787-8abc-8a7450304e26",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "853314c2-b754-4447-8731-826abd45f4d4",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            },
            {
              "id": "7a85e81e-bf72-4c24-8d61-1044862e922c",
              "name": "RETURN_URL",
              "value": "https://app.saasdoparceiro.com/integracoes/whatsapp",
              "type": "string"
            },
            {
              "id": "3e51f72d-5eac-4a94-a0ae-9c30b7104c5f",
              "name": "CANCEL_URL",
              "value": "https://app.saasdoparceiro.com/integracoes/whatsapp",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "6c4b7f9e-11e8-4e56-b7f1-ca0ed11523a8",
      "name": "Config - Reconnect",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        860
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "create-connect-session"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            },
            {
              "name": "mode",
              "value": "reconnect"
            },
            {
              "name": "return_url",
              "value": "={{$json.RETURN_URL}}"
            },
            {
              "name": "cancel_url",
              "value": "={{$json.CANCEL_URL}}"
            },
            {
              "name": "success_url",
              "value": "https://partner-connect.hookcloud.app/connect/success"
            },
            {
              "name": "error_url",
              "value": "https://partner-connect.hookcloud.app/connect/error"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "9e0f2a7a-ec77-4cf3-8dda-e912d1f907ed",
      "name": "API - create-connect-session",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        860
      ],
      "notesInFlow": true,
      "notes": "Gera uma nova sessão de conexão/reconnect para uma instância existente."
    },
    {
      "parameters": {},
      "id": "f53e6117-4b10-409e-ada5-7c6f67d972ec",
      "name": "▶ 4. Consultar instância (GET)",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        1180
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "9b5d0b2d-e6d4-49e2-ad85-afd0cc1fb7a3",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "2f0f2445-35dd-412b-985b-be8f2534aae9",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "667a56a5-5b9c-4228-a398-3b8852090dfd",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "49c6533a-def8-4af1-b5ee-6d53b6da05b2",
              "name": "INSTANCE_ID",
              "value": "",
              "type": "string"
            },
            {
              "id": "ed19faaf-c96b-4e3b-8c79-1d7299dff35f",
              "name": "INSTANCE_KEY",
              "value": "",
              "type": "string"
            },
            {
              "id": "7e3dbcb3-5492-4f1e-95dc-79495ceeea01",
              "name": "PHONE_NUMBER_ID",
              "value": "",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "9168795b-534f-4f10-9112-56ec94053b00",
      "name": "Config - Consultar instancia",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        1180
      ],
      "notes": "Preencha exatamente um identificador. INSTANCE_ID deve ser UUID; 56790 é external_customer_id e não é aceito como instance_id.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "jsCode": "const input = $input.first().json;\n\nconst instanceId = String(input.INSTANCE_ID ?? '').trim();\nconst instanceKey = String(input.INSTANCE_KEY ?? '').trim();\nconst phoneNumberId = String(input.PHONE_NUMBER_ID ?? '').trim();\n\nconst filled = [\n  instanceId ? 'INSTANCE_ID' : null,\n  instanceKey ? 'INSTANCE_KEY' : null,\n  phoneNumberId ? 'PHONE_NUMBER_ID' : null,\n].filter(Boolean);\n\nif (filled.length === 0) {\n  throw new Error('Preencha exatamente um identificador: INSTANCE_ID (UUID), INSTANCE_KEY ou PHONE_NUMBER_ID.');\n}\n\nif (filled.length > 1) {\n  throw new Error(`Preencha somente um identificador. Campos preenchidos: ${filled.join(', ')}`);\n}\n\nconst uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nif (instanceId && !uuidPattern.test(instanceId)) {\n  throw new Error(\n    `INSTANCE_ID inválido: \"${instanceId}\". Esse campo exige o UUID retornado por create-customer-instance. ` +\n    'Um valor como 56790 é external_customer_id; use INSTANCE_KEY (ex.: 56790-whatsapp1) ou PHONE_NUMBER_ID.'\n  );\n}\n\nconst identifierQuery = instanceId\n  ? `instance_id=${encodeURIComponent(instanceId)}`\n  : instanceKey\n    ? `instance_key=${encodeURIComponent(instanceKey)}`\n    : `phone_number_id=${encodeURIComponent(phoneNumberId)}`;\n\nreturn [{\n  json: {\n    ...input,\n    INSTANCE_ID: instanceId,\n    INSTANCE_KEY: instanceKey,\n    PHONE_NUMBER_ID: phoneNumberId,\n    IDENTIFIER_QUERY: identifierQuery,\n  },\n}];"
      },
      "id": "abb96810-3fbc-4ed7-81ba-cd67c8620f3e",
      "name": "Validar identificador da instancia",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -560,
        1180
      ],
      "notesInFlow": true,
      "notes": "Bloqueia external_customer_id no campo INSTANCE_ID e exige exatamente um identificador."
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=get-partner-instance&' + $json.IDENTIFIER_QUERY}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "c17cfdfc-f3ef-4473-b17f-fa2cc9814b2c",
      "name": "API - GET get-partner-instance",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -300,
        1180
      ],
      "notesInFlow": true,
      "notes": "GET sem body. Preencha somente um identificador: INSTANCE_ID, INSTANCE_KEY ou PHONE_NUMBER_ID. A resposta inclui verified_name, whatsapp_manager_url e status do callback."
    },
    {
      "parameters": {},
      "id": "4c084ca4-ac9d-421b-ace8-fb52a9cef75e",
      "name": "▶ 5. Atualizar dados oficiais da Meta",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        1500
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fdd11d91-85cd-4c0e-abf5-72d790e241b4",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "20caac74-00f6-45c8-a51b-9b76fb7a84f7",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "e0cf03e3-8578-4e81-bcc1-5e3c16ef28b8",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "91adc673-84c8-44eb-98ea-d8cac09228bf",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "6c235c84-9a70-4621-afd6-f977d1849d4f",
      "name": "Config - Refresh Meta",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        1500
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "refresh-partner-instance-meta"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "c04a6f0f-0bf1-4445-8c85-63acbffc73e5",
      "name": "API - refresh-partner-instance-meta",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        1500
      ],
      "notesInFlow": true,
      "notes": "Atualiza verified_name, display_phone_number, quality_rating, name_status e outros dados oficiais diretamente na Meta."
    },
    {
      "parameters": {},
      "id": "58b9f0a0-22ed-4df8-b79f-e47ae5e96f37",
      "name": "▶ 6. Atualizar nome interno",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        1820
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a3121aaf-0ea7-4c40-91ba-0264e7beba48",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "29efd91c-e710-4880-b200-4171660788bf",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "f4cdca2f-5a4d-4036-a7d0-394d941f39d5",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "bbe669e6-bd76-4d77-ac74-2527e0c0f3b3",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            },
            {
              "id": "85e1a1f1-d779-4fbd-a399-4aef059d748c",
              "name": "INSTANCE_NAME",
              "value": "Apelido interno no SaaS",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "716bb793-8b69-485c-a035-6af6fe129ee2",
      "name": "Config - Nome interno",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        1820
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "update-partner-instance-label"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            },
            {
              "name": "instance_name",
              "value": "={{$json.INSTANCE_NAME}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "e2352b4c-221c-438f-86b7-037dfb1a6c93",
      "name": "API - update-partner-instance-label",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        1820
      ],
      "notesInFlow": true,
      "notes": "Altera somente o apelido interno. Não altera o verified_name oficial da Meta."
    },
    {
      "parameters": {},
      "id": "e4c83e29-e87e-4743-8208-78f6ec78e0c3",
      "name": "▶ 7. Revelar token Meta da instância",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        2140
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3def8ab8-85d1-459e-ad9d-2827e19268db",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "3ad23c95-d9a5-4b64-998c-488ff7802300",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "b6a35c46-08b4-4598-84b8-4a07df542c78",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "f0339517-7d8f-48e8-9f2b-1237fd74c088",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "477d6236-21dd-4bd3-b705-31de964ade53",
      "name": "Config - Token Meta",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        2140
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "reveal-partner-instance-meta-token"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "3e099f3d-bd6a-4339-b72b-274e5e3ff46d",
      "name": "API - reveal-partner-instance-meta-token",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        2140
      ],
      "notesInFlow": true,
      "notes": "Retorna meta_access_token e send_message_url. Use somente no backend do partner; a execução do n8n pode registrar o token."
    },
    {
      "parameters": {},
      "id": "d55560c3-20ec-4dd7-ad3d-a68e8bf6d983",
      "name": "▶ 8. Revelar token e enviar texto via Meta",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        2460
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "ceffcfba-eca0-462f-9901-2de32528a45b",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "3c13b7a1-642b-40a2-8d46-9f766aea284a",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "b67eec76-0649-4eb4-bf08-3e5657593585",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "271d88ba-78d6-407e-abb1-6b00cf0fb21d",
              "name": "PHONE_NUMBER_ID",
              "value": "COLE_PHONE_NUMBER_ID_DA_META",
              "type": "string"
            },
            {
              "id": "198fcfe6-a7e7-43be-a536-d4cd38a2da57",
              "name": "TEST_RECIPIENT",
              "value": "5511999999999",
              "type": "string"
            },
            {
              "id": "b38fb221-b737-403d-9927-e084e7faddb0",
              "name": "TEST_MESSAGE",
              "value": "Olá! Esta é uma mensagem de teste do sistema do partner.",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "d7805087-10d7-48ed-812c-b6bb9cf3ca2c",
      "name": "Config - Envio direto Meta",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        2460
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "reveal-partner-instance-meta-token"
            },
            {
              "name": "phone_number_id",
              "value": "={{$json.PHONE_NUMBER_ID}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "ea16f693-7a37-4809-aced-e6fadef77823",
      "name": "API - obter token para envio",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        2460
      ],
      "notesInFlow": true,
      "notes": "Obtém o token Meta pelo phone_number_id antes do envio direto."
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.send_message_url}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.meta_access_token}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={{ { messaging_product: 'whatsapp', to: $('Config - Envio direto Meta').item.json.TEST_RECIPIENT, type: 'text', text: { body: $('Config - Envio direto Meta').item.json.TEST_MESSAGE } } }}",
        "options": {
          "timeout": 300000
        }
      },
      "id": "d8c163b4-de33-4ae3-959c-852a5d9ed90d",
      "name": "META - enviar mensagem de texto",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        20,
        2460
      ],
      "notesInFlow": true,
      "notes": "ATENÇÃO: envia uma mensagem real diretamente para a Meta Cloud API usando o token retornado pela HookCloud."
    },
    {
      "parameters": {},
      "id": "9cb6d0f7-dec0-4f7b-a519-3b183b3f8938",
      "name": "▶ 9. Inativar instância",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        2780
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "2349532a-8850-4051-8137-fbc5821f7ace",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "5b5ba182-a6b7-427c-8796-ff22904fc0ea",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "211cc0d8-a465-43f2-80af-91d52eaff3cf",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "701c5f46-4025-4eb5-a4e7-baf73d2ffcfa",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            },
            {
              "id": "18c63026-81fa-4a4c-bf66-7ce6fee600b2",
              "name": "REASON",
              "value": "Cliente cancelou esta linha",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a7aca13d-2bcb-4cb8-bf57-88e1c9f9b9a8",
      "name": "Config - Inativar instancia",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        2780
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "deactivate-partner-instance"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            },
            {
              "name": "reason",
              "value": "={{$json.REASON}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "566a03de-d885-4711-8327-327a574e3873",
      "name": "API - deactivate-partner-instance",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        2780
      ],
      "notesInFlow": true,
      "notes": "AÇÃO REAL: remove o callback remoto do phone_number_id e só depois libera a instância."
    },
    {
      "parameters": {},
      "id": "232c6caf-d470-470c-9a0f-e94ceb907d5c",
      "name": "▶ 10. Inativar cliente inteiro",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        3100
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6a873b90-7b86-4866-acff-d21291a33bf9",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "7416fd2a-ddc1-47cb-80f0-d50fc284cbc1",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "ebff2723-f804-4f28-9798-0d5dffcef985",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "3e944b76-a434-4b90-91fd-4323f162bfb6",
              "name": "EXTERNAL_CUSTOMER_ID",
              "value": "56790",
              "type": "string"
            },
            {
              "id": "221df645-d970-4c5b-88fd-9f2d6f3efa19",
              "name": "REASON",
              "value": "Cliente cancelou assinatura no SaaS parceiro",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "e0210def-8fb4-4c06-b92e-9b308ad6a63c",
      "name": "Config - Inativar cliente",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        3100
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "deactivate-partner-customer"
            },
            {
              "name": "external_customer_id",
              "value": "={{$json.EXTERNAL_CUSTOMER_ID}}"
            },
            {
              "name": "reason",
              "value": "={{$json.REASON}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "b9b80433-56aa-4c76-9d9e-bbb2d3056cbd",
      "name": "API - deactivate-partner-customer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        3100
      ],
      "notesInFlow": true,
      "notes": "AÇÃO REAL: inativa o cliente e tenta remover os callbacks remotos de todas as instâncias."
    },
    {
      "parameters": {},
      "id": "fba9987b-1e73-4330-a376-344c22146038",
      "name": "▶ 11. Reativar cliente",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1180,
        3420
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "06ed6740-ca04-431d-a9da-93de119d2bfb",
              "name": "HOOKCLOUD_API_URL",
              "value": "={$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}",
              "type": "string"
            },
            {
              "id": "4e571049-e971-46b8-b44f-5760361d695c",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}",
              "type": "string"
            },
            {
              "id": "18f74001-5124-4148-adf6-5c7d909d8ee2",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "0e66d948-ece0-456f-8fb9-5876c36b6e09",
              "name": "EXTERNAL_CUSTOMER_ID",
              "value": "56790",
              "type": "string"
            },
            {
              "id": "7d1c4a54-80b4-4507-82e4-5e9fc8421467",
              "name": "REASON",
              "value": "Cliente voltou para o SaaS",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "babeb57a-6310-42a2-97bb-14ec0914c0d7",
      "name": "Config - Reativar cliente",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        3420
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "reactivate-partner-customer"
            },
            {
              "name": "external_customer_id",
              "value": "={{$json.EXTERNAL_CUSTOMER_ID}}"
            },
            {
              "name": "reason",
              "value": "={{$json.REASON}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "6be48c38-9b09-4ac2-9d11-fa66e1f91d99",
      "name": "API - reactivate-partner-customer",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -420,
        3420
      ],
      "notesInFlow": true,
      "notes": "Reativa o cadastro do cliente. Se necessário, gere um reconnect para as instâncias."
    },
    {
      "parameters": {
        "content": "## GET correto no domínio api.hookcloud.app\n\n`get-partner-instance` usa **GET**, sem body.\n\nEndpoint base:\n`https://api.hookcloud.app/functions/v1/swift-worker`\n\nQuery obrigatória:\n`route=get-partner-instance`\n\nPreencha exatamente um identificador:\n- `INSTANCE_ID`: UUID da instância retornado na criação\n- `INSTANCE_KEY`: ex. `56790-whatsapp1`\n- `PHONE_NUMBER_ID`: ID longo retornado pela Meta\n\n⚠️ `56790` sozinho é normalmente `external_customer_id`, não `instance_id`.\n\nExemplo correto:\n`?route=get-partner-instance&instance_key=56790-whatsapp1`\n\nA resposta inclui `whatsapp_manager_url`, `verified_name`, IDs Meta, estado do callback e uso de slot.",
        "height": 430,
        "width": 720
      },
      "id": "34539132-f00c-47f2-853d-d53bfa58b7b3",
      "name": "GET correto",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        20,
        1120
      ]
    },
    {
      "parameters": {
        "content": "## Envio direto pela Meta\n\n1. O webhook do partner recebe `metadata.phone_number_id`.\n2. O backend chama `reveal-partner-instance-meta-token`.\n3. Usa `meta_access_token` e `send_message_url` para responder direto pela Meta.\n\nO cliente final não vê o token. A HookCloud não fica no caminho de cada mensagem.",
        "height": 430,
        "width": 760
      },
      "id": "778fa4b6-8758-434f-b114-f3c1bba0f4b8",
      "name": "Fluxo envio Meta",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        520,
        2350
      ]
    },
    {
      "parameters": {
        "content": "# v35 — Templates Meta e Saúde de Entregas\n\nNovas rotas:\n- listar/consultar templates do cache HookCloud\n- solicitar refresh controlado da Graph API\n- consultar status do sync\n- reportar falhas 131049 e 131042\n- reportar status de entrega\n- consultar saúde e pesquisar eventos\n\n**Atenção:** o refresh é enfileirado e tem rate limit por WABA. Para falha síncrona sem waMID, use `CLIENT_MESSAGE_ID`. Não envie telefone em texto puro; prefira `RECIPIENT_HASH`.",
        "height": 580,
        "width": 1000
      },
      "id": "e925fb37-f1f2-46f0-b46f-c1775fa13d47",
      "name": "Instruções v35 - Templates e Entregas",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1200,
        3880
      ]
    },
    {
      "parameters": {},
      "id": "c69288f7-a730-44dc-8ecf-a8d0072fd04e",
      "name": "▶ 12. Listar templates aprovados",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        4300
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a83f9ea3-ce26-440f-8f63-f77846998459",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "e5f5e05e-7480-4518-b4aa-11097752ed91",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "2117f892-5d39-43d6-af37-70bc50c84d30",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "d1e741b4-7ae7-4b93-9337-7a0b38ed4e2c",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            },
            {
              "id": "4ea4d8a0-887a-44ca-98a9-bf9be7fc0887",
              "name": "STATUS",
              "value": "APPROVED",
              "type": "string"
            },
            {
              "id": "e8d65b0a-9fdd-4429-bfd6-34ab11fe6ae2",
              "name": "SENDABLE_ONLY",
              "value": true,
              "type": "boolean"
            }
          ]
        },
        "options": {}
      },
      "id": "fbc34077-5775-4c82-b9f6-93e67865e08a",
      "name": "Config - Listar templates aprovados",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        4300
      ],
      "notes": "Retorna components, parameter_schema, status, qualidade e sendable.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=list-partner-meta-templates&instance_id=' + encodeURIComponent($json.INSTANCE_ID) + '&status=' + encodeURIComponent($json.STATUS) + '&sendable_only=' + String($json.SENDABLE_ONLY) + '&page=1&page_size=50'}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "2b6c9f29-744c-4568-98bb-95af11fdb73f",
      "name": "API - list-partner-meta-templates",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        4300
      ],
      "notes": "GET do cache HookCloud. Esta chamada não consulta a Graph API.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "d5184ae3-5468-49fc-bb97-645820659451",
      "name": "▶ 13. Consultar um template",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        4630
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5847462e-e731-4805-9a37-2e1dfa8aa457",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "42f8b821-b19d-4cc7-b040-346d0d0f5375",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "b617dcd7-8be8-4893-a582-6ff490ad0a5c",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "0d456950-b776-4da7-b7bc-991689064f02",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            },
            {
              "id": "f0b181d6-302d-47fc-ba6a-f130fea9d056",
              "name": "TEMPLATE_NAME",
              "value": "confirmacao_agendamento",
              "type": "string"
            },
            {
              "id": "149ea2ad-22a2-49fb-a888-f16671a38ac6",
              "name": "LANGUAGE",
              "value": "pt_BR",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "560ae731-26be-4b13-8685-c996f7c45abe",
      "name": "Config - Consultar um template",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        4630
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=get-partner-meta-template&instance_id=' + encodeURIComponent($json.INSTANCE_ID) + '&template_name=' + encodeURIComponent($json.TEMPLATE_NAME) + '&language=' + encodeURIComponent($json.LANGUAGE)}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "9ef9db6d-00da-4875-8f25-da45b78ae391",
      "name": "API - get-partner-meta-template",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        4630
      ],
      "notes": "GET detalhado de um template no catálogo HookCloud.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "8134ac87-33e7-4664-9158-6c6261daa7c9",
      "name": "▶ 14. Atualizar catálogo de templates",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        4960
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "4b09794a-0d27-4326-b9eb-598fd3e08fa5",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "c171aa22-5188-435c-ae13-e51ee7c5b8f3",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "3a704ae0-0907-455a-9855-0e5a04588d50",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "471ac709-9549-45ec-83ea-604659337ef5",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "a991f70e-44e1-4d86-b597-a952cd9c6f32",
      "name": "Config - Atualizar catálogo de templates",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        4960
      ],
      "notes": "Não execute repetidamente. O padrão permite um refresh manual por WABA a cada 5 minutos.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "options": {
          "timeout": 300000
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "refresh-partner-meta-templates"
            },
            {
              "name": "instance_id",
              "value": "={{$json.INSTANCE_ID}}"
            }
          ]
        }
      },
      "id": "99777b6f-cc97-4268-ae94-94521ac1387d",
      "name": "API - refresh-partner-meta-templates",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        4960
      ],
      "notes": "Retorna 202. O GET da Graph acontece em background com rate limit e coalescing.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "4a95b0a2-9ad1-4347-8131-647f04b3ba63",
      "name": "▶ 15. Consultar sync de templates",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        5290
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "767b11db-2a3c-47f4-b321-e2beb5c054b8",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "9461a704-e374-4527-a77a-5c69f164dd42",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "d423d2f2-e6ee-4c5b-8b7e-bf6b64789470",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "03030511-eb21-4767-830d-5063494d0dff",
              "name": "INSTANCE_ID",
              "value": "COLE_UUID_DA_INSTANCIA",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "fd87f851-efc2-42b3-bd32-e73588d8f814",
      "name": "Config - Consultar sync de templates",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        5290
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=get-partner-meta-template-sync&instance_id=' + encodeURIComponent($json.INSTANCE_ID)}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "c71e0fbe-8841-424e-a1e7-68d137c1ef98",
      "name": "API - get-partner-meta-template-sync",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        5290
      ]
    },
    {
      "parameters": {},
      "id": "58dcad99-9227-49a7-8297-cb553fb73201",
      "name": "▶ 16. Reportar erro 131049",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        5620
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "63e59426-7c36-4a2b-b284-85b4b252c718",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "ee6c02b1-90ca-4fc7-b596-d8f1d28ca2af",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "d3c64f15-0f68-4de3-81eb-7d2468546672",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "81a38b61-3e80-4d78-b332-fabcf82b7898",
              "name": "PHONE_NUMBER_ID",
              "value": "COLE_PHONE_NUMBER_ID",
              "type": "string"
            },
            {
              "id": "be17e4a2-dc14-4c1f-8d8a-cec32a225f51",
              "name": "MESSAGE_ID",
              "value": "wamid.xxxxx",
              "type": "string"
            },
            {
              "id": "ac5931ec-2c7a-4c45-8aa7-3dd8df7a35cf",
              "name": "CLIENT_MESSAGE_ID",
              "value": "",
              "type": "string"
            },
            {
              "id": "89297f65-e552-486c-9f48-8fb6f9a7bfdd",
              "name": "TEMPLATE_NAME",
              "value": "campanha_marketing",
              "type": "string"
            },
            {
              "id": "61202748-d233-4b65-af41-f2a08e765621",
              "name": "CAMPAIGN_ID",
              "value": "campanha_456",
              "type": "string"
            },
            {
              "id": "146347bf-4567-4c93-8d95-69a75c2d1ff5",
              "name": "RECIPIENT_HASH",
              "value": "COLE_HMAC_SHA256_HEX_64",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "74c429c2-ca6f-409d-800b-7afbf08d6990",
      "name": "Config - Reportar erro 131049",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        5620
      ],
      "notes": "Use MESSAGE_ID quando houver waMID. Para falha síncrona sem waMID, deixe MESSAGE_ID vazio e preencha CLIENT_MESSAGE_ID.",
      "notesInFlow": true
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "options": {
          "timeout": 300000
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "report-partner-message-delivery-failure"
            },
            {
              "name": "phone_number_id",
              "value": "={{$json.PHONE_NUMBER_ID}}"
            },
            {
              "name": "message_id",
              "value": "={{$json.MESSAGE_ID}}"
            },
            {
              "name": "client_message_id",
              "value": "={{$json.CLIENT_MESSAGE_ID}}"
            },
            {
              "name": "template_name",
              "value": "={{$json.TEMPLATE_NAME}}"
            },
            {
              "name": "template_language",
              "value": "pt_BR"
            },
            {
              "name": "campaign_id",
              "value": "={{$json.CAMPAIGN_ID}}"
            },
            {
              "name": "error_code",
              "value": 131049
            },
            {
              "name": "error_title",
              "value": "This message was not delivered to maintain a healthy ecosystem engagement"
            },
            {
              "name": "error_message",
              "value": "Mensagem não entregue pela proteção de engajamento saudável da Meta."
            },
            {
              "name": "recipient_hash",
              "value": "={{$json.RECIPIENT_HASH}}"
            },
            {
              "name": "occurred_at",
              "value": "={{$now.toISO()}}"
            }
          ]
        }
      },
      "id": "9d08e513-e494-4da2-8e94-1b30ce81be7b",
      "name": "API - reportar 131049",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        5620
      ],
      "notes": "Não faz retry imediato. A HookCloud classifica e cria alerta de engagement.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "e92b23ff-f8ba-4b6d-b237-bcb855de0b7d",
      "name": "▶ 17. Reportar erro 131042",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        5950
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "25ff96b5-d975-4cb4-9e77-c4223977afd8",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "101736af-76b7-4b51-aa1c-619f4383645e",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "d1f55649-70e6-4f48-8bfa-9614abe8b72e",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "18b9c849-a246-461e-8a43-8e6d5cc4ab11",
              "name": "PHONE_NUMBER_ID",
              "value": "COLE_PHONE_NUMBER_ID",
              "type": "string"
            },
            {
              "id": "0cf8f3b6-937a-433d-892a-562b4241fde3",
              "name": "CLIENT_MESSAGE_ID",
              "value": "msg_local_124",
              "type": "string"
            },
            {
              "id": "7b4c05e5-1c5f-4b12-ba39-ecd77f44f958",
              "name": "TEMPLATE_NAME",
              "value": "campanha_marketing",
              "type": "string"
            },
            {
              "id": "01dce740-87da-4f7c-9ff5-4bca5b6a2835",
              "name": "CAMPAIGN_ID",
              "value": "campanha_456",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "5abd4a8c-9731-43fc-b9f6-4360cb0c48e1",
      "name": "Config - Reportar erro 131042",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        5950
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "options": {
          "timeout": 300000
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "report-partner-message-delivery-failure"
            },
            {
              "name": "phone_number_id",
              "value": "={{$json.PHONE_NUMBER_ID}}"
            },
            {
              "name": "client_message_id",
              "value": "={{$json.CLIENT_MESSAGE_ID}}"
            },
            {
              "name": "template_name",
              "value": "={{$json.TEMPLATE_NAME}}"
            },
            {
              "name": "campaign_id",
              "value": "={{$json.CAMPAIGN_ID}}"
            },
            {
              "name": "error_code",
              "value": 131042
            },
            {
              "name": "error_title",
              "value": "Business eligibility payment issue"
            },
            {
              "name": "error_message",
              "value": "Problema no método de pagamento ou linha de crédito da WABA na Meta."
            },
            {
              "name": "occurred_at",
              "value": "={{$now.toISO()}}"
            }
          ]
        }
      },
      "id": "70ffbff6-29da-4618-8593-9bdaa139734c",
      "name": "API - reportar 131042",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        5950
      ],
      "notes": "Erro financeiro da Meta/WABA, não Stripe da HookCloud.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "84d4614a-a451-43c8-8e87-a1930fedc81f",
      "name": "▶ 18. Reportar status de entrega",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        6280
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "784fac4d-02dc-4d60-a07c-593ab96fdf20",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "6328435d-6e5a-4da0-9492-ca84c738ea41",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "a61f4ae5-ecae-42b3-8ac3-0f8e452f1ed4",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "067cdd34-72b0-47a1-b86d-2bed5804a784",
              "name": "PHONE_NUMBER_ID",
              "value": "COLE_PHONE_NUMBER_ID",
              "type": "string"
            },
            {
              "id": "55dc3c1d-de56-48cd-a6ec-5cda473a5487",
              "name": "MESSAGE_ID",
              "value": "wamid.xxxxx",
              "type": "string"
            },
            {
              "id": "251567cf-0239-46af-8790-7b52f8abee08",
              "name": "CLIENT_MESSAGE_ID",
              "value": "",
              "type": "string"
            },
            {
              "id": "18f283c0-4462-44a2-a28b-79f2dd7cd428",
              "name": "STATUS",
              "value": "delivered",
              "type": "string"
            },
            {
              "id": "760fafc4-afd3-49db-aaaf-01c148e4dbe8",
              "name": "TEMPLATE_NAME",
              "value": "confirmacao_agendamento",
              "type": "string"
            },
            {
              "id": "b85594f9-2397-4a76-98b3-c10f02749bbf",
              "name": "CAMPAIGN_ID",
              "value": "campanha_456",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "3c7455ec-3a56-456e-b42d-ea6b4e469c71",
      "name": "Config - Reportar status de entrega",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        6280
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{$json.HOOKCLOUD_API_URL}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            },
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "options": {
          "timeout": 300000
        },
        "bodyParameters": {
          "parameters": [
            {
              "name": "route",
              "value": "report-partner-message-status"
            },
            {
              "name": "phone_number_id",
              "value": "={{$json.PHONE_NUMBER_ID}}"
            },
            {
              "name": "message_id",
              "value": "={{$json.MESSAGE_ID}}"
            },
            {
              "name": "client_message_id",
              "value": "={{$json.CLIENT_MESSAGE_ID}}"
            },
            {
              "name": "status",
              "value": "={{$json.STATUS}}"
            },
            {
              "name": "template_name",
              "value": "={{$json.TEMPLATE_NAME}}"
            },
            {
              "name": "campaign_id",
              "value": "={{$json.CAMPAIGN_ID}}"
            },
            {
              "name": "occurred_at",
              "value": "={{$now.toISO()}}"
            }
          ]
        }
      },
      "id": "088e7221-108f-411b-b4d4-7248bd12c289",
      "name": "API - report-partner-message-status",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        6280
      ],
      "notes": "Status aceitos: accepted, sent, delivered, read, failed, deleted.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "8b354092-2815-44c4-80df-7b444e8a7e82",
      "name": "▶ 19. Consultar saúde de entregas",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        6610
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5d85edc6-3a82-4e92-8e9c-dbbe47f19219",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "2c543f9a-4250-4a75-8ac2-a6bfd66bd50a",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "5c7af93e-6508-476e-9554-3edd65ffb2e8",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "73826de8-0ea8-4424-8408-11871d6fc365",
              "name": "WINDOW_HOURS",
              "value": 24,
              "type": "number"
            }
          ]
        },
        "options": {}
      },
      "id": "cfd0ad52-ab76-488d-ba35-946a48db7bee",
      "name": "Config - Consultar saúde de entregas",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        6610
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=get-partner-delivery-health&window_hours=' + encodeURIComponent($json.WINDOW_HOURS)}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "6cfcbb2d-4f0e-404a-aa47-3bf6285247d2",
      "name": "API - get-partner-delivery-health",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        6610
      ],
      "notes": "Resumo, top errors/templates e alertas abertos.",
      "notesInFlow": true
    },
    {
      "parameters": {},
      "id": "f148c77c-f0e6-4441-9bd6-8fd5d35695dd",
      "name": "▶ 20. Pesquisar eventos de entrega",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -1100,
        6940
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "3c4c8a42-eb96-405d-99df-d8451c368014",
              "name": "HOOKCLOUD_API_URL",
              "value": "={{$env.HOOKCLOUD_API_URL || 'https://api.hookcloud.app/functions/v1/swift-worker'}}",
              "type": "string"
            },
            {
              "id": "b3bac79f-bb9a-43a3-a7c7-f7cbaa158aa5",
              "name": "HOOKCLOUD_PUBLISHABLE_KEY",
              "value": "={{$env.HOOKCLOUD_PUBLISHABLE_KEY || 'sb_publishable_vcEqaz4bqRNm3Oh7POfznA_SfWpNn5q'}}",
              "type": "string"
            },
            {
              "id": "f2e0da47-be50-4ad9-9aab-86ccdcdd3eca",
              "name": "HOOKCLOUD_PARTNER_API_KEY",
              "value": "={{$env.HOOKCLOUD_PARTNER_API_KEY || 'hc_partner_live_COLE_SUA_CHAVE_COMPLETA'}}",
              "type": "string"
            },
            {
              "id": "1383fc33-3617-4eae-b336-be29cc39c684",
              "name": "STATUS",
              "value": "failed",
              "type": "string"
            },
            {
              "id": "0e40483e-c680-47bf-a6c3-d8d193ec09c5",
              "name": "ERROR_CODE",
              "value": "131049",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "c199ed76-101f-4018-bbea-8ffd3f39a024",
      "name": "Config - Pesquisar eventos de entrega",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -850,
        6940
      ]
    },
    {
      "parameters": {
        "method": "GET",
        "url": "={{$json.HOOKCLOUD_API_URL + '?route=search-partner-delivery-events&status=' + encodeURIComponent($json.STATUS) + '&error_code=' + encodeURIComponent($json.ERROR_CODE) + '&page=1&page_size=50'}}",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$json.HOOKCLOUD_PUBLISHABLE_KEY}}"
            },
            {
              "name": "Authorization",
              "value": "={{'Bearer ' + $json.HOOKCLOUD_PARTNER_API_KEY}}"
            }
          ]
        },
        "options": {
          "timeout": 300000
        }
      },
      "id": "75d65a43-25f1-4522-a2d5-59a3755a1265",
      "name": "API - search-partner-delivery-events",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.4,
      "position": [
        -480,
        6940
      ],
      "notes": "Filtros adicionais podem ser incluídos na URL: template_name, campaign_id, date_from, date_to.",
      "notesInFlow": true
    }
  ],
  "pinData": {},
  "connections": {
    "▶ 1. Criar ou atualizar cliente": {
      "main": [
        [
          {
            "node": "Config - Cliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Cliente": {
      "main": [
        [
          {
            "node": "API - upsert-partner-customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 2. Criar instância e connect_url": {
      "main": [
        [
          {
            "node": "Config - Criar instancia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Criar instancia": {
      "main": [
        [
          {
            "node": "API - create-customer-instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 3. Gerar reconnect": {
      "main": [
        [
          {
            "node": "Config - Reconnect",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Reconnect": {
      "main": [
        [
          {
            "node": "API - create-connect-session",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 4. Consultar instância (GET)": {
      "main": [
        [
          {
            "node": "Config - Consultar instancia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Consultar instancia": {
      "main": [
        [
          {
            "node": "Validar identificador da instancia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 5. Atualizar dados oficiais da Meta": {
      "main": [
        [
          {
            "node": "Config - Refresh Meta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Refresh Meta": {
      "main": [
        [
          {
            "node": "API - refresh-partner-instance-meta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 6. Atualizar nome interno": {
      "main": [
        [
          {
            "node": "Config - Nome interno",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Nome interno": {
      "main": [
        [
          {
            "node": "API - update-partner-instance-label",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 7. Revelar token Meta da instância": {
      "main": [
        [
          {
            "node": "Config - Token Meta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Token Meta": {
      "main": [
        [
          {
            "node": "API - reveal-partner-instance-meta-token",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 8. Revelar token e enviar texto via Meta": {
      "main": [
        [
          {
            "node": "Config - Envio direto Meta",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Envio direto Meta": {
      "main": [
        [
          {
            "node": "API - obter token para envio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "API - obter token para envio": {
      "main": [
        [
          {
            "node": "META - enviar mensagem de texto",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 9. Inativar instância": {
      "main": [
        [
          {
            "node": "Config - Inativar instancia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Inativar instancia": {
      "main": [
        [
          {
            "node": "API - deactivate-partner-instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 10. Inativar cliente inteiro": {
      "main": [
        [
          {
            "node": "Config - Inativar cliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Inativar cliente": {
      "main": [
        [
          {
            "node": "API - deactivate-partner-customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 11. Reativar cliente": {
      "main": [
        [
          {
            "node": "Config - Reativar cliente",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Reativar cliente": {
      "main": [
        [
          {
            "node": "API - reactivate-partner-customer",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validar identificador da instancia": {
      "main": [
        [
          {
            "node": "API - GET get-partner-instance",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 12. Listar templates aprovados": {
      "main": [
        [
          {
            "node": "Config - Listar templates aprovados",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Listar templates aprovados": {
      "main": [
        [
          {
            "node": "API - list-partner-meta-templates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 13. Consultar um template": {
      "main": [
        [
          {
            "node": "Config - Consultar um template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Consultar um template": {
      "main": [
        [
          {
            "node": "API - get-partner-meta-template",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 14. Atualizar catálogo de templates": {
      "main": [
        [
          {
            "node": "Config - Atualizar catálogo de templates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Atualizar catálogo de templates": {
      "main": [
        [
          {
            "node": "API - refresh-partner-meta-templates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 15. Consultar sync de templates": {
      "main": [
        [
          {
            "node": "Config - Consultar sync de templates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Consultar sync de templates": {
      "main": [
        [
          {
            "node": "API - get-partner-meta-template-sync",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 16. Reportar erro 131049": {
      "main": [
        [
          {
            "node": "Config - Reportar erro 131049",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Reportar erro 131049": {
      "main": [
        [
          {
            "node": "API - reportar 131049",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 17. Reportar erro 131042": {
      "main": [
        [
          {
            "node": "Config - Reportar erro 131042",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Reportar erro 131042": {
      "main": [
        [
          {
            "node": "API - reportar 131042",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 18. Reportar status de entrega": {
      "main": [
        [
          {
            "node": "Config - Reportar status de entrega",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Reportar status de entrega": {
      "main": [
        [
          {
            "node": "API - report-partner-message-status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 19. Consultar saúde de entregas": {
      "main": [
        [
          {
            "node": "Config - Consultar saúde de entregas",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Consultar saúde de entregas": {
      "main": [
        [
          {
            "node": "API - get-partner-delivery-health",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "▶ 20. Pesquisar eventos de entrega": {
      "main": [
        [
          {
            "node": "Config - Pesquisar eventos de entrega",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config - Pesquisar eventos de entrega": {
      "main": [
        [
          {
            "node": "API - search-partner-delivery-events",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "a555ee73-1065-4390-b8bc-2b32c8778ae0",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "tags": []
}