waha icon indicating copy to clipboard operation
waha copied to clipboard

# [WEBJS] - Error "Cannot read properties of undefined (reading 'markedUnread')" when sending messages via sendText

Open RaphaelMa opened this issue 10 months ago • 6 comments

Describe the bug

Ao tentar enviar mensagens de texto via POST /api/sendText, o WAHA retorna erro 500 com a mensagem Cannot read properties of undefined (reading 'markedUnread'). O erro ocorre no método sendSeen (marcar mensagem como lida) após o envio da mensagem.

Importante: A mensagem pode estar sendo enviada com sucesso para o WhatsApp, mas o erro impede a confirmação adequada do envio.

Version

{
  "version": "2025.12.2",
  "engine": "WEBJS",
  "tier": "CORE"
}

Steps to Reproduce

  1. Conectar WhatsApp ao WAHA via QR code
  2. Enviar requisição POST para /api/sendText com payload mínimo:
curl -X 'POST' \
  'http://localhost:3000/api/sendText' \
  -H 'accept: application/json' \
  -H 'X-Api-Key: your-api-key' \
  -H 'Content-Type: application/json' \
  -d '{
  "session": "default",
  "chatId": "[email protected]",
  "text": "Hi there!"
}'
  1. O erro ocorre imediatamente após a requisição

Expected behavior

A mensagem deve ser enviada com sucesso e retornar status 200 com o ID da mensagem enviada.

Actual behavior

A requisição retorna status 500 com o seguinte erro:

{
  "statusCode": 500,
  "timestamp": "2026-01-17T03:53:24.543Z",
  "exception": {
    "message": "Cannot read properties of undefined (reading 'markedUnread')\nI (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:4365)\nObject.<anonymous> (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:1751)",
    "name": "TypeError",
    "stack": "TypeError: Cannot read properties of undefined (reading 'markedUnread')\nI (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:4365)\nObject.<anonymous> (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:1751)\n    at window.WWebJS.sendSeen (evaluate at WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:13:40)\n    at #evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)\n    at async ExecutionContext.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:277:16)\n    at async IsolatedWorld.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:100:16)\n    at async CdpFrame.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:362:20)\n    at async CdpPage.evaluate (/app/node_modules/puppeteer/api/Page.js:818:20)\n    at async WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:20)\n    at async WebjsClientCore.sendMessage (/app/node_modules/whatsapp-web.js/src/Client.js:1100:25)\n    at async descriptor.value (/app/dist/core/abc/activity.js:9:20)"
  },
  "request": {
    "path": "/api/sendText",
    "method": "POST",
    "body": {
      "chatId": "[email protected]",
      "text": "Hi there!",
      "session": "default"
    },
    "query": {}
  }
}

Requests - Responses

Request:

POST /api/sendText
Headers:
  accept: application/json
  X-Api-Key: 5e328483c79d4818bf90aae9f246f89d
  Content-Type: application/json

Body:
{
  "session": "default",
  "chatId": "[email protected]",
  "text": "Hi there!"
}

Response (Error):

{
  "statusCode": 500,
  "timestamp": "2026-01-17T03:53:24.543Z",
  "exception": {
    "message": "Cannot read properties of undefined (reading 'markedUnread')",
    "name": "TypeError"
  },
  "request": {
    "path": "/api/sendText",
    "method": "POST",
    "body": {
      "chatId": "[email protected]",
      "text": "Hi there!",
      "session": "default"
    }
  },
  "version": {
    "version": "2025.12.2",
    "engine": "WEBJS",
    "tier": "CORE"
  }
}

Docker Logs

TypeError: Cannot read properties of undefined (reading 'markedUnread')
    at window.WWebJS.sendSeen (evaluate at WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:13:40)
    at async WebjsClientCore.sendMessage (/app/node_modules/whatsapp-web.js/src/Client.js:1100:25)

Additional context

