From 12feaa778052b48173034a083f54dd2334d1642d Mon Sep 17 00:00:00 2001 From: Lei OT Date: Fri, 19 Sep 2025 15:45:40 +0800 Subject: [PATCH] =?UTF-8?q?perf(WAI):=20=E8=A7=A3=E6=9E=90=E6=9C=89?= =?UTF-8?q?=E5=BC=95=E7=94=A8=E7=9A=84=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wai-server/core/baileys/index.js | 13 ++++++++++--- wai-server/helper/wai.msg.helper.js | 23 ++++++++++++++++------- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/wai-server/core/baileys/index.js b/wai-server/core/baileys/index.js index 03b98ea..5a79f7f 100644 --- a/wai-server/core/baileys/index.js +++ b/wai-server/core/baileys/index.js @@ -46,6 +46,7 @@ const createWhatsApp = async phone => { const { state, saveCreds } = await useMultiFileAuthState(authStateFolder); // fetch latest version of WA Web // const { version, isLatest } = await fetchLatestBaileysVersion(); + // const { version, isLatest } = await fetchLatestWaWebVersion(); const { version, isLatest, } = { version: [2, 3000, 1025091846], isLatest: false }; const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out'); @@ -107,15 +108,21 @@ const createWhatsApp = async phone => { text: { body: text, }, + context: { + from: decodeJid(original.message?.extendedTextMessage?.contextInfo?.participant), + id: original.message?.extendedTextMessage?.contextInfo?.stanzaId, + }, }; }; const parseReactionMessage = original => { const text = original.message?.reactionMessage?.text; + const context = original.message?.reactionMessage?.key?.id; return { - type: 'text', - text: { - body: text, + type: 'reaction', + reaction: { + message_id: context, + emoji: text, }, }; }; diff --git a/wai-server/helper/wai.msg.helper.js b/wai-server/helper/wai.msg.helper.js index 262e314..beb0460 100644 --- a/wai-server/helper/wai.msg.helper.js +++ b/wai-server/helper/wai.msg.helper.js @@ -89,7 +89,17 @@ const waiMsgTypeMapped = { ...(msg.msgcontent.context ? { quoted: { key: msg.msgcontent.context.message_id } } : {}), }), waiContentToDB: msg => { - return { text_body: msg.text.body, actionId: msg?.externalId, externalId: (msg?.externalId || '').split('.')?.[0] }; + return { + text_body: msg.text.body, + actionId: msg?.externalId, + externalId: (msg?.externalId || '').split('.')?.[0], + ...(msg.context + ? { + context_id: msg.context.id, + context_from: msg.context.from, + } + : {}), + }; }, dataToDB: msg => { const { msgcontent } = msg; @@ -162,22 +172,21 @@ const waiMsgTypeMapped = { dataToDB: msg => mediaMsg.dataToDB(msg), DbData: msg => mediaMsg.DbData(msg), }, - react: { - type: 'react', + reaction: { + type: 'reaction', contentToSend: msg => ({ // ...msg, to: msg.to, externalId: msg.actionId, - react: { + reaction: { text: msg.msgcontent.body, // emoji | use an empty string to remove the reaction key: msg.msgcontent.context.message_id, }, }), waiContentToDB: msg => { return { - // todo: - reaction_message_id: '', - reaction_emoji: '', + reaction_message_id: msg?.reaction?.message_id || '', + reaction_emoji: msg?.reaction?.emoji || '', actionId: msg?.externalId, externalId: (msg?.externalId || '').split('.')?.[0], };