Free, Open Source, Self-Hosted WhatsApp API Gateway
TypeScript apibotgatewayself-hostedwhatsappwhatsapp-apiwhatsapp-automationwhatsapp-botwhatsapp-gatewaywhatsapp-gateway-apiwhatsapp-webwhatsapp-web-api
fix(dashboard): skip the live history read on Baileys
Yudhi Armyndharis70e30b2739ed
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 1dfe525e2..d8ef2523a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -69,6 +69,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0- Bound Redis cache commands and discard expired operations during reconnect.- Preserve literal request values in custom ingress acknowledgments.- Honor inclusive millisecond lower bounds in built-in search.+- Stop the dashboard from asking Baileys for live chat history on every chat it opens; Baileys answers 501 to it, which logged a failed request each time.- Preserve replacement plugin search providers during worker recovery.- Answer 409 naming the path and the cause on `GET /api/infra/storage/files/count` and `/export` when the local storage directory holds a symbolic link, a directory the app cannot read or one nested 20 levels deep, instead of silently leaving those files out of the count and the archive.- Normalize CRLF line endings in SDK contract parsers so Windows checkouts do not produce false contract mismatches (#1885). Thanks @Purushotham-Prajapati-24.diff --git a/dashboard/src/hooks/useChatMessages.ts b/dashboard/src/hooks/useChatMessages.tsindex 4c75577e2..5aedf0b49 100644--- a/dashboard/src/hooks/useChatMessages.ts+++ b/dashboard/src/hooks/useChatMessages.ts@@ -56,17 +56,21 @@ export function flattenMessagePages(data: MessagesData): ChatMessageView[] {* in it (so a media-heavy page 0 can't grow the cache unbounded), and `select` caps the flattened,* correctly-ordered thread again for what actually renders — the two bounds cover the cache and the* viewport respectively, and neither alone would cover both.+ *+ * `historySupported` is false for an engine that answers 501 to the history read (Baileys): the request is+ * never sent, so every chat opened there does not log a failed call in the browser console.*/export function useChatMessages(sessionId: string,chatId: string | null,+ historySupported = true,): UseInfiniteQueryResult<ChatMessageView[], Error> {const queryClient = useQueryClient();const query = useInfiniteQuery<MessagePage, Error, ChatMessageView[], MessagesQueryKey, number>({queryKey: messagesQueryKey(sessionId, chatId ?? ''),initialPageParam: 0,queryFn: async ({ pageParam }) => {- const wantsHistory = pageParam === 0;+ const wantsHistory = pageParam === 0 && historySupported;const [dbRes, historyRes] = await Promise.allSettled([sessionApi.getChatMessages(sessionId, chatId!, MESSAGE_PAGE_SIZE, pageParam),wantsHistory ? sessionApi.getChatHistory(sessionId, chatId!, 100, false) : Promise.resolve([]),diff --git a/dashboard/src/pages/Chats.features.test.ts b/dashboard/src/pages/Chats.features.test.tsindex f15e9bdaa..ab492ba19 100644--- a/dashboard/src/pages/Chats.features.test.ts+++ b/dashboard/src/pages/Chats.features.test.ts@@ -2063,6 +2063,29 @@ test('a message that reaches a chat after a change keeps its row when an earlierassert.ok(screen.getByText('after the mark'), 'the earlier list rolled the preview back');});+// ── The live history read of an opened chat. ──++// Baileys answers 501 to it, so every chat opened there logged a failed call in the browser console. An engine+// the page does not know is still asked: skipping it would drop the backfill on an engine that has it.+for (const [engine, asked] of [+ ['baileys', false],+ ['whatsapp-web.js', true],+ [null, true],+] as const) {+ test(`opening a chat ${asked ? 'asks' : 'does not ask'} ${engine ?? 'an unknown engine'} for live history`, async () => {+ const { screen, fireEvent, waitFor } = rtl;+ if (engine) window.sessionStorage.setItem('openwa_engine_type', engine);+ else window.sessionStorage.removeItem('openwa_engine_type');+ aliceThread = [threadRow(1)];+ renderPage();+ fireEvent.click(await screen.findByText('Alice'));+ await screen.findByText('message 1');+ const history = () => fetchCalls.filter(c => c.method === 'GET' && /\/messages\/[^/]+\/history/.test(c.path));+ if (asked) await waitFor(() => assert.equal(history().length, 1, 'the live history was not read once'));+ else assert.equal(history().length, 0, 'the engine that answers 501 was asked for live history');+ });+}+// ── What clearing and deleting a chat leave behind on the page. ──test('clearing a chat empties its preview and refreshes the thread that is open', async () => {diff --git a/dashboard/src/pages/Chats.tsx b/dashboard/src/pages/Chats.tsxindex f575c5bee..98e41fff3 100644--- a/dashboard/src/pages/Chats.tsx+++ b/dashboard/src/pages/Chats.tsx@@ -272,7 +272,12 @@ export function Chats() {hasNextPage: hasMoreMessages,isFetchingNextPage: loadingOlderMessages,fetchNextPage,- } = useChatMessages(selectedSessionId, activeChat?.id ?? null);+ } = useChatMessages(+ selectedSessionId,+ activeChat?.id ?? null,+ // Baileys has no live per-chat history read and answers 501 to it; any other or unknown engine is asked.+ engineType !== 'baileys',+ );const { appendMessage, updateMessage } = useChatMessagesActions();const queryClient = useQueryClient();