{
  "name": "WAHA - Message Type Extractor v2",
  "nodes": [
    {
      "id": "webhook_entrada",
      "type": "n8n-nodes-base.webhook",
      "name": "Webhook - WAHA",
      "typeVersion": 1,
      "position": [
        280,
        320
      ],
      "parameters": {
        "httpMethod": "POST",
        "path": "webhook/waha",
        "responseMode": "onReceived",
        "responseData": "auto"
      }
    },
    {
      "id": "function_extract",
      "type": "n8n-nodes-base.function",
      "name": "Extrair Dados WAHA",
      "typeVersion": 1,
      "position": [
        700,
        320
      ],
      "parameters": {
        "functionCode": "const body = $json.body || {};\nconst p = body.payload || {};\n\n// Campos principais\nconst instance = body.session || null;\nconst eventId = body.id || null;\nconst messageId = p.id || null;\nconst messageType = p.messageType || p._data?.Info?.Type || \"unknown\";\n\n// Conte\u00fados\nconst text = p.body || p._data?.Message?.conversation || null;\nconst media = p.media || null;\n\n// remoteJid\nconst remoteJid = p._data?.Info?.Chat || p.from || p.to || null;\n\n// telefone e nome\nconst from = p.from?.replace(\"@c.us\", \"\") || null;\nconst name = p._data?.Info?.PushName || null;\n\n// grupo e participantes\nconst isGroup = p._data?.Info?.IsGroup || false;\nconst participant = p.participant || null;\n\n// veio de mim\nconst fromMe = p.fromMe || false;\n\nreturn [\n{\n  json: {\n    instance,\n    eventId,\n    messageId,\n    remoteJid,\n    messageType,\n    text,\n    media,\n    from,\n    name,\n    participant,\n    isGroup,\n    fromMe,\n    full: $json\n  }\n}\n];"
      }
    },
    {
      "id": "switch_tipo",
      "type": "n8n-nodes-base.switch",
      "name": "Switch Tipo",
      "typeVersion": 1,
      "position": [
        1040,
        320
      ],
      "parameters": {
        "value1": "={{$json[\"messageType\"]}}",
        "rules": {
          "rules": [
            {
              "operation": "equals",
              "value": "text"
            },
            {
              "operation": "equals",
              "value": "image"
            },
            {
              "operation": "equals",
              "value": "audio"
            },
            {
              "operation": "equals",
              "value": "video"
            },
            {
              "operation": "equals",
              "value": "document"
            },
            {
              "operation": "equals",
              "value": "sticker"
            },
            {
              "operation": "equals",
              "value": "location"
            },
            {
              "operation": "equals",
              "value": "button"
            },
            {
              "operation": "equals",
              "value": "list"
            }
          ]
        }
      }
    },
    {
      "id": "texto",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udcc4 Texto",
      "typeVersion": 1,
      "position": [
        1400,
        40
      ]
    },
    {
      "id": "imagem",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\uddbc\ufe0f Imagem",
      "typeVersion": 1,
      "position": [
        1400,
        160
      ]
    },
    {
      "id": "audio",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83c\udfa7 \u00c1udio",
      "typeVersion": 1,
      "position": [
        1400,
        280
      ]
    },
    {
      "id": "video",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83c\udfac V\u00eddeo",
      "typeVersion": 1,
      "position": [
        1400,
        400
      ]
    },
    {
      "id": "documento",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udcc4 Documento",
      "typeVersion": 1,
      "position": [
        1400,
        520
      ]
    },
    {
      "id": "sticker",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udc9f Sticker",
      "typeVersion": 1,
      "position": [
        1400,
        640
      ]
    },
    {
      "id": "location",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udccd Localiza\u00e7\u00e3o",
      "typeVersion": 1,
      "position": [
        1400,
        760
      ]
    },
    {
      "id": "button",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udd18 Bot\u00e3o",
      "typeVersion": 1,
      "position": [
        1400,
        880
      ]
    },
    {
      "id": "list",
      "type": "n8n-nodes-base.noOp",
      "name": "\ud83d\udccb Lista",
      "typeVersion": 1,
      "position": [
        1400,
        1000
      ]
    }
  ],
  "connections": {
    "webhook_entrada": {
      "main": [
        [
          {
            "node": "function_extract",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "function_extract": {
      "main": [
        [
          {
            "node": "switch_tipo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "switch_tipo": {
      "main": [
        [
          {
            "node": "\ud83d\udcc4 Texto",
            "type": "main",
            "index": 0
          },
          {
            "node": "\ud83d\uddbc\ufe0f Imagem",
            "type": "main",
            "index": 1
          },
          {
            "node": "\ud83c\udfa7 \u00c1udio",
            "type": "main",
            "index": 2
          },
          {
            "node": "\ud83c\udfac V\u00eddeo",
            "type": "main",
            "index": 3
          },
          {
            "node": "\ud83d\udcc4 Documento",
            "type": "main",
            "index": 4
          },
          {
            "node": "\ud83d\udc9f Sticker",
            "type": "main",
            "index": 5
          },
          {
            "node": "\ud83d\udccd Localiza\u00e7\u00e3o",
            "type": "main",
            "index": 6
          },
          {
            "node": "\ud83d\udd18 Bot\u00e3o",
            "type": "main",
            "index": 7
          },
          {
            "node": "\ud83d\udccb Lista",
            "type": "main",
            "index": 8
          }
        ]
      ]
    }
  }
}