diff --git a/index.d.ts b/index.d.ts index b46483f..be9bb7e 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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? * @default true (enabled) */ ignoreQuoteErrors?: boolean + /** + * Should the bot wait for the message send result? + * @default false + */ + waitUntilMsgSent?: boolean } /** Options for editing a message */ diff --git a/src/Client.js b/src/Client.js index f1fe15b..18d3bea 100644 --- a/src/Client.js +++ b/src/Client.js @@ -900,6 +900,7 @@ class Client extends EventEmitter { * @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 {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 {any} [extra] - Extra options */ @@ -950,6 +951,7 @@ class Client extends EventEmitter { groupMentions: options.groupMentions, invokedBotWid: options.invokedBotWid, ignoreQuoteErrors: options.ignoreQuoteErrors !== false, + waitUntilMsgSent: options.waitUntilMsgSent || false, extraOptions: options.extra }; diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index 224ac7e..675073e 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -326,10 +326,11 @@ exports.LoadUtils = () => { return msg; } - await window.Store.SendMessage.addAndSendMsgToChat(chat, message); - await window.Store.HistorySync.sendPeerDataOperationRequest(3, { - chatId: chat.id - }); + const [msgPromise, sendMsgResultPromise] = window.Store.SendMessage.addAndSendMsgToChat(chat, message); + await msgPromise; + + if (options.waitUntilMsgSent) await sendMsgResultPromise; + return window.Store.Msg.get(newMsgKey._serialized); };