[BUG] msgCall quebra com TypeError quando quem liga chega como @lid, e o erro engole o webhook CALL do offer

Open
#2,781 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 4 days

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
72/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript

Research direction

Read src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts around lines 1886–1899 in tag 2.3.7, focusing on the call offer handler, LID mapping, sendMessage, and sendDataWebhook. Trace what happens when getPNForLID() returns undefined and check how an error affects the remaining event handlers. Done means an unmapped LID cannot suppress the CALL offer webhook or abort unrelated events, while the webhook retains the original caller JID.

Written by the indexing model from the issue text.

Description

Bem-vindo!
  • Sim, pesquisei problemas semelhantes no GitHub e não encontrei nenhum.
O que você fez?

Tenho instâncias Baileys numa Evolution 2.3.7, algumas delas com recusa automática de chamada ligada:

{ "rejectCall": true, "msgCall": "📵 Desculpe, esse número não recebe chamadas; envie uma mensagem!" }

Comparando o que acontece quando alguém liga para essas instâncias, encontrei dois comportamentos diferentes, dependendo apenas do formato do JID de quem liga:

Quem ligou chegou como Chamada recusada msgCall enviada
5511xxxxxxxxx:[email protected] sim sim
2148301202187xx@lid sim não — estoura TypeError
O que você esperava?

Que a mensagem do msgCall fosse enviada em qualquer um dos dois casos, e que uma falha nesse envio não afetasse mais nada.

O que vc observou ao invés do que esperava?

Quando quem liga chega como @lid, a chamada é recusada (o servidor confirma com CB:ack, class: 'call', type: 'reject'), mas o envio da mensagem quebra:

[Evolution API] [<instancia>] v2.3.7 - ERROR [ChannelStartupService]
TypeError: Cannot destructure property 'user' of 'jidDecode(...)' as it is undefined.
    at relayMessage (file:///evolution/node_modules/baileys/lib/Socket/messages-send.js:408:17)
    at Object.sendMessage (file:///evolution/node_modules/baileys/lib/Socket/messages-send.js:957:23)
    at async /evolution/dist/main.js:263:3482

Causa, em src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts (linhas 1886–1899 na tag 2.3.7):

if (settings?.rejectCall && call.status == 'offer') {
  this.client.rejectCall(call.id, call.from);
}

if (settings?.msgCall?.trim().length > 0 && call.status == 'offer') {
  if (call.from.endsWith('@lid')) {
    call.from = await this.client.signalRepository.lidMapping.getPNForLID(call.from as string);
  }
  const msg = await this.client.sendMessage(call.from, { text: settings.msgCall });

  this.client.ev.emit('messages.upsert', { messages: [msg], type: 'notify' });
}

this.sendDataWebhook(Events.CALL, call);

Quando o LID de quem liga ainda não tem mapeamento para telefone — caso comum de alguém que nunca conversou com o número —, getPNForLID() devolve undefined. O valor é escrito de volta em call.from, e o sendMessage(undefined, …) cai no jidDecode(undefined) dentro do Baileys.

Três consequências, em ordem de gravidade:

  1. A exceção aborta o restante do lote de eventos. O try que envolve esse trecho cobre também connection.update, messages.upsert, creds.update e os demais handlers do mesmo lote do ev.process. Uma chamada perdida pode, portanto, descartar eventos que nada têm a ver com chamada.
  2. O webhook CALL do offer nunca é entregue, porque sendDataWebhook() vem depois do envio. Confirmado aqui comparando duas instâncias com a mesma configuração: na que o envio funcionou, o webhook recebeu status: "offer" e depois os ringing; na que estourou, só chegaram os ringing — o offer desapareceu. Quem integra perde justamente o evento que indica a chamada entrando.
  3. call.from é modificado antes do webhook. Quando o mapeamento funciona, o payload do CALL sai com o telefone no lugar do @lid original, ou seja, o mesmo campo tem significado diferente dependendo de o mapeamento existir ou não.
Como reproduzir
  1. Instância Baileys com rejectCall: true e msgCall preenchido.
  2. Ligar para o número a partir de uma conta que nunca trocou mensagem com ele (para não haver mapeamento LID→telefone).
  3. A chamada é cortada, a mensagem não chega e o log mostra o TypeError acima. O webhook não recebe o evento com status: "offer".
Capturas de Tela/Vídeos

Sem resposta

Qual versão da API você está usando?

v2.3.7 (evoapicloud/evolution-api:latest, baileys 7.0.0-rc.9)

Qual é o seu ambiente?

Docker

Outras especificações do ambiente

Docker Swarm, Postgres 14, Redis, instâncias Baileys atrás de proxy HTTP.

Dominant language
TypeScript
Stars
10.2k
Forks
7.5k
Avg merge
6d 19h
Merged PRs (30d)
4

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from evolution-foundation/evolution-api

All issues in evolution-foundation/evolution-api

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.