fix: send message properly (#3692)

* fix: remove high cpu consumption by adding waiting for message logic

 Co-authored-by: Shir Serlui <70711723+shirser121@users.noreply.github.com>

* refactor: use already defined msg id

* refactor: use optional arg for waiting for msg ack
This commit is contained in:
alechkos 2025-08-12 07:33:02 +03:00 • committed by GitHub
commit bd677a8a66
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 4 deletions

5
index.d.ts vendored
View file

@ -1382,6 +1382,11 @@ declare namespace WAWebJS {
/** Should the bot send a quoted message without the quoted message if it fails to get the quote? /** Should the bot send a quoted message without the quoted message if it fails to get the quote?
* @default true (enabled) */ * @default true (enabled) */
ignoreQuoteErrors?: boolean ignoreQuoteErrors?: boolean
/**
* Should the bot wait for the message send result?
* @default false
*/
waitUntilMsgSent?: boolean
} }
/** Options for editing a message */ /** Options for editing a message */

View file

@ -900,6 +900,7 @@ class Client extends EventEmitter {
* @property {string} [stickerName=undefined] - Sets the name of the sticker, (if sendMediaAsSticker is true). * @property {string} [stickerName=undefined] - Sets the name of the sticker, (if sendMediaAsSticker is true).
* @property {string[]} [stickerCategories=undefined] - Sets the categories of the sticker, (if sendMediaAsSticker is true). Provide emoji char array, can be null. * @property {string[]} [stickerCategories=undefined] - Sets the categories of the sticker, (if sendMediaAsSticker is true). Provide emoji char array, can be null.
* @property {boolean} [ignoreQuoteErrors = true] - Should the bot send a quoted message without the quoted message if it fails to get the quote? * @property {boolean} [ignoreQuoteErrors = true] - Should the bot send a quoted message without the quoted message if it fails to get the quote?
* @property {boolean} [waitUntilMsgSent = false] - Should the bot wait for the message send result?
* @property {MessageMedia} [media] - Media to be sent * @property {MessageMedia} [media] - Media to be sent
* @property {any} [extra] - Extra options * @property {any} [extra] - Extra options
*/ */
@ -950,6 +951,7 @@ class Client extends EventEmitter {
groupMentions: options.groupMentions, groupMentions: options.groupMentions,
invokedBotWid: options.invokedBotWid, invokedBotWid: options.invokedBotWid,
ignoreQuoteErrors: options.ignoreQuoteErrors !== false, ignoreQuoteErrors: options.ignoreQuoteErrors !== false,
waitUntilMsgSent: options.waitUntilMsgSent || false,
extraOptions: options.extra extraOptions: options.extra
}; };

View file

@ -326,10 +326,11 @@ exports.LoadUtils = () => {
return msg; return msg;
} }
await window.Store.SendMessage.addAndSendMsgToChat(chat, message); const [msgPromise, sendMsgResultPromise] = window.Store.SendMessage.addAndSendMsgToChat(chat, message);
await window.Store.HistorySync.sendPeerDataOperationRequest(3, { await msgPromise;
chatId: chat.id
}); if (options.waitUntilMsgSent) await sendMsgResultPromise;
return window.Store.Msg.get(newMsgKey._serialized); return window.Store.Msg.get(newMsgKey._serialized);
}; };