{
  "name": "Atendimento WhatsApp - Cortinas Bresser",
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "whatsapp",
        "responseMode": "responseNode",
        "options": {}
      },
      "id": "webhook-whatsapp",
      "name": "Webhook WhatsApp",
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 1,
      "position": [
        250,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json.body.event}}",
              "operation": "equals",
              "value2": "messages.upsert"
            }
          ]
        }
      },
      "id": "filter-messages",
      "name": "Filtrar Mensagens",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        450,
        300
      ]
    },
    {
      "parameters": {
        "functionCode": "// Extrair dados da mensagem\nconst message = $input.item.json.body.data;\nconst from = message.key.remoteJid;\nconst text = message.message?.conversation || \n             message.message?.extendedTextMessage?.text || '';\n\n// Detectar inten\u00e7\u00e3o\nlet intent = 'outros';\nlet response = '';\n\nconst textLower = text.toLowerCase();\n\nif (textLower.includes('or\u00e7amento') || textLower.includes('orcamento')) {\n  intent = 'orcamento';\n  response = `Ol\u00e1! \ud83d\udc4b\\n\\nFico feliz em ajudar com seu or\u00e7amento!\\n\\nPara fazer um or\u00e7amento personalizado, preciso de algumas informa\u00e7\u00f5es:\\n\\n1\ufe0f\u20e3 Qual tipo de tecido voc\u00ea prefere?\\n\u2022 Blackout\\n\u2022 Voil\\n\u2022 Linho\\n\u2022 Veludo\\n\u2022 N\u00e3o sei\\n\\nPor favor, me diga qual op\u00e7\u00e3o voc\u00ea prefere! \ud83d\ude0a`;\n} \nelse if (textLower.includes('pre\u00e7o') || textLower.includes('preco') || textLower.includes('valor')) {\n  intent = 'preco';\n  response = `\ud83d\udcb0 *Nossos Pre\u00e7os*\\n\\nNossos valores variam de acordo com:\\n\u2022 Tipo de tecido escolhido\\n\u2022 Tamanho da cortina\\n\u2022 Tipo de instala\u00e7\u00e3o\\n\\nPara um or\u00e7amento exato, responda:\\n\"Quero um or\u00e7amento\"\\n\\nOu ligue: (11) 2692-7865\\n\\n\u2728 Instala\u00e7\u00e3o GR\u00c1TIS em todos os or\u00e7amentos!`;\n}\nelse if (textLower.includes('prazo') || textLower.includes('entrega') || textLower.includes('demora')) {\n  intent = 'prazo';\n  response = `\ud83d\ude9a *Prazos de Entrega*\\n\\n\u2022 Confec\u00e7\u00e3o: 7 a 10 dias \u00fateis\\n\u2022 Instala\u00e7\u00e3o: Agendamos conforme sua disponibilidade\\n\\n\u2705 Trabalhamos com confec\u00e7\u00e3o pr\u00f3pria\\n\u2705 Instala\u00e7\u00e3o GR\u00c1TIS inclu\u00edda\\n\\nGostaria de fazer um or\u00e7amento?`;\n}\nelse if (textLower.includes('instala\u00e7\u00e3o') || textLower.includes('instalacao') || textLower.includes('instalar')) {\n  intent = 'instalacao';\n  response = `\ud83d\udd27 *Instala\u00e7\u00e3o*\\n\\n\u2705 A instala\u00e7\u00e3o \u00e9 TOTALMENTE GR\u00c1TIS!\\n\u2705 Inclu\u00edda em todos os or\u00e7amentos\\n\u2705 Feita por profissionais experientes\\n\\nTipos de instala\u00e7\u00e3o dispon\u00edveis:\\n\u2022 Trilho\\n\u2022 Var\u00e3o\\n\u2022 Trilho Motorizado\\n\\nQuer fazer um or\u00e7amento?`;\n}\nelse if (textLower.includes('hor\u00e1rio') || textLower.includes('horario') || textLower.includes('funciona')) {\n  intent = 'horario';\n  response = `\ud83d\udd50 *Hor\u00e1rio de Atendimento*\\n\\n\ud83d\udccd Loja F\u00edsica:\\nSegunda a Sexta: 9h \u00e0s 18h\\nS\u00e1bado: 9h \u00e0s 13h\\n\\n\ud83d\udcf1 WhatsApp:\\nSegunda a Sexta: 9h \u00e0s 18h\\n\\n\ud83d\udce7 Email (24h):\\nloja@cortinasbresser.com.br\\n\\nComo posso ajudar?`;\n}\nelse if (textLower.includes('endere\u00e7o') || textLower.includes('endereco') || textLower.includes('localiza\u00e7\u00e3o') || textLower.includes('onde')) {\n  intent = 'endereco';\n  response = `\ud83d\udccd *Nossa Localiza\u00e7\u00e3o*\\n\\nRua Bresser, 1084\\nBr\u00e1s - S\u00e3o Paulo - SP\\nCEP: 03162-030\\n\\n\ud83d\ude87 Metr\u00f4 mais pr\u00f3ximo:\\nEsta\u00e7\u00e3o Bresser (Linha 3 - Vermelha)\\n\\n\ud83d\ude97 Estacionamento dispon\u00edvel\\n\\nVenha nos visitar! \ud83d\ude0a`;\n}\nelse if (textLower.includes('tecido') || textLower.includes('tipo') || textLower.includes('modelo')) {\n  intent = 'tecidos';\n  response = `\ud83c\udfa8 *Tipos de Tecido*\\n\\nTrabalhamos com:\\n\\n\ud83c\udf19 *Blackout*\\n\u2022 Bloqueia 100% da luz\\n\u2022 Ideal para quartos\\n\\n\ud83c\udf2b\ufe0f *Voil*\\n\u2022 Leve e transl\u00facido\\n\u2022 Deixa luz natural passar\\n\\n\ud83c\udf3e *Linho*\\n\u2022 Elegante e sofisticado\\n\u2022 V\u00e1rias cores dispon\u00edveis\\n\\n\u2728 *Veludo*\\n\u2022 Luxuoso e confort\u00e1vel\\n\u2022 \u00d3timo isolamento t\u00e9rmico\\n\\nQual te interessa mais?`;\n}\nelse if (textLower.includes('oi') || textLower.includes('ol\u00e1') || textLower.includes('ola') || textLower.includes('bom dia') || textLower.includes('boa tarde') || textLower.includes('boa noite')) {\n  intent = 'saudacao';\n  response = `Ol\u00e1! \ud83d\udc4b Bem-vindo \u00e0 *Cortinas Bresser*!\\n\\nSou o assistente virtual e estou aqui para ajudar! \ud83d\ude0a\\n\\nComo posso te ajudar hoje?\\n\\n\u2022 \ud83d\udecd\ufe0f Fazer um or\u00e7amento\\n\u2022 \ud83d\udcb0 Consultar pre\u00e7os\\n\u2022 \ud83d\ude9a Informa\u00e7\u00f5es sobre prazos\\n\u2022 \ud83d\udccf Tipos de tecido\\n\u2022 \ud83d\udccd Nossa localiza\u00e7\u00e3o\\n\\nDigite sua d\u00favida ou escolha uma op\u00e7\u00e3o!`;\n}\nelse {\n  intent = 'outros';\n  response = `Desculpe, n\u00e3o entendi sua mensagem. \ud83d\ude05\\n\\nPosso ajudar com:\\n\\n\u2022 \ud83d\udecd\ufe0f Or\u00e7amentos\\n\u2022 \ud83d\udcb0 Pre\u00e7os\\n\u2022 \ud83d\ude9a Prazos de entrega\\n\u2022 \ud83d\udccf Tipos de tecido\\n\u2022 \ud83d\udccd Localiza\u00e7\u00e3o\\n\u2022 \ud83d\udd50 Hor\u00e1rio de atendimento\\n\\nOu se preferir, fale com um atendente:\\n\ud83d\udcde (11) 2692-7865`;\n}\n\nreturn {\n  json: {\n    from: from,\n    text: text,\n    intent: intent,\n    response: response,\n    timestamp: new Date().toISOString()\n  }\n};"
      },
      "id": "detect-intent",
      "name": "Detectar Inten\u00e7\u00e3o",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        650,
        300
      ]
    },
    {
      "parameters": {
        "url": "={{$env.EVOLUTION_API_URL}}/message/sendText/{{$env.WHATSAPP_INSTANCE_NAME}}",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "apikey",
              "value": "={{$env.EVOLUTION_API_KEY}}"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "number",
              "value": "={{$json.from}}"
            },
            {
              "name": "text",
              "value": "={{$json.response}}"
            }
          ]
        },
        "options": {}
      },
      "id": "send-response",
      "name": "Enviar Resposta",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        850,
        300
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "schema": "public",
        "table": "leads",
        "columns": "telefone, mensagem, intencao, timestamp",
        "additionalFields": {}
      },
      "id": "save-lead",
      "name": "Salvar Lead",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        850,
        500
      ],
      "credentials": {
        "postgres": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$json.intent}}",
              "operation": "equals",
              "value2": "orcamento"
            }
          ]
        }
      },
      "id": "check-orcamento",
      "name": "\u00c9 Or\u00e7amento?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 1,
      "position": [
        1050,
        300
      ]
    },
    {
      "parameters": {
        "fromEmail": "loja@cortinasbresser.com.br",
        "toEmail": "loja@cortinasbresser.com.br",
        "subject": "\ud83d\udd14 Novo Lead - Or\u00e7amento WhatsApp",
        "text": "=Novo lead solicitou or\u00e7amento via WhatsApp!\n\nTelefone: {{$json.from}}\nMensagem: {{$json.text}}\nHor\u00e1rio: {{$json.timestamp}}\n\nResponda o mais r\u00e1pido poss\u00edvel!",
        "options": {}
      },
      "id": "notify-email",
      "name": "Notificar por Email",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2,
      "position": [
        1250,
        200
      ],
      "credentials": {
        "smtp": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "respondWith": "json",
        "responseBody": "={{ { \"success\": true, \"message\": \"Mensagem processada\" } }}"
      },
      "id": "response",
      "name": "Response",
      "type": "n8n-nodes-base.respondToWebhook",
      "typeVersion": 1,
      "position": [
        1450,
        300
      ]
    }
  ],
  "connections": {
    "Webhook WhatsApp": {
      "main": [
        [
          {
            "node": "Filtrar Mensagens",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Filtrar Mensagens": {
      "main": [
        [
          {
            "node": "Detectar Inten\u00e7\u00e3o",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Detectar Inten\u00e7\u00e3o": {
      "main": [
        [
          {
            "node": "Enviar Resposta",
            "type": "main",
            "index": 0
          },
          {
            "node": "Salvar Lead",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Enviar Resposta": {
      "main": [
        [
          {
            "node": "\u00c9 Or\u00e7amento?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "\u00c9 Or\u00e7amento?": {
      "main": [
        [
          {
            "node": "Notificar por Email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Notificar por Email": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Salvar Lead": {
      "main": [
        [
          {
            "node": "Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "staticData": null,
  "tags": [],
  "triggerCount": 1,
  "updatedAt": "2025-12-07T23:59:00.000Z",
  "versionId": "1"
}