Send message without quote if quoteFails (#3475)

* Send message without quote if quoteFails

New option to send a message without quote when quotedMessage fails

* Rest

* Changing to sendMessage level

* Update Utils.js

* Update Utils.js

* Update Utils.js

---------

Co-authored-by: alechkos <93551621+alechkos@users.noreply.github.com>
This commit is contained in:
tuyuribr 2025-04-24 18:10:39 -03:00 • committed by GitHub
commit ad11b5bfee
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 12 deletions

5
index.d.ts vendored
View file

@ -1158,7 +1158,10 @@ declare namespace WAWebJS {
/** Sticker author, if sendMediaAsSticker is true */
stickerAuthor?: string
/** Sticker categories, if sendMediaAsSticker is true */
stickerCategories?: string[]
stickerCategories?: string[],
/** Should the bot send a quoted message without the quoted message if it fails to get the quote?
* @default false (disabled) */
ignoreQuoteErrors?: boolean
}
/** Options for editing a message */

View file

@ -46,20 +46,24 @@ exports.LoadUtils = () => {
if (options.quotedMessageId) {
let quotedMessage = await window.Store.Msg.getMessagesById([options.quotedMessageId]);
if (quotedMessage['messages'].length != 1) {
throw new Error('Could not get the quoted message.');
if (quotedMessage['messages'].length == 1) {
quotedMessage = quotedMessage['messages'][0];
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
const canReply = window.Store.ReplyUtils ?
window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) :
quotedMessage.canReply();
if (canReply) {
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
}
}else{
if(!options.ignoreQuoteErrors) {
throw new Error('Could not get the quoted message.');
}
}
quotedMessage = quotedMessage['messages'][0];
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
const canReply = window.Store.ReplyUtils ?
window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) :
quotedMessage.canReply();
if (canReply) {
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
}
delete options.ignoreQuoteErrors;
delete options.quotedMessageId;
}