davexbaileys 2.5.17 → 2.5.18

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10,30 +10,57 @@ const WABinary_1 = require("../WABinary");
10
10
  const chats_1 = require("./chats");
11
11
 
12
12
  /**
13
- * Detect if a message mentions any group JID (@g.us)
14
- * — "antiGroupMention" prevents users from tagging groups inside private chats or status updates.
15
- * Works on text, extendedText, image captions, video captions, etc.
16
- * @param message - the WebMessageInfo object
17
- * @returns array of group JIDs that were mentioned (empty array = no group mentions)
13
+ * Extract all group JIDs (@g.us) mentioned in a message's contextInfo.mentionedJid list.
14
+ *
15
+ * WHAT "antiGroupMention" means in WhatsApp bots:
16
+ * When someone sends a message and @-tags a GROUP (not a person), WhatsApp puts that
17
+ * group's JID (ending in @g.us) inside contextInfo.mentionedJid.
18
+ * "Anti group mention" = detect & action messages where someone is tagging/promoting
19
+ * ANOTHER GROUP inside your group — e.g. sharing group invite links or pinging rival groups.
20
+ * It is NOT about messages coming FROM a group; it is about messages that CONTAIN a @group mention.
21
+ *
22
+ * HOW it works (official Baileys source — Utils/messages.js):
23
+ * key.contextInfo.mentionedJid = message.mentions;
24
+ * Each entry is either a user JID (@s.whatsapp.net) or a group JID (@g.us).
25
+ *
26
+ * FIX (v2.5.18): previous version used `getAllMentioned(ctx) || getAllMentioned(next)`.
27
+ * An empty array [] is truthy in JS, so the || chain ALWAYS stopped at the first call
28
+ * even when that message type didn't exist. Now we chain on contextInfo objects (which
29
+ * are undefined when absent = falsy) so the || correctly falls through.
30
+ *
31
+ * @param message - WebMessageInfo object (sock.ev.on('messages.upsert') message)
32
+ * @returns array of group JIDs (@g.us) mentioned — empty array means no group mentions
18
33
  */
19
34
  const getGroupMentions = (message) => {
20
- var _a, _b, _c, _d, _e, _f, _g, _h;
21
- const getAllMentioned = (contextInfo) => {
22
- return (contextInfo === null || contextInfo === void 0 ? void 0 : contextInfo.mentionedJid) || [];
23
- };
24
- const msg = message === null || message === void 0 ? void 0 : message.message;
35
+ const msg = (message === null || message === void 0 ? void 0 : message.message) || null;
25
36
  if (!msg) return [];
26
- const mentioned =
27
- getAllMentioned((_b = (_a = msg.extendedTextMessage) === null || _a === void 0 ? void 0 : _a.contextInfo) !== null && _b !== void 0 ? _b : null) ||
28
- getAllMentioned((_d = (_c = msg.imageMessage) === null || _c === void 0 ? void 0 : _c.contextInfo) !== null && _d !== void 0 ? _d : null) ||
29
- getAllMentioned((_f = (_e = msg.videoMessage) === null || _e === void 0 ? void 0 : _e.contextInfo) !== null && _f !== void 0 ? _f : null) ||
30
- getAllMentioned((_h = (_g = msg.documentMessage) === null || _g === void 0 ? void 0 : _g.contextInfo) !== null && _h !== void 0 ? _h : null) ||
31
- [];
32
- return mentioned.filter(jid => typeof jid === 'string' && jid.endsWith('@g.us'));
37
+ // Chain on contextInfo OBJECTS (undefined = falsy → || falls through correctly)
38
+ const contextInfo =
39
+ msg.extendedTextMessage?.contextInfo ||
40
+ msg.imageMessage?.contextInfo ||
41
+ msg.videoMessage?.contextInfo ||
42
+ msg.documentMessage?.contextInfo ||
43
+ msg.audioMessage?.contextInfo ||
44
+ msg.stickerMessage?.contextInfo ||
45
+ null;
46
+ const mentionedJids = (contextInfo === null || contextInfo === void 0 ? void 0 : contextInfo.mentionedJid) || [];
47
+ return mentionedJids.filter(jid => typeof jid === 'string' && jid.endsWith('@g.us'));
33
48
  };
34
49
  /**
35
- * Returns true if the message contains any group mention (@g.us JID)
36
- * Use this to enforce "antiGroupMention" policy in private chats or status updates.
50
+ * Returns true if the message @-mentions any group JID (@g.us).
51
+ * Use to enforce "anti group mention" remove or warn members who tag other groups
52
+ * inside your group to prevent spam or promotion of rival groups.
53
+ *
54
+ * Usage:
55
+ * sock.ev.on('messages.upsert', async ({ messages }) => {
56
+ * for (const msg of messages) {
57
+ * if (isAntiGroupMention(msg)) {
58
+ * const groups = getGroupMentions(msg); // array of @g.us JIDs they tagged
59
+ * await sock.sendMessage(msg.key.remoteJid, { text: 'No group mentions allowed!' });
60
+ * await sock.groupParticipantsUpdate(msg.key.remoteJid, [msg.key.participant], 'remove');
61
+ * }
62
+ * }
63
+ * });
37
64
  */
38
65
  const isAntiGroupMention = (message) => {
39
66
  return getGroupMentions(message).length > 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davexbaileys",
3
- "version": "2.5.17",
3
+ "version": "2.5.18",
4
4
  "description": "A lightweight, full-featured WhatsApp Web API library for Node.js — maintained by Dave Tech",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",