Observações importantes:

  1. O erro ocorre no sendSeen, não no envio da mensagem em si. A mensagem pode estar sendo enviada com sucesso para o WhatsApp, mas o erro impede a confirmação adequada.

  2. O erro é consistente - ocorre em todas as tentativas de envio, mesmo com payload mínimo (apenas session, chatId, text).

  3. Já testado com:

    • Payload mínimo (apenas campos essenciais)
    • Com e sem API key
    • Diferentes formatos de chatId
    • Reconexão do WhatsApp (removendo sessão e escaneando QR code novamente)
  4. Possível workaround: O erro parece estar relacionado ao WhatsApp Web tentando marcar a mensagem como lida automaticamente. Talvez seja necessário:

    • Desabilitar o sendSeen automático
    • Ou tornar o sendSeen opcional/tratável quando falhar
    • Ou verificar se o chat está carregado antes de tentar marcar como lida
  5. Relacionado a: Este erro pode estar relacionado à issue #671 sobre mensagens não sendo entregues ao webhook, pois ambos envolvem problemas de conexão/estado do WhatsApp Web.

Configuração do Docker:

services:
  waha:
    image: devlikeapro/waha:latest
    platform: linux/amd64
    environment:
      WHATSAPP_HOOK_URL: http://host.docker.internal:3333/api/webhooks/waha
      WHATSAPP_DEFAULT_ENGINE: WEBJS
      WHATSAPP_HOOK_EVENTS: message.any
      WAHA_NO_API_KEY: true

Testado em:

  • macOS (Docker Desktop)
  • WAHA versão 2025.12.2
  • Engine: WEBJS
  • Tier: CORE

RaphaelMa avatar Jan 17 '26 04:01 RaphaelMa

English


Describe the bug

When trying to send text messages via POST /api/sendText, WAHA returns error 500 with the message Cannot read properties of undefined (reading 'markedUnread'). The error occurs in the sendSeen method (mark message as read) after sending the message.

Important: The message may be being sent successfully to WhatsApp, but the error prevents proper confirmation of sending.

###Version

{
  "version": "2025.12.2",
  "engine": "WEBJS",
  "tier": "CORE"
}

Steps to Reproduce

  1. Connect WhatsApp to WAHA via QR code
  2. Send POST request to /api/sendText with minimum payload:
curl -X 'POST' \
  'http://localhost:3000/api/sendText' \
  -H 'accept: application/json' \
  -H 'X-Api-Key: your-api-key' \
  -H 'Content-Type: application/json' \
  -d '{
  "session": "default",
  "chatId": "[email protected]",
  "text": "Hi there!"
}'
  1. The error occurs immediately after the request

Expected behavior

The message must be sent successfully and return status 200 with the message ID sent.

Current behavior

The request returns status 500 with the following error:

{
  "statusCode": 500,
  "timestamp": "2026-01-17T03:53:24.543Z",
  "exception": {
    "message": "Cannot read properties of undefined (reading 'markedUnread')\nI (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:4365)\nObject.<anonymous> (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:1751)",
    "name": "TypeError",
    "stack": "TypeError: Cannot read properties of undefined (reading 'markedUnread')\nI (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:4365)\nObject.<anonymous> (https://static.whatsapp.net/rsrc.php/v4ivYF4/yO/l/pt_BR-j/v6r9uR-QSIK.js:1541:1751)\n at window.WWebJS.sendSeen (evaluate at WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:13:40)\n at #evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:391:56)\n at async ExecutionContext.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/ExecutionContext.js:277:16)\n at async IsolatedWorld.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/cdp/IsolatedWorld.js:100:16)\n at async CdpFrame.evaluate (/app/node_modules/puppeteer-core/lib/cjs/puppeteer/api/Frame.js:362:20)\n at async CdpPage.evaluate (/app/node_modules/puppeteer/api/Page.js:818:20)\n at async WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:20)\n at async WebjsClientCore.sendMessage (/app/node_modules/whatsapp-web.js/src/Client.js:1100:25)\n at async descriptor.value (/app/dist/core/abc/activity.js:9:20)"
  },
  "request": {
    "path": "/api/sendText",
    "method": "POST",
    "body": {
      "chatId": "[email protected]",
      "text": "Hi there!",
      "session": "default"
    },
    "query": {}
  }
}

