Skip to content

Commit ad11b5b

Browse files
tuyuribralechkos
andauthored
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 <[email protected]>
1 parent 6d16555 commit ad11b5b

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

index.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,10 @@ declare namespace WAWebJS {
11581158
/** Sticker author, if sendMediaAsSticker is true */
11591159
stickerAuthor?: string
11601160
/** Sticker categories, if sendMediaAsSticker is true */
1161-
stickerCategories?: string[]
1161+
stickerCategories?: string[],
1162+
/** Should the bot send a quoted message without the quoted message if it fails to get the quote?
1163+
* @default false (disabled) */
1164+
ignoreQuoteErrors?: boolean
11621165
}
11631166

11641167
/** Options for editing a message */

src/util/Injected/Utils.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,20 +46,24 @@ exports.LoadUtils = () => {
4646
if (options.quotedMessageId) {
4747
let quotedMessage = await window.Store.Msg.getMessagesById([options.quotedMessageId]);
4848

49-
if (quotedMessage['messages'].length != 1) {
50-
throw new Error('Could not get the quoted message.');
51-
}
52-
53-
quotedMessage = quotedMessage['messages'][0];
49+
if (quotedMessage['messages'].length == 1) {
50+
quotedMessage = quotedMessage['messages'][0];
5451

55-
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
56-
const canReply = window.Store.ReplyUtils ?
57-
window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) :
58-
quotedMessage.canReply();
52+
// TODO remove .canReply() once all clients are updated to >= v2.2241.6
53+
const canReply = window.Store.ReplyUtils ?
54+
window.Store.ReplyUtils.canReplyMsg(quotedMessage.unsafe()) :
55+
quotedMessage.canReply();
5956

60-
if (canReply) {
61-
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
57+
if (canReply) {
58+
quotedMsgOptions = quotedMessage.msgContextInfo(chat);
59+
}
60+
}else{
61+
if(!options.ignoreQuoteErrors) {
62+
throw new Error('Could not get the quoted message.');
63+
}
6264
}
65+
66+
delete options.ignoreQuoteErrors;
6367
delete options.quotedMessageId;
6468
}
6569

0 commit comments

Comments
 (0)