perf(WAI): 解析有引用的消息

main
Lei OT 7 months ago
parent 44b9d930dc
commit 12feaa7780

@ -46,6 +46,7 @@ const createWhatsApp = async phone => {
const { state, saveCreds } = await useMultiFileAuthState(authStateFolder); const { state, saveCreds } = await useMultiFileAuthState(authStateFolder);
// fetch latest version of WA Web // fetch latest version of WA Web
// const { version, isLatest } = await fetchLatestBaileysVersion(); // const { version, isLatest } = await fetchLatestBaileysVersion();
// const { version, isLatest } = await fetchLatestWaWebVersion();
const { version, isLatest, } = { version: [2, 3000, 1025091846], isLatest: false }; const { version, isLatest, } = { version: [2, 3000, 1025091846], isLatest: false };
const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out'); const waVersion = version.join('.') + ', ' + (isLatest ? 'latest' : 'out');
@ -107,15 +108,21 @@ const createWhatsApp = async phone => {
text: { text: {
body: text, body: text,
}, },
context: {
from: decodeJid(original.message?.extendedTextMessage?.contextInfo?.participant),
id: original.message?.extendedTextMessage?.contextInfo?.stanzaId,
},
}; };
}; };
const parseReactionMessage = original => { const parseReactionMessage = original => {
const text = original.message?.reactionMessage?.text; const text = original.message?.reactionMessage?.text;
const context = original.message?.reactionMessage?.key?.id;
return { return {
type: 'text', type: 'reaction',
text: { reaction: {
body: text, message_id: context,
emoji: text,
}, },
}; };
}; };

@ -89,7 +89,17 @@ const waiMsgTypeMapped = {
...(msg.msgcontent.context ? { quoted: { key: msg.msgcontent.context.message_id } } : {}), ...(msg.msgcontent.context ? { quoted: { key: msg.msgcontent.context.message_id } } : {}),
}), }),
waiContentToDB: msg => { 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 => { dataToDB: msg => {
const { msgcontent } = msg; const { msgcontent } = msg;
@ -162,22 +172,21 @@ const waiMsgTypeMapped = {
dataToDB: msg => mediaMsg.dataToDB(msg), dataToDB: msg => mediaMsg.dataToDB(msg),
DbData: msg => mediaMsg.DbData(msg), DbData: msg => mediaMsg.DbData(msg),
}, },
react: { reaction: {
type: 'react', type: 'reaction',
contentToSend: msg => ({ contentToSend: msg => ({
// ...msg, // ...msg,
to: msg.to, to: msg.to,
externalId: msg.actionId, externalId: msg.actionId,
react: { reaction: {
text: msg.msgcontent.body, // emoji | use an empty string to remove the reaction text: msg.msgcontent.body, // emoji | use an empty string to remove the reaction
key: msg.msgcontent.context.message_id, key: msg.msgcontent.context.message_id,
}, },
}), }),
waiContentToDB: msg => { waiContentToDB: msg => {
return { return {
// todo: reaction_message_id: msg?.reaction?.message_id || '',
reaction_message_id: '', reaction_emoji: msg?.reaction?.emoji || '',
reaction_emoji: '',
actionId: msg?.externalId, actionId: msg?.externalId,
externalId: (msg?.externalId || '').split('.')?.[0], externalId: (msg?.externalId || '').split('.')?.[0],
}; };

Loading…
Cancel
Save