Requests - Responses

Request:

POST /api/sendText
Headers:
  accept: application/json
  X-Api-Key: 5e328483c79d4818bf90aae9f246f89d
  Content-Type: application/json

Body:
{
  "session": "default",
  "chatId": "[email protected]",
  "text": "Hi there!"
}

Response (Error):

{
  "statusCode": 500,
  "timestamp": "2026-01-17T03:53:24.543Z",
  "exception": {
    "message": "Cannot read properties of undefined (reading 'markedUnread')",
    "name": "TypeError"
  },
  "request": {
    "path": "/api/sendText",
    "method": "POST",
    "body": {
      "chatId": "[email protected]",
      "text": "Hi there!",
      "session": "default"
    }
  },
  "version": {
    "version": "2025.12.2",
    "engine": "WEBJS",
    "tier": "CORE"
  }
}

Docker Logs

TypeError: Cannot read properties of undefined (reading 'markedUnread')
    at window.WWebJS.sendSeen (evaluate at WPage.evaluate (/app/dist/core/engines/webjs/WPage.js:13:36), <anonymous>:13:40)
    at async WebjsClientCore.sendMessage (/app/node_modules/whatsapp-web.js/src/Client.js:1100:25)

Additional context

Important notes:

  1. The error occurs in sendSeen, not in sending the message itself. The message may be being sent successfully to WhatsApp, but the error prevents proper confirmation.

  2. The error is consistent - it occurs in all sending attempts, even with minimal payload (only session, chatId, text).

  3. Already tested with:

    • Minimum payload (essential fields only)
    • With and without API key
    • Different chatId formats
    • WhatsApp reconnection (removing session and scanning QR code again)
  4. Possible workaround: The error appears to be related to WhatsApp Web trying to mark the message as automatically read. You may need:

    • Disable automatic sendSeen
    • Or make sendSeen optional/handleable when it fails
    • Or check if the chat is loaded before trying to mark it as read
  5. Related to: This error may be related to issue #671 about messages not being delivered to the webhook, as both involve WhatsApp Web connection/status issues.

Docker Configuration:

services:
  waha:
    image: devlikeapro/waha:latest
    platform: linux/amd64
    environment:
      WHATSAPP_HOOK_URL: http://host.docker.internal:3333/api/webhooks/waha
      WHATSAPP_DEFAULT_ENGINE: WEBJS
      WHATSAPP_HOOK_EVENTS: message.any
      WAHA_NO_API_KEY: true

Tested on:

  • macOS (Docker Desktop)
  • WAHA version 2025.12.2
  • Engine: WEBJS
  • Tier: CORE

github-actions[bot] avatar Jan 17 '26 04:01 github-actions[bot]

you can fix this with update to latest version

agungyaa86 avatar Jan 17 '26 05:01 agungyaa86

you can fix this with update to latest version

What is the most up-to-date version so I can test it? I've already tried sendText and senSeen, and neither works. If you know, it would be a great help.

raphaelmviana avatar Jan 17 '26 05:01 raphaelmviana

you can fix this with update to latest version

What is the most up-to-date version so I can test it? I've already tried sendText and senSeen, and neither works. If you know, it would be a great help.

2026.1.3 , for SendText its working For WEBJS , but SendSeen its not working until now . but if you use engine GOWS its working for sendText and SendSeen

agungyaa86 avatar Jan 17 '26 06:01 agungyaa86

Okay, I tested it this morning and it should be working again.

raphaelmviana avatar Jan 17 '26 22:01 raphaelmviana

🛠️ Fixes

  • 2026.1.3 - WEBJS - fix api/sendText - #1810

patron:PRO

devlikepro avatar Jan 19 '26 02:01 devlikepro