{
  "active": true,
  "connections": {
    "Split In Batches": {
      "main": [
        [
          {
            "node": "Nome e telefone para validar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Nome e telefone para validar": {
      "main": [
        [
          {
            "node": "Formatando Nome e Telefone",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Formatando Nome e Telefone": {
      "main": [
        [
          {
            "node": "Cadastrando na Audi\u00eancia",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Webhook": {
      "main": [
        [
          {
            "node": "Google Sheets1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Cadastrando na Audi\u00eancia": {
      "main": [
        [
          {
            "node": "enviar fluxo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "telefone vazio": {
      "main": [
        [],
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets3": {
      "main": [
        [
          {
            "node": "telefone vazio1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "telefone vazio1": {
      "main": [
        [
          {
            "node": "telefone vazio2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "telefone vazio2": {
      "main": [
        [],
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "Google Sheets4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets4": {
      "main": [
        [
          {
            "node": "telefone vazio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "enviar fluxo": {
      "main": [
        [
          {
            "node": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2023-12-05T23:13:44.286Z",
  "id": "Cjy4Wuqs1Wuv6NuL",
  "meta": null,
  "name": "Julia",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o",
          "mode": "list",
          "cachedResultName": "BOT-JULIA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 448379726,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726"
        },
        "options": {
          "columnsToWatch": [
            "NOME"
          ]
        }
      },
      "id": "22562cb6-ea0a-4ef2-91ba-3c93519ca3e1",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        160,
        480
      ],
      "credentials": {
        "googleSheetsTriggerOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "0bcecce3-fba6-4818-92c4-d508ba1437b8",
      "name": "Split In Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        900,
        500
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
        },
        "sheetName": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/docs\\.google\\.com/spreadsheets\\/d\\/[0-9a-zA-Z\\-_]+\\/edit\\#gid=([0-9]+)"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "TELEFONE FORMATADO": "={{ $json.whatsapp }}",
            "TELEFONE": "={{ $('telefone vazio').item.json.TELEFONE }}"
          },
          "matchingColumns": [
            "TELEFONE"
          ],
          "schema": [
            {
              "id": "TELEFONE FORMATADO",
              "displayName": "TELEFONE FORMATADO",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "TELEFONE",
              "displayName": "TELEFONE",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "NOME",
              "displayName": "NOME",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": true
            }
          ]
        },
        "options": {
          "locationDefine": {
            "values": {
              "firstDataRow": "={{ $('telefone vazio').item.json.row_number }}"
            }
          }
        }
      },
      "id": "9bf406cf-53e8-4cff-aefd-6d3577deec54",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1700,
        460
      ],
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "https://conectawebhook.com.br/api/v1/webhook/subscriber/",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "phone",
              "value": "={{ $json.whatsapp }}"
            },
            {
              "name": "first_name",
              "value": "={{ $json.Nome }}"
            },
            {
              "name": "last_name",
              "value": "={{ $json.Sobrenome }}"
            }
          ]
        }
      },
      "name": "Cadastrando na Audi\u00eancia",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1700,
        660
      ],
      "id": "6c8ecee6-c51d-4dd0-9162-62990b9e51c4",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "=telefone",
              "value": "={{ $json.TELEFONE.toString() }}"
            },
            {
              "name": "nomeCompleto",
              "value": "={{ $json.NOME }}"
            }
          ]
        },
        "options": {}
      },
      "id": "6c3d079b-9dd3-4514-8923-6658a0914063",
      "name": "Nome e telefone para validar",
      "type": "n8n-nodes-base.set",
      "position": [
        1120,
        480
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "jsCode": "// Obter a string de nome completo do n\u00f3 anterior\nconst nomeCompleto = items[0].json.nomeCompleto;\n\n// Fun\u00e7\u00e3o para separar o nome completo em nome e sobrenome\nfunction separarNomeSobrenome(nomeCompleto) {\n  // Verificar se o nome completo \u00e9 uma string\n  if (typeof nomeCompleto !== 'string') {\n    throw new Error('O nome completo deve ser uma string.');\n  }\n\n  // Dividir o nome completo em palavras\n  const palavras = nomeCompleto.trim().split(' ');\n\n  // Verificar se h\u00e1 mais de uma palavra\n  if (palavras.length === 0) {\n    throw new Error('O nome completo deve conter pelo menos um nome.');\n  }\n\n  // Extrair o primeiro nome\n  const primeiroNome = palavras.shift();\n\n  // Extrair o sobrenome\n  const sobrenome = palavras.length > 0 ? palavras.join(' ') : '.';\n\n  // Formatar o nome e sobrenome com a primeira letra de cada palavra em mai\u00fascula\n  const nomeFormatado = formatarNome(primeiroNome);\n  const sobrenomeFormatado = formatarNome(sobrenome);\n\n  return {\n    nome: nomeFormatado,\n    sobrenome: sobrenomeFormatado\n  };\n}\n\nfunction formatarNome(nome) {\n  return nome\n    .toLowerCase()\n    .split(' ')\n    .map((palavra) => palavra.charAt(0).toUpperCase() + palavra.slice(1))\n    .join(' ');\n}\n\n// Separar o nome completo em nome e sobrenome\nconst resultado = separarNomeSobrenome(nomeCompleto);\n\nvar whatsapp = items[0].json.telefone.replace(/\\D/g, '');\nvar ddd = whatsapp.slice(2,4);\nvar ddi = whatsapp.charAt(0);\nvar ddx = whatsapp.slice(0,2);\nvar length = whatsapp.length;\nif (length >= 12){\n  if (ddi == '+'){\n    ddi = whatsapp.slice(0,3);\n    whatsapp = parseInt(whatsapp.slice(3)).toString();\n  } else {\n    if (ddx == '55'){\n      whatsapp = parseInt(whatsapp.slice(2)).toString();\n      ddi = \"+55\";\n    } else {\n      whatsapp = parseInt(whatsapp).toString();\n      ddi = 'n\u00e3o informado';\n    }\n  }\n} else {\n  whatsapp = parseInt(whatsapp).toString();\n  ddi = 'n\u00e3o informado';\n}\n\nddd = whatsapp.slice(0,2);\nwhatsapp = whatsapp.slice(2);\nif (ddd > 28){\n  whatsapp = whatsapp.slice(-8);\n} else {\n  whatsapp = '9'+whatsapp.slice(-8);\n}\nvar whatsapp = '+55'+ddd+whatsapp;\n\n// Armazenar o nome e sobrenome nos campos desejados\nreturn {\n  json: {\n    Nome: resultado.nome,\n    Sobrenome: resultado.sobrenome,\n    NomeCompleto: resultado.nome+' '+resultado.sobrenome,\n    whatsapp\n  }\n};\n"
      },
      "id": "a4dec782-de85-46a8-b42a-5dbc00d6ca37",
      "name": "Formatando Nome e Telefone",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1420,
        560
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "verificar-planilha-julia",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "cda78b44-5767-4d53-94af-3a24044f448c",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        -60,
        980
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
        },
        "sheetName": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/docs\\.google\\.com/spreadsheets\\/d\\/[0-9a-zA-Z\\-_]+\\/edit\\#gid=([0-9]+)"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "TELEFONE FORMATADO",
              "lookupValue": "={{ $json.body.telefone }}"
            }
          ]
        },
        "options": {}
      },
      "id": "378a8407-30b8-4ca5-b99b-eda57bb83440",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        140,
        980
      ],
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "maxTries": 5,
      "alwaysOutputData": true,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "=https://backend.botconversa.com.br/api/v1/webhook/subscriber/{{ $json[\"id\"] }}/send_flow/\n",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "flow",
              "value": "=302138"
            }
          ]
        }
      },
      "name": "enviar fluxo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1900,
        660
      ],
      "id": "a76f797d-c6ca-47e0-8736-3628f2141bd6",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "unit": "minutes"
      },
      "id": "5644d142-68de-4690-a748-a224343f5209",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        2120,
        660
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.TELEFONE }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "e68625e6-f383-4116-9e96-c871231de3b9",
      "name": "telefone vazio",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        540,
        480
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o",
          "mode": "list",
          "cachedResultName": "BOT-JULIA",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 448379726,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726"
        },
        "options": {
          "returnAllMatches": "returnAllMatches"
        }
      },
      "id": "0b410292-8edc-4e79-aecd-4baeb5c77149",
      "name": "Google Sheets3",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        260,
        800
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.TELEFONE }}",
              "operation": "isNotEmpty"
            }
          ]
        }
      },
      "id": "63e535fc-aa94-4684-9550-492b6e253b1e",
      "name": "telefone vazio1",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        440,
        800
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json['TELEFONE'] }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "91f4f781-5fbe-436d-b1b3-3fa23808e55a",
      "name": "telefone vazio2",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        660,
        780
      ]
    },
    {
      "parameters": {},
      "id": "3b19edc8-838d-45bc-8b95-756ae92e6db5",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        20,
        320
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/(?:drive|docs)\\.google\\.com(?:\\/.*|)\\/d\\/([0-9a-zA-Z\\-_]+)(?:\\/.*|)"
        },
        "sheetName": {
          "__rl": true,
          "value": "https://docs.google.com/spreadsheets/d/1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o/edit#gid=448379726",
          "mode": "url",
          "__regex": "https:\\/\\/docs\\.google\\.com/spreadsheets\\/d\\/[0-9a-zA-Z\\-_]+\\/edit\\#gid=([0-9]+)"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "TELEFONE FORMATADO"
            }
          ]
        },
        "options": {
          "returnAllMatches": "returnAllMatches"
        }
      },
      "id": "f8dd0867-77f0-4868-9589-dc3e9cc2850d",
      "name": "Google Sheets4",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        380,
        480
      ],
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": {
    "node:Google Sheets Trigger": {
      "documentId": "1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o",
      "sheetId": 448379726,
      "lastRevision": 18732,
      "lastRevisionLink": "https://docs.google.com/spreadsheets/export?id=1_PYgJ1kybEGr2-XK2rjuaWhzfHFgFppDaz0TnIT6b8o&revision=18732&exportFormat=xlsx",
      "lastIndexChecked": 252
    }
  },
  "tags": [],
  "triggerCount": 2,
  "updatedAt": "2024-01-18T18:33:08.000Z",
  "versionId": "b5d426e6-4a1f-45cf-94bb-a4a253a7df0e"
}