waha
waha copied to clipboard
[BAILEYS][Chatwoot App] readMessages on @lid chats routes to WEBJS getChat -> 500, blocks outbound send
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/versionor error payloadversion.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
- Run WAHA with BAILEYS engine and Chatwoot app enabled (inbox API channel).
- Ensure a Chatwoot contact has
custom_attributes.wa_lid(e.g.{numeric_id}@lid) — normal for WhatsApp privacy / Linked ID. - Create an outgoing message in Chatwoot inbox (or via API) so
ChatWootInboxMessageCreatedConsumerruns. - Observe job
chatwoot.inbox | message_createdfail after 3 retries.
Expected behavior
sendTextMessageshould deliver to WhatsApp even if mark-as-read fails, orreadMessageson 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)
- Implement
readChatMessagesfor BAILEYS engine (or route by active engine, not WEBJS fallback). - In Chatwoot app consumer: do not fail the whole send if
readMessagesfails (non-fatal). - Resolve
@lid→@c.usvia/api/{session}/lids/{lid}before read, when applicable.
Related issues
- #1782, #1810, #1985 — similar
getChat/ WEBJS undefined Store errors on@lidchats
Issue filed: https://github.com/devlikeapro/waha/issues/2115