{
  "name": "bsf-bestpass",
  "nodes": [
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.emailReadImap",
      "typeVersion": 2.1,
      "position": [
        -704,
        128
      ],
      "id": "dafadcd4-cff3-4b4f-876b-1e58f462bd04",
      "name": "Email Trigger (IMAP)",
      "credentials": {
        "imap": {
          "id": "uwGmGockNXEsiVeS",
          "name": "IMAP account (bestpassbsf@bestpass.travel)"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "5dec74a6-d73a-4c65-b2f4-5f4abd78707a",
              "name": "output",
              "value": "={{ $('Email Trigger (IMAP)').all().map(item => item) }}",
              "type": "string"
            },
            {
              "id": "272f4899-f191-49ff-a147-b8005088d0cb",
              "name": "uazapi-instance-token",
              "value": "766308ad-5ca4-4c3d-8fd9-e09eec14ff2c",
              "type": "string"
            },
            {
              "id": "9d0947fb-7ca2-4c77-9b78-e36a52cfd8e2",
              "name": "uazapi-url",
              "value": "https://xbluedigital.uazapi.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -256,
        224
      ],
      "id": "df52c92f-f5fe-41b5-ab7b-9bcac87011e1",
      "name": "init-config",
      "notes": "TEMPLATE DESENVOLVIDO POR NOCODE STARTUP\nhttps://nocodestartup.io/\n\nFORMAÇÃO GESTOR DE AGENTES DE IA:\nhttps://nocodestartup.io/formacao-gestor-agentes-ia/"
    },
    {
      "parameters": {
        "jsCode": "// n8n Code Node (JavaScript)\n// Retorna apenas um output com a direção (\"received\" ou \"sent\")\n// e o email do remetente (from)\n\nconst j = items[0].json || {};\nconst myEmails = (j.myEmails || [\"bestpassbsf@bestpass.travel\"]).map(e => e.toLowerCase());\n\nconst from = (j.from || \"\").toLowerCase();\nconst to = (j.to || \"\").toLowerCase();\n\nlet result = \"unknown\";\n\n// Se o destinatário é meu e o remetente não é meu → RECEBIDO\nif (myEmails.some(e => to.includes(e)) && !myEmails.some(e => from.includes(e))) {\n  result = \"received\";\n}\n// Se o remetente é meu e o destinatário não é meu → ENVIADO\nelse if (myEmails.some(e => from.includes(e)) && !myEmails.some(e => to.includes(e))) {\n  result = \"sent\";\n}\n\nreturn [\n  {\n    json: {\n      direction: result,\n      sender: from   // email do remetente\n    }\n  }\n];\n"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -480,
        224
      ],
      "id": "0e0ae381-3e2d-4f8a-a9d6-afa94c94136b",
      "name": "getSender"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "73dff320-4a3f-470a-8858-464b46395f13",
              "leftValue": "={{ $('getSender').item.json.direction }}",
              "rightValue": "received",
              "operator": {
                "type": "string",
                "operation": "equals",
                "name": "filter.operator.equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -32,
        224
      ],
      "id": "b5d4653f-4b2d-422a-9014-3ac9b3370c12",
      "name": "e-mail Recebido"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $('getSender').item.json.sender }}",
                    "rightValue": "nao-responder@beneficiosocial.com.br",
                    "operator": {
                      "type": "string",
                      "operation": "equals"
                    },
                    "id": "76145106-6bb2-4d2a-b42f-d3e4f75ca04c"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "BSF"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "5291264d-d0bf-4c1d-b1d3-2d68628f2be0",
                    "leftValue": "={{ $('getSender').item.json.sender }}",
                    "rightValue": "nao-responder@beneficiosocial.com.br",
                    "operator": {
                      "type": "string",
                      "operation": "notEquals"
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Outro Remetente"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.3,
      "position": [
        192,
        128
      ],
      "id": "7550b653-8221-49ac-9096-1f5f675ef62a",
      "name": "Switch"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        496,
        48
      ],
      "id": "2f7884db-8aa9-4a5b-ac0f-ff560f3aab7a",
      "name": "OpenRouter Chat Model",
      "credentials": {
        "openRouterApi": {
          "id": "FRtnDk85rxHxQ8kO",
          "name": "OpenRouter account"
        }
      }
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.noOp",
      "typeVersion": 1,
      "position": [
        192,
        320
      ],
      "id": "963a78f1-fe18-4a6e-8f3b-37e1a0d59b22",
      "name": "No Operation, do nothing"
    },
    {
      "parameters": {
        "text": "={{ $json.output }}",
        "attributes": {
          "attributes": [
            {
              "name": "cpf",
              "description": "recebe o CPF do remetente do email",
              "required": true
            },
            {
              "name": "dt_nasc",
              "description": "recebe a data de nascimento do remetente do emal",
              "required": true
            },
            {
              "name": "email",
              "description": "recebe o e-mail do Operador",
              "required": true
            },
            {
              "name": "nome_cliente",
              "description": "Recebe o nome do operador",
              "required": true
            },
            {
              "name": "fone_cliente",
              "description": "Recebe o telefone do cliente",
              "required": true
            },
            {
              "name": "nro_protocolo",
              "description": "Recebe o numero do protocolo",
              "required": true
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        416,
        -176
      ],
      "id": "eafed9d0-2f5c-4c72-9758-a0b929dfdae3",
      "name": "BSF Information Extractor"
    },
    {
      "parameters": {
        "text": "={{ $('init-config').item.json.output }}",
        "attributes": {
          "attributes": [
            {
              "name": "cpf",
              "description": "Recebe o cpf do usuário e grava apenas os numeros",
              "required": true
            },
            {
              "name": "dt_nascimento",
              "description": "Recebe a data de nascimento do usuario e grava no formato DD/MM/YYYY",
              "required": true
            },
            {
              "name": "Nome",
              "description": "Recebe o nome do remetente",
              "required": true
            },
            {
              "name": "email",
              "description": "Recebe o email do remetente",
              "required": true
            },
            {
              "name": "telefone",
              "description": "Recebe o telefone do Cliente",
              "required": true
            }
          ]
        },
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "typeVersion": 1.2,
      "position": [
        416,
        336
      ],
      "id": "7cda3a96-0c82-4bd1-9af5-0123f76e1d3a",
      "name": "Cliente Information Extractor"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenRouter",
      "typeVersion": 1,
      "position": [
        496,
        560
      ],
      "id": "ccd0591a-a4c4-4ccf-beea-95db04b648cd",
      "name": "OpenRouter Chat Model1",
      "credentials": {
        "openRouterApi": {
          "id": "qgER3pahOxC1ZXYC",
          "name": "OpenRouter Lorenzo"
        }
      }
    },
    {
      "parameters": {
        "fromEmail": "Benefício Social Familiar <bestpassbsf@bestpass.travel>",
        "toEmail": "={{ $json.output.email }}",
        "subject": "🎉 Bem-vindo(a) à Bestpass Travel! 🌍✈️",
        "emailFormat": "text",
        "text": "=Prezado(a) {{ $json.output.nome_cliente }},\n\nÉ uma grande alegria informar que, através do Benefício Social Familiar, você agora faz parte da Bestpass Travel! 🎊✨\n \nAqui, você terá acesso a viagens com descontos exclusivos e experiências inesquecíveis criadas especialmente para nossos clientes 🌎💙\n \nPara concluirmos o seu cadastro e liberar o acesso à plataforma, pedimos que responda a este e-mail com as seguintes informações:\n\n📌 CPF:\n📌 Data de nascimento:\n\nAssim que recebermos seus dados, ativaremos seu acesso para que você possa começar a aproveitar todos os benefícios! 🚀\n\nMuito obrigado pela confiança e seja muito bem-vindo(a) à sua nova forma de viajar! 💫\n\nCom carinho,\nEquipe Bestpass Travel 💼✈️",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        768,
        -80
      ],
      "id": "2f05097d-f250-43d3-9c00-3a89bc49fccd",
      "name": "Envia email de solicitando info complementares",
      "webhookId": "c7a8d082-3d54-444a-bb0e-17d849b49235",
      "credentials": {
        "smtp": {
          "id": "OBhWiMiQMNzVJP6p",
          "name": "SMTP account"
        }
      }
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('init-config').item.json[\"uazapi-url\"] }}/send/text",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "token",
              "value": "={{ $('init-config').item.json[\"uazapi-instance-token\"] }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"number\": \"5511982084044\",\n  \"text\": \"*BSF*\\n \\n*PROTOCOLO*:{{ $('BSF Information Extractor').item.json.output.nro_protocolo }}\\n*CLIENTE*:{{ $('BSF Information Extractor').item.json.output.nome_cliente }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        992,
        -80
      ],
      "id": "89bd49e6-5a4b-42c7-837e-ea90d18e2e80",
      "name": "sendText Message Uazapi"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -704,
        320
      ],
      "id": "b7053f78-a11b-4ad6-a163-eb50428b72b0",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "options": {
          "delimiter": ";",
          "fileName": "={{ ($json['NOME COMPLETO'] || '').replace(/\\s+/g, '_') }}.csv"
        }
      },
      "type": "n8n-nodes-base.convertToFile",
      "typeVersion": 1.1,
      "position": [
        992,
        336
      ],
      "id": "baed43cb-7114-4fc7-b950-47c7bc0c7f10",
      "name": "Convert to File"
    },
    {
      "parameters": {
        "mode": "raw",
        "jsonOutput": "={\n  \"CPF\": \"{{ $json.output.cpf }}\",\n  \"NOME COMPLETO\": \"{{ $json.output.Nome }}\",\n  \"DTNASC\": \"{{ $json.output.dt_nascimento }}\",\n  \"EMAILCORPORATIVO\": \"{{ $json.output.email }}\",\n  \"TELEFONE\": \"\",\n  \"RAMAL\": \"\",\n  \"CELULAR\": \"<CELULAR>\",\n  \"SETOR\": \"\",\n  \"CARGO\": \"\",\n  \"CNPJMATRIZ\": \"18.679.897/0001-97\",\n  \"CNPJFILIAL\": \"\",\n  \"NOME DA UNIDADE\": \"\",\n  \"CENTROCUSTO\": \"\",\n  \"PATROCINIO\": \"\",\n  \"DESCONTOFOLHA\": \"\",\n  \"ATIVO\": \"\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        800,
        336
      ],
      "id": "7014f746-0b40-46b3-ac22-7875a9ff2599",
      "name": "Gera CSV"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "={{ $('init-config').item.json[\"uazapi-url\"] }}/send/text",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Accept",
              "value": "application/json"
            },
            {
              "name": "token",
              "value": "={{ $('init-config').item.json[\"uazapi-instance-token\"] }}"
            }
          ]
        },
        "sendBody": true,
        "specifyBody": "json",
        "jsonBody": "={\n  \"number\": \"5511982084044\",\n  \"text\": \"*BSF*\\n \\n*USER*:{{ $('Gera CSV').item.json.nome_completo }}\\n*E-MAIL*:{{ $('Gera CSV').item.json.email_corporativo }}\"\n}",
        "options": {}
      },
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.2,
      "position": [
        1232,
        336
      ],
      "id": "e9b9385d-10b2-4fa7-b8b1-163dbb5d145a",
      "name": "sendText Message Uazapi2"
    }
  ],
  "pinData": {
    "Email Trigger (IMAP)": [
      {
        "json": {
          "textHtml": "",
          "textPlain": "ï»¿\r\nEnviado do meu iPhone\r\n",
          "metadata": {
            "return-path": "<mahiumealves@gmail.com>",
            "received": "from mx.flockmail.com (localhost [127.0.0.1])\tby prod-use1-smtp-in1009.ops.titan.email (AQM) with ESMTP\tid 4fxYVM68wmz4vxK(208188318192357376);\tThu, 16 Apr 2026 23:04:12 +0000",
            "x-titan-identity": "208188318192357376,4fxYVM68wmz4vxK",
            "authentication-results": "mx.flockmail.com;\tspf=pass smtp.helo=mail-dl1-f46.google.com smtp.mailfrom=gmail.com;\tdmarc=pass reason=\"(p=none sp=quarantine dis=none)\" header.from=gmail.com",
            "received-spf": "pass (sender SPF authorized) identity=mailfrom; client-ip=74.125.82.46; helo=mail-dl1-f46.google.com; envelope-from=mahiumealves@gmail.com;",
            "dkim-signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com; s=20251104; t=1776380651; x=1776985451; darn=bestpass.travel;        h=to:date:message-id:subject:mime-version:from         :content-transfer-encoding:from:to:cc:subject:date:message-id         :reply-to;        bh=M5EPXh/NmYTZ1jIVt2g+Xe8BgelGouvhpluxxUCK9Z4=;        b=sWfr7R1I0MGJh2dqAqNr1zE9XdDZw/f3kvOfXqWL1ZJSGG9pJRlSEOikMqYWY5199z         qYN2SL32tsMQvD8KDGxFtORkky0Jr+HA8BUG28vvMxerSsDf9/xfxLi/uwzdFEDduY/t         Sn42PnNtZlkWn0x5zUwzkLDMiXx2ZbIrvChTUDgz5szgTnXJb2XSHff0H/pOXwrOVPs9         8D1TU/Y9uvNMSq/68neuFVmL4Klh9nnS8hh2Vu2Wqe1ovVIu5wcJSgAiUdIOCurvTEUr         uatt4PpTCdWB9VAqP9SxDM5WU4DC0f2gCG/dydYizWC+eAss5xQM/wX1H2GahmGPapZG         ZIxQ==",
            "x-google-dkim-signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;        d=1e100.net; s=20251104; t=1776380651; x=1776985451;        h=to:date:message-id:subject:mime-version:from         :content-transfer-encoding:x-gm-gg:x-gm-message-state:from:to:cc         :subject:date:message-id:reply-to;        bh=M5EPXh/NmYTZ1jIVt2g+Xe8BgelGouvhpluxxUCK9Z4=;        b=F7UjIED6EyeViozN2AkoxqyAKxziXsq3LU1fdqj4sUvj7UEbCg7S7gNgsjyvj6jjDi         Xd877q9unaHrMqhZVoJAHnU93LN/sdHUvxrNLkf3GDbXAF7WSlvvDN7VCQ57BfpY9CmQ         egr+SUSoOIguSaMiLS3T0zTykb7sbxSOaRmFZY3V+DbkqEyrM3NxGUZyWrpqbQblO4/n         M2qlU4d3IFv5DZkyQ7kfmvqJMZ+e1wHdCBypHSZxikGPS8rAUViE/w6XpfkQ+l2abOXK         oQYZKJVp4qeGnyG3nA8rsIV8RzqkS3t3/5OIth0yH2V6VGGpj3F5e6UiVl/xnhlKwpyh         PKvg==",
            "x-gm-message-state": "AOJu0YzuRzYAfl8RR68FLzB7qZQOqMzFU1HVVbK7AsSdPIWeGKw1qd4z\tyKwbzjyf+vuHnWx3QMB4vckLJ3/pUvIbMPfOh0e3KSV1RVEjkQaspNPHLCoHiw==",
            "x-gm-gg": "AeBDievynq6bFjUwnX7aSci5J59H04wex8BN2fhwRheVfVn5Md+Ihyeoa7VlPjG5o7a\tkOV3S/uh7/g8C6VD7FyB7jW/hr+e1g9p2xxd8dLeeZHdaJc50yc+p8pUnDApgENlRn3kbee3FiY\tk4PKHL9TUfPeFWfmhUwLHhhDm9vEfB9Wbggb7WCyFT/BNnL0WHk+puiFwBaofYCyHSfjlBRhrAn\t+t4XFMu687cTZIhCwOKpRXwU4S7tlBlxSIm2PFRcOb9ZvU+9xc3jZQ/l9JLXjLoeapdiTUBdwe6\tVYAO3q6r8MiV1T9op841YxHNMF73ei7tT7jIdz98AKQXT2HtMOLBTmeG682MTZ4CVbio2AfLXcM\tGyptaT6EQUgRzedo282masecGecg9ImRZOdowQ2nPWk1awWNQb50WXTl8Ys2INcUMv5MoRudzEJ\tZRLufI9WtWVZOup0z4YHl0bd2RNBtigOVkf/xIAFF7JZUwWOW66nlnP7A=",
            "x-received": "by 2002:a05:7022:12b:b0:128:d2f2:5cf8 with SMTP id a92af1059eb24-12c73fa8d16mr134847c88.34.1776380650775;        Thu, 16 Apr 2026 16:04:10 -0700 (PDT)",
            "content-type": "text/plain; charset=utf-8",
            "content-transfer-encoding": "quoted-printable",
            "mime-version": "1.0 (1.0)",
            "message-id": "<FA34B836-5EA0-4A91-8E62-69D7DEDDF8F1@gmail.com>",
            "x-mailer": "iPhone Mail (22H340)",
            "x-cmae-score": "0",
            "x-cmae-analysis": "v=2.4 cv=XcC5Co55 c=1 sm=1 tr=0 ts=69e16aeb\ta=nIc0VDSzMRGb8XsmHHV1bw==:117 a=uUA72fVxQoXn4bHo524f2g==:17\ta=IkcTkHD0fZMA:10 a=A5OVakUREuEA:10 a=x7bEGLp0ZPQA:10 a=P37sU9rFIOgA:10\ta=95EFz5htlIgA:10 a=wVq0vAYC1MsYWrz3A3YA:9 a=QEXdDO2ut3YA:10\ta=Uz9EnhuHEG25YKoRyM-d:22"
          },
          "attributes": {
            "uid": 146
          },
          "from": "Mahiume Alves <mahiumealves@gmail.com>",
          "subject": "CPF:568.134218/24. Data de nascimento 13/05/20005",
          "date": "Thu, 16 Apr 2026 20:03:58 -0300",
          "to": "bestpassbsf@bestpass.travel"
        },
        "pairedItem": {
          "item": 0
        }
      }
    ]
  },
  "connections": {
    "Email Trigger (IMAP)": {
      "main": [
        [
          {
            "node": "getSender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "init-config": {
      "main": [
        [
          {
            "node": "e-mail Recebido",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "getSender": {
      "main": [
        [
          {
            "node": "init-config",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e-mail Recebido": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "No Operation, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "BSF Information Extractor",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Cliente Information Extractor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "BSF Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "BSF Information Extractor": {
      "main": [
        [
          {
            "node": "Envia email de solicitando info complementares",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenRouter Chat Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Cliente Information Extractor",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Cliente Information Extractor": {
      "main": [
        [
          {
            "node": "Gera CSV",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Envia email de solicitando info complementares": {
      "main": [
        [
          {
            "node": "sendText Message Uazapi",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "getSender",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Gera CSV": {
      "main": [
        [
          {
            "node": "Convert to File",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Convert to File": {
      "main": [
        [
          {
            "node": "sendText Message Uazapi2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate"
  },
  "versionId": "9ac41c40-49cc-4a8f-8054-528fd2325301",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "21e7ff57946cbf869334fcf06dc46972ae1354730470591b3b54db42351e3ff1"
  },
  "id": "uLv0I2monULLATGO",
  "tags": []
}