diff --git a/index.d.ts b/index.d.ts index 8127770492b..5085535134f 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1571,8 +1571,8 @@ declare namespace WAWebJS { caption?: string; /** Id of the message that is being quoted (or replied to) */ quotedMessageId?: string; - /** User IDs to mention in the message */ - mentions?: string[]; + /** User IDs to mention in the message or string @all to mention everybody */ + mentions?: string[] | string; /** An array of object that handle group mentions */ groupMentions?: { /** The name of a group to mention (can be custom) */ diff --git a/src/Client.js b/src/Client.js index a122a8f336b..c9c1c1e8dd4 100644 --- a/src/Client.js +++ b/src/Client.js @@ -1492,19 +1492,26 @@ class Client extends EventEmitter { } if (options.mentions) { - !Array.isArray(options.mentions) && - (options.mentions = [options.mentions]); if ( - options.mentions.some( - (possiblyContact) => possiblyContact instanceof Contact, - ) + options.mentions !== '@all' && + !Array.isArray(options.mentions) ) { - console.warn( - 'Mentions with an array of Contact are now deprecated. See more at https://github.com/wwebjssapp-web.js/pull/2166.', - ); - options.mentions = options.mentions.map( - (a) => a.id._serialized, - ); + options.mentions = [options.mentions]; + } + + if (Array.isArray(options.mentions)) { + if ( + options.mentions.some( + (possiblyContact) => possiblyContact instanceof Contact, + ) + ) { + console.warn( + 'Mentions with an array of Contact are now deprecated. See more at https://github.com/wwebjs/whatsapp-web.js/pull/2166.', + ); + options.mentions = options.mentions.map( + (a) => a.id._serialized, + ); + } } } diff --git a/src/util/Injected/Utils.js b/src/util/Injected/Utils.js index dfa30a579de..885b923e782 100644 --- a/src/util/Injected/Utils.js +++ b/src/util/Injected/Utils.js @@ -203,11 +203,23 @@ exports.LoadUtils = () => { delete options.quotedMessageId; } + let mentionAll = {}; if (options.mentionedJidList) { - options.mentionedJidList = options.mentionedJidList.map((id) => - window.require('WAWebWidFactory').createWid(id), - ); - options.mentionedJidList = options.mentionedJidList.filter(Boolean); + if (options.mentionedJidList === '@all') { + mentionAll = { nonJidMentions: 1 }; + options.mentionedJidList = []; + } else if (Array.isArray(options.mentionedJidList)) { + if (options.mentionedJidList.includes('@all')) { + options.mentionedJidList = options.mentionedJidList.filter( + (id) => id !== '@all', + ); + } + options.mentionedJidList = options.mentionedJidList.map((id) => + window.require('WAWebWidFactory').createWid(id), + ); + options.mentionedJidList = + options.mentionedJidList.filter(Boolean); + } } if (options.groupMentions) { @@ -480,6 +492,7 @@ exports.LoadUtils = () => { ...buttonOptions, ...listOptions, ...botOptions, + ...mentionAll, ...extraOptions, };