{
  "active": false,
  "connections": {
    "Google Sheets Trigger": {
      "main": [
        [
          {
            "node": "telefone vazio",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "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": "Wait",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait": {
      "main": [
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "telefone vazio": {
      "main": [
        [
          {
            "node": "Google Sheets2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Split In Batches",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "createdAt": "2023-12-05T23:16:20.951Z",
  "id": "9EYR2mFN9Y3CJOFi",
  "meta": null,
  "name": "Vini",
  "nodes": [
    {
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "documentId": {
          "__rl": true,
          "value": "1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc",
          "mode": "list",
          "cachedResultName": "BOT-VINI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1292052403,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit#gid=1292052403"
        },
        "options": {
          "columnsToWatch": [
            "TELEFONE"
          ]
        }
      },
      "id": "702f7c8a-a17c-43f9-aa9a-cf151ea2a455",
      "name": "Google Sheets Trigger",
      "type": "n8n-nodes-base.googleSheetsTrigger",
      "typeVersion": 1,
      "position": [
        -100,
        620
      ]
    },
    {
      "parameters": {
        "batchSize": 1,
        "options": {}
      },
      "id": "33d4b052-aab6-40ff-a01f-617bb8b9a3cf",
      "name": "Split In Batches",
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 2,
      "position": [
        460,
        640
      ]
    },
    {
      "parameters": {
        "operation": "update",
        "documentId": {
          "__rl": true,
          "value": "1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc",
          "mode": "list",
          "cachedResultName": "BOT-VINI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1292052403,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit#gid=1292052403"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "TELEFONE": "={{ $('Split In Batches').item.json.TELEFONE }}",
            "TELEFONE FORMATADO": "={{ $json.whatsapp }}"
          },
          "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": "={{ $('Split In Batches').item.json.row_number }}"
            }
          }
        }
      },
      "id": "58323c9e-b19e-427a-a139-6687a9e8c6b6",
      "name": "Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        1180,
        540
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "https://backend.botconversa.com.br/swagger/?format=openapi",
        "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": [
        1180,
        740
      ],
      "id": "f9dd07a7-2881-4729-b734-11fbc0bc17f4",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "keepOnlySet": true,
        "values": {
          "string": [
            {
              "name": "telefone",
              "value": "={{ $json.TELEFONE }}"
            },
            {
              "name": "nomeCompleto",
              "value": "={{ $json.NOME }}"
            }
          ]
        },
        "options": {}
      },
      "id": "4018d9d9-a90e-45d3-9668-a36935e36a5d",
      "name": "Nome e telefone para validar",
      "type": "n8n-nodes-base.set",
      "position": [
        700,
        640
      ],
      "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": "fbd7a2f0-d259-4d7e-b2fd-9dbd309b73f1",
      "name": "Formatando Nome e Telefone",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        900,
        640
      ]
    },
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "vini-planilha",
        "responseMode": "lastNode",
        "options": {}
      },
      "id": "f7b120d4-c95a-4b0d-a2b0-4ab619ce0143",
      "name": "Webhook",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        240,
        1120
      ]
    },
    {
      "parameters": {
        "documentId": {
          "__rl": true,
          "value": "1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc",
          "mode": "list",
          "cachedResultName": "BOT-VINI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1292052403,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit#gid=1292052403"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "TELEFONE FORMATADO",
              "lookupValue": "={{ $json.body.telefone }}"
            }
          ]
        },
        "options": {}
      },
      "id": "c77ac935-1c19-43eb-b8aa-e5245ae0a968",
      "name": "Google Sheets1",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        460,
        1120
      ],
      "retryOnFail": true,
      "waitBetweenTries": 3000,
      "maxTries": 5,
      "alwaysOutputData": true,
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "authentication": "headerAuth",
        "requestMethod": "POST",
        "url": "=https://conectawebhook.com.br/api/v1/webhook/subscriber/{{ $json[\"id\"] }}/send_flow/",
        "options": {},
        "bodyParametersUi": {
          "parameter": [
            {
              "name": "flow",
              "value": "=212819"
            }
          ]
        }
      },
      "name": "enviar fluxo",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        1480,
        980
      ],
      "id": "2ca6e244-80e3-4a82-bda6-ffe596f561b5",
      "retryOnFail": true,
      "maxTries": 5,
      "waitBetweenTries": 5000,
      "credentials": {
        "httpHeaderAuth": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "unit": "seconds"
      },
      "id": "84e7c573-11d9-4617-a42d-f388b3f2d8a5",
      "name": "Wait",
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1,
      "position": [
        1660,
        740
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.TELEFONE }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "id": "a83ed0fd-e0dc-41bd-ad7b-8d3d2e647756",
      "name": "telefone vazio",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        180,
        620
      ]
    },
    {
      "parameters": {
        "operation": "delete",
        "documentId": {
          "__rl": true,
          "value": "1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc",
          "mode": "list",
          "cachedResultName": "BOT-VINI",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1292052403,
          "mode": "list",
          "cachedResultName": "n8n",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1oA43WpaWi8FF_PbnyPbpVN8b-bEFGCyAMr9BEBWVIAc/edit#gid=1292052403"
        },
        "startIndex": "={{ $json.row_number }}"
      },
      "id": "0ea437ba-15c3-40b8-b0d3-c591bf1547f6",
      "name": "Google Sheets2",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4,
      "position": [
        460,
        460
      ],
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      }
    }
  ],
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 0,
  "updatedAt": "2023-12-10T08:37:16.000Z",
  "versionId": "9526403c-e899-4c70-9073-dd13312f8ae4"
}