From 5cfd51fdb6ca2b274fc9090c3d3f15f9a042ef5b Mon Sep 17 00:00:00 2001 From: Adrian Victor Date: Tue, 14 Jul 2026 18:04:41 -0300 Subject: [PATCH] Infer attachment type from file mime type and change endpoint accordingly. --- app.js | 2 ++ ui.js | 1 - waha.js | 11 +++++++---- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app.js b/app.js index cd5a5a1..3d0da53 100644 --- a/app.js +++ b/app.js @@ -290,6 +290,8 @@ async function sendMessage() { async function sendFileMessage(file) { try { const result = await waha.sendFileMessage(activeChatState.id, file); + console.log(result) + // ui.appendSingleMessage(result, activeChatState.name, userInfo.id, activeChatState.id); } catch (error) { console.error(error.message); } diff --git a/ui.js b/ui.js index 3fd2f3b..4f8909d 100644 --- a/ui.js +++ b/ui.js @@ -147,7 +147,6 @@ export const ui = { }, generateMessage(msg, activeChatName, userID, chatId) { - console.log(msg) const isOutgoing = msg.fromMe || msg.sender === 'me'; const groupDiv = document.createElement('div'); diff --git a/waha.js b/waha.js index 4ce4abf..15028ea 100644 --- a/waha.js +++ b/waha.js @@ -144,7 +144,6 @@ export const waha = { async sendFileMessage(chatId, file) { const fileBase64 = await getBase64(file); - console.log(fileBase64) const body = { method: 'POST', body: JSON.stringify({ @@ -157,9 +156,13 @@ export const waha = { session: config.session }) }; - console.log(body); - const result = await request('/api/sendFile', body); - console.log(result); + + let endpoint = "/api/sendFile"; + + if (file.type.startsWith('image/')) endpoint = '/api/sendImage'; + if (file.type.startsWith('video/')) endpoint = '/api/sendVideo'; + + const result = await request(endpoint, body); return result; } };