feat: group mentions + improved user mentions (#2602)
* added logic to mention groups + fixed user mentions * usage example updated * docs fixed * window.injectToFunction clarifications * usage example clarifications * fix: typo * docs: added missed docs
This commit is contained in:
parent
8d683a668b
commit
e0d955f130
1 changed files with 164 additions and 25 deletions
|
|
@ -810,6 +810,13 @@ class Client extends EventEmitter {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* An object representing mentions of groups
|
||||
* @typedef {Object} GroupMention
|
||||
* @property {string} subject - The name of a group to mention (can be custom)
|
||||
* @property {string} id - The group ID, e.g.: 'XXXXXXXXXX@g.us'
|
||||
*/
|
||||
|
||||
/**
|
||||
* Message options.
|
||||
* @typedef {Object} MessageSendOptions
|
||||
|
|
@ -822,7 +829,8 @@ class Client extends EventEmitter {
|
|||
* @property {boolean} [parseVCards=true] - Automatically parse vCards and send them as contacts
|
||||
* @property {string} [caption] - Image or video caption
|
||||
* @property {string} [quotedMessageId] - Id of the message that is being quoted (or replied to)
|
||||
* @property {Contact[]} [mentions] - Contacts that are being mentioned in the message
|
||||
* @property {GroupMention[]} [groupMentions] - An array of object that handle group mentions
|
||||
* @property {string[]} [mentions] - User IDs to mention in the message
|
||||
* @property {boolean} [sendSeen=true] - Mark the conversation as seen after sending the message
|
||||
* @property {string} [stickerAuthor=undefined] - Sets the author of the sticker, (if sendMediaAsSticker is true).
|
||||
* @property {string} [stickerName=undefined] - Sets the name of the sticker, (if sendMediaAsSticker is true).
|
||||
|
|
@ -839,10 +847,16 @@ class Client extends EventEmitter {
|
|||
* @returns {Promise<Message>} Message that was just sent
|
||||
*/
|
||||
async sendMessage(chatId, content, options = {}) {
|
||||
if (options.mentions && options.mentions.some(possiblyContact => possiblyContact instanceof Contact)) {
|
||||
console.warn('Mentions with an array of Contact are now deprecated. See more at https://github.com/pedroslopez/whatsapp-web.js/pull/2166.');
|
||||
options.mentions = options.mentions.map(a => a.id._serialized);
|
||||
if (options.mentions) {
|
||||
!Array.isArray(options.mentions) && (options.mentions = [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/pedroslopez/whatsapp-web.js/pull/2166.');
|
||||
options.mentions = options.mentions.map((a) => a.id._serialized);
|
||||
}
|
||||
}
|
||||
|
||||
options.groupMentions && !Array.isArray(options.groupMentions) && (options.groupMentions = [options.groupMentions]);
|
||||
|
||||
let internalOptions = {
|
||||
linkPreview: options.linkPreview === false ? undefined : true,
|
||||
sendAudioAsVoice: options.sendAudioAsVoice,
|
||||
|
|
@ -852,7 +866,8 @@ class Client extends EventEmitter {
|
|||
caption: options.caption,
|
||||
quotedMessageId: options.quotedMessageId,
|
||||
parseVCards: options.parseVCards === false ? false : true,
|
||||
mentionedJidList: Array.isArray(options.mentions) ? options.mentions : [],
|
||||
mentionedJidList: options.mentions || [],
|
||||
groupMentions: options.groupMentions,
|
||||
extraOptions: options.extra
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue