diff --git a/index.d.ts b/index.d.ts index 22aea7e..a6c3250 100644 --- a/index.d.ts +++ b/index.d.ts @@ -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 */ diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index f476441..8af0324 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -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]; - 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(); - // 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); + if (canReply) { + quotedMsgOptions = quotedMessage.msgContextInfo(chat); + } + }else{ + if(!options.ignoreQuoteErrors) { + throw new Error('Could not get the quoted message.'); + } } + + delete options.ignoreQuoteErrors; delete options.quotedMessageId; }