Skip to content

[BAILEYS][Chatwoot App] readMessages on @lid chats routes to WEBJS getChat -> 500, blocks outbound send #2115

@uilll

Description

@uilll

GitHub Issue — devlikeapro/waha

Title: [BAILEYS][Chatwoot App] readMessages on @lid chats routes to WEBJS getChat → 500, blocks outbound send

Description

Environment

  • WAHA version: 2026.5.1 (GET /api/version or error payload version.version)
  • Image: devlikeapro/waha:latest (digest truncated)
  • Engine: WHATSAPP_DEFAULT_ENGINE=BAILEYS
  • WAHA Apps: WAHA_APPS_ON=chatwoot
  • Platform: linux/x64, tier CORE

Steps to reproduce

  1. Run WAHA with BAILEYS engine and Chatwoot app enabled (inbox API channel).
  2. Ensure a Chatwoot contact has custom_attributes.wa_lid (e.g. {numeric_id}@lid) — normal for WhatsApp privacy / Linked ID.
  3. Create an outgoing message in Chatwoot inbox (or via API) so ChatWootInboxMessageCreatedConsumer runs.
  4. Observe job chatwoot.inbox | message_created fail after 3 retries.

Expected behavior

  • sendTextMessage should deliver to WhatsApp even if mark-as-read fails, or
  • readMessages on BAILEYS session should use Baileys implementation, not WEBJS.

Actual behavior

MessageHandler.sendTextMessage calls await session.readMessages(chatId) before sendText:

// /app/dist/apps/chatwoot/consumers/inbox/message_created.js (~line 163)
await session.readMessages(chatId);
await session.startTyping(...);
const msg = await session.sendText(request);

For @lid chat IDs, internal API call fails:

POST /api/default/chats/{lid}@lid/messages/read
→ 500 TypeError: Cannot read properties of undefined (reading 'getChat')

Stack trace shows WEBJS path while session reports BAILEYS:

WhatsappSessionWebJSCore.readChatMessages (session.webjs.core.js:608)
WebjsClientCore.getChatById (whatsapp-web.js Client.js:1171)
WPage.evaluate (webjs/WPage.js:13)

Version block in error JSON:

"version": { "version": "2026.5.1", "engine": "BAILEYS", "tier": "CORE" }

Outbound WhatsApp messages never send because the exception aborts before sendText.

Workaround (local patch)

Wrap readMessages in try/catch in message_created.js so send proceeds:

try { await session.readMessages(chatId); } catch (e) { this.logger.warn(`Skip readMessages: ${e?.message}`); }

Suggested fix (upstream)

  1. Implement readChatMessages for BAILEYS engine (or route by active engine, not WEBJS fallback).
  2. In Chatwoot app consumer: do not fail the whole send if readMessages fails (non-fatal).
  3. Resolve @lid@c.us via /api/{session}/lids/{lid} before read, when applicable.

Related issues


Issue filed: #2115

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions