evolution-api icon indicating copy to clipboard operation
evolution-api copied to clipboard

No está funcionando la solución al bug de remotejid = @lid

Open erikam-stack opened this issue 11 months ago • 14 comments

Closing as duplicate of #1872 — @lid handling meta-issue.

See #1872 for tracked symptoms and ongoing work.

erikam-stack avatar Dec 17 '25 13:12 erikam-stack

Tambem estou com o mesmo problema

JeanLDev avatar Dec 17 '25 16:12 JeanLDev

A solução é adicionar um nó de código (JavaScript) no fluxo pra resolver o JID de forma segura, mesmo quando o remoteJidAlt não vem.

O que esse código faz

  • Valida se um JID é realmente um WhatsApp válido (@s.whatsapp.net com 11 a 15 dígitos).
  • Primeiro tenta usar o remoteJid.
  • Se o remoteJid for do tipo @lid ou inválido, tenta o remoteJidAlt.
  • Se nenhum dos dois servir, retorna null.
  • No final, ele padroniza a saída, evitando quebrar o fluxo.

Código para o nó Code (JS) no n8n

const jidRegex = /^\d{11,15}@s\.whatsapp\.net$/;

const isValidJid = (value) =>
  typeof value === "string" && jidRegex.test(value.trim());

const pickRemoteJid = (json) => {
  const primary = json?.body?.data?.key?.remoteJid;
  if (isValidJid(primary)) return { value: primary.trim(), from: "remoteJid" };

  const alt = json?.body?.data?.key?.remoteJidAlt;
  if (isValidJid(alt)) return { value: alt.trim(), from: "remoteJidAlt" };

  return { value: null, from: null };
};

for (const item of $input.all()) {
  const { value, from } = pickRemoteJid(item.json);

  item.json.remoteJidResolved = value;
  item.json.remoteJidResolvedFrom = from;
  item.json.remoteJidIsValid = Boolean(value);
}

return $input.all();

Como usar depois no fluxo

Após esse nó:

  • Sempre use remoteJidResolved como JID oficial do cliente

  • Pode validar antes com remoteJidIsValid === true

  • Se for false, você já sabe que veio apenas @lid e pode:

    • Ignorar a mensagem
    • Logar para debug
    • Tratar como conversa não identificável

Isso elimina o problema do @lid, evita dependência exclusiva do remoteJidAlt e deixa o fluxo bem mais estável.

renatojuniordw avatar Dec 17 '25 22:12 renatojuniordw

renatojuniordw não resolve pois o numero só vem com remoteJid

JeanLDev avatar Dec 18 '25 14:12 JeanLDev

renatojuniordw não resolve pois o numero só vem com remoteJid

No meu o número aparece em ambos (remoteJid/remoteJidAlt), pesquisando vi pessoas falando que podiam aparece em um ou outro, por isso adicionei está validação.

renatojuniordw avatar Dec 18 '25 14:12 renatojuniordw

no meu só aparece remoteJid, testei para 3 numeros

JeanLDev avatar Dec 18 '25 14:12 JeanLDev

no meu só aparece remoteJid, testei para 3 numeros

Você tá usando qual imagem do evolution? Utilizei uma que só mostrava o remoteJid com @lid, e precisei muda-la para que mostrasse remoteJid e remoteJidAlt.

renatojuniordw avatar Dec 18 '25 15:12 renatojuniordw

acabei de resolver mudando a imagem e a versão, rodei evoapicloud/evolution-api:latest

JeanLDev avatar Dec 18 '25 21:12 JeanLDev

Isso vai resolver. Comece o fluxo a partir deste:

{
  "nodes": [
    {
      "parameters": {
        "httpMethod": "POST",
        "path": "mensagem-recebida",
        "options": {}
      },
      "type": "n8n-nodes-base.webhook",
      "typeVersion": 2,
      "position": [
        -960,
        224
      ],
      "id": "9e199461-0f4c-48ee-a544-6536d016f1dd",
      "name": "Mensagem Recebida",
      "webhookId": "282cab09-112a-4c89-97a1-8f7663389db8"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "f449fe96-7893-4903-bc88-ef5b5abce3c9",
              "leftValue": "={{ $json.body.data.key.remoteJid }}",
              "rightValue": "@lid",
              "operator": {
                "type": "string",
                "operation": "endsWith"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -352,
        208
      ],
      "id": "53fbf511-e7a0-45e5-98a3-850bce3e7a9b",
      "name": "Verifica @lid",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fa705675-b844-4cf1-a23d-868568bdd3fd",
              "name": "remetente",
              "value": "={{ $json.body.data.key.remoteJid.split('@') [0]  }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -48,
        112
      ],
      "id": "45017eba-16d5-4f34-836e-1c3673ddbaa5",
      "name": "@lid"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fa705675-b844-4cf1-a23d-868568bdd3fd",
              "name": "remetente",
              "value": "={{ $json.body.data.key.remoteJid.split('@') [0]  }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -48,
        320
      ],
      "id": "8259c27d-9c9c-4eca-8d5a-7450242555a0",
      "name": "@whatsapp.net"
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 2
          },
          "conditions": [
            {
              "id": "9f76561b-68c6-4faf-8e6d-583850189237",
              "leftValue": "={{ $json.body.data.key.fromMe }}",
              "rightValue": "[email protected]",
              "operator": {
                "type": "boolean",
                "operation": "false",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -704,
        224
      ],
      "id": "4b34f529-1f85-4ab0-852c-868c53ed6b36",
      "name": "Me?",
      "alwaysOutputData": false
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "fa705675-b844-4cf1-a23d-868568bdd3fd",
              "name": "remetente",
              "value": "={{ $json.remetente }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        192
      ],
      "id": "f07252d4-e564-44e7-ab34-ff51ec7bf37a",
      "name": "Dados"
    }
  ],
  "connections": {
    "Mensagem Recebida": {
      "main": [
        [
          {
            "node": "Me?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Verifica @lid": {
      "main": [
        [
          {
            "node": "@lid",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "@whatsapp.net",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "@lid": {
      "main": [
        [
          {
            "node": "Dados",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "@whatsapp.net": {
      "main": [
        [
          {
            "node": "Dados",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Me?": {
      "main": [
        [
          {
            "node": "Verifica @lid",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    }
  },
  "pinData": {
    "Mensagem Recebida": [
      {
        "headers": {
          "host": "sistemas-n8n.izzm4q.easypanel.host",
          "user-agent": "axios/1.10.0",
          "content-length": "690",
          "accept": "application/json, text/plain, */*",
          "accept-encoding": "gzip, compress, deflate, br",
          "content-type": "application/json",
          "x-forwarded-for": "172.18.0.1",
          "x-forwarded-host": "sistemas-n8n.izzm4q.easypanel.host",
          "x-forwarded-port": "443",
          "x-forwarded-proto": "https",
          "x-forwarded-server": "5411e7e6f0d3",
          "x-real-ip": "172.18.0.1"
        },
        "params": {},
        "query": {},
        "body": {
          "event": "messages.upsert",
          "instance": "ldl",
          "data": {
            "key": {
              "remoteJid": "[email protected]",
              "fromMe": true,
              "id": "3A456053CDADF3FC3B55"
            },
            "pushName": "Loja das Lojas",
            "status": "SERVER_ACK",
            "message": {
              "conversation": "#Jarvis\nAdicione acesso vitalício para\[email protected]"
            },
            "messageType": "conversation",
            "messageTimestamp": 1756940767,
            "instanceId": "7abe36d8-e74b-407c-ad22-2a7d56eb7d5a",
            "source": "ios"
          },
          "destination": "https://sistemas-n8n.izzm4q.easypanel.host/webhook/mensagem-recebida",
          "date_time": "2025-09-03T20:06:07.854Z",
          "sender": "[email protected]",
          "server_url": "https://sistemas-evolution-api.izzm4q.easypanel.host",
          "apikey": "C49C1F3B13A9-4B02-95B1-95410D837834"
        },
        "webhookUrl": "https://sistemas-n8n.izzm4q.easypanel.host/webhook/mensagem-recebida",
        "executionMode": "production"
      }
    ]
  },
  "meta": {
    "instanceId": "b871045089a8444a6a7163962f9f54fc390e770d426ee84b4931263a3abbdf1c"
  }
}

thallesmitchell avatar Dec 19 '25 18:12 thallesmitchell

SOLUCIONADO: La última versión de ApiEvolution (v2.3.7) soluciona este bug

erikam-stack avatar Dec 19 '25 18:12 erikam-stack

a versao nova 2.3.7 resolveu o problema do @lid porem o meu sendlist parou, alguem passou por isso tambem?

marcosserg12 avatar Dec 20 '25 05:12 marcosserg12

a versao nova 2.3.7 resolveu o problema do @lid porem o meu sendlist parou, alguem passou por isso tambem?

Me pasa lo mismo y no veo la version 2.3.7

palma001 avatar Dec 28 '25 15:12 palma001

Na evolution 2.3.7 também está acontecendo isso, somente o remoteJid com o lid dentro.

gmarruda avatar Dec 29 '25 17:12 gmarruda

Fala galera! estou com esse problema, no Easypanel a evolution api mostra como ultima versão apenas a v2.3.2 em 12/01/26. não aparece a v2.3.7

IsaacFSantos avatar Jan 12 '26 21:01 IsaacFSantos

Had the same symptom described here (remoteJid = @lid with no working fallback). Turned out remoteJidAlt was completely missing from the message key in my case, not just unresolved — that's what was crashing createConversation.

Submitted a fix: https://github.com/evolution-foundation/evolution-api/pull/2718

abdulsametkarakayali avatar Sep 03 '26 13:09 abdulsametkarakayali