@hbmodsofc/baileys 1.5.0 → 1.7.6

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.
Files changed (156) hide show
  1. package/LICENSE +1 -1
  2. package/WAProto/index.js +19671 -152026
  3. package/engine-requirements.js +4 -4
  4. package/lib/Defaults/index.d.ts +12 -8
  5. package/lib/Defaults/index.js +90 -124
  6. package/lib/Signal/Group/group_cipher.d.ts +0 -1
  7. package/lib/Signal/Group/group_cipher.js +28 -39
  8. package/lib/Signal/Group/sender-chain-key.d.ts +1 -1
  9. package/lib/Signal/Group/sender-chain-key.js +9 -2
  10. package/lib/Signal/Group/sender-key-distribution-message.js +3 -3
  11. package/lib/Signal/Group/sender-key-message.js +3 -3
  12. package/lib/Signal/Group/sender-key-state.d.ts +4 -4
  13. package/lib/Signal/Group/sender-key-state.js +47 -16
  14. package/lib/Signal/libsignal.d.ts +7 -3
  15. package/lib/Signal/libsignal.js +224 -39
  16. package/lib/Signal/lid-mapping.d.ts +26 -0
  17. package/lib/Signal/lid-mapping.js +146 -0
  18. package/lib/Socket/Client/index.d.ts +2 -3
  19. package/lib/Socket/Client/index.js +2 -3
  20. package/lib/Socket/Client/{abstract-socket-client.d.ts → types.d.ts} +1 -3
  21. package/lib/Socket/Client/{web-socket-client.d.ts → websocket.d.ts} +1 -1
  22. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +10 -16
  23. package/lib/Socket/business.d.ts +94 -78
  24. package/lib/Socket/business.js +130 -11
  25. package/lib/Socket/chats.d.ts +63 -233
  26. package/lib/Socket/chats.js +234 -184
  27. package/lib/Socket/communities.d.ts +232 -0
  28. package/lib/Socket/communities.js +402 -0
  29. package/lib/Socket/groups.d.ts +62 -41
  30. package/lib/Socket/groups.js +76 -64
  31. package/lib/Socket/index.d.ts +129 -83
  32. package/lib/Socket/index.js +13 -6
  33. package/lib/Socket/messages-recv.d.ts +59 -48
  34. package/lib/Socket/messages-recv.js +516 -371
  35. package/lib/Socket/messages-send.d.ts +86 -67
  36. package/lib/Socket/messages-send.js +1091 -1
  37. package/lib/Socket/mex.d.ts +2 -0
  38. package/lib/Socket/mex.js +45 -0
  39. package/lib/Socket/newsletter.d.ts +76 -64
  40. package/lib/Socket/newsletter.js +184 -1
  41. package/lib/Socket/socket.d.ts +19 -13
  42. package/lib/Socket/socket.js +805 -1
  43. package/lib/Types/Auth.d.ts +4 -10
  44. package/lib/Types/Bussines.d.ts +24 -0
  45. package/lib/Types/Bussines.js +2 -0
  46. package/lib/Types/Call.d.ts +1 -1
  47. package/lib/Types/Chat.d.ts +29 -9
  48. package/lib/Types/Chat.js +7 -1
  49. package/lib/Types/Contact.d.ts +5 -1
  50. package/lib/Types/Events.d.ts +55 -14
  51. package/lib/Types/GroupMetadata.d.ts +15 -5
  52. package/lib/Types/Label.d.ts +11 -0
  53. package/lib/Types/Label.js +1 -1
  54. package/lib/Types/LabelAssociation.js +1 -1
  55. package/lib/Types/Message.d.ts +75 -49
  56. package/lib/Types/Message.js +10 -7
  57. package/lib/Types/Newsletter.d.ts +129 -98
  58. package/lib/Types/Newsletter.js +33 -38
  59. package/lib/Types/Product.d.ts +1 -1
  60. package/lib/Types/Signal.d.ts +29 -1
  61. package/lib/Types/Socket.d.ts +48 -22
  62. package/lib/Types/State.d.ts +13 -2
  63. package/lib/Types/State.js +12 -0
  64. package/lib/Types/USync.d.ts +1 -1
  65. package/lib/Types/index.d.ts +10 -3
  66. package/lib/Types/index.js +2 -2
  67. package/lib/Utils/auth-utils.d.ts +3 -3
  68. package/lib/Utils/auth-utils.js +378 -102
  69. package/lib/Utils/baileys-event-stream.js +1 -1
  70. package/lib/Utils/business.d.ts +2 -2
  71. package/lib/Utils/business.js +19 -13
  72. package/lib/Utils/chat-utils.d.ts +21 -22
  73. package/lib/Utils/chat-utils.js +201 -154
  74. package/lib/Utils/crypto.d.ts +18 -19
  75. package/lib/Utils/crypto.js +78 -37
  76. package/lib/Utils/decode-wa-message.d.ts +34 -7
  77. package/lib/Utils/decode-wa-message.js +138 -66
  78. package/lib/Utils/event-buffer.d.ts +6 -8
  79. package/lib/Utils/event-buffer.js +81 -43
  80. package/lib/Utils/generics.d.ts +27 -27
  81. package/lib/Utils/generics.js +128 -133
  82. package/lib/Utils/history.d.ts +9 -5
  83. package/lib/Utils/history.js +17 -23
  84. package/lib/Utils/index.d.ts +2 -0
  85. package/lib/Utils/index.js +2 -0
  86. package/lib/Utils/lidToJid-test.d.ts +11 -0
  87. package/lib/Utils/lidToJid-test.js +27 -0
  88. package/lib/Utils/link-preview.d.ts +4 -4
  89. package/lib/Utils/link-preview.js +40 -12
  90. package/lib/Utils/logger.d.ts +11 -3
  91. package/lib/Utils/lt-hash.d.ts +8 -8
  92. package/lib/Utils/lt-hash.js +23 -24
  93. package/lib/Utils/make-mutex.d.ts +2 -2
  94. package/lib/Utils/make-mutex.js +3 -2
  95. package/lib/Utils/message-retry-manager.d.ts +81 -0
  96. package/lib/Utils/message-retry-manager.js +152 -0
  97. package/lib/Utils/messages-media.d.ts +37 -41
  98. package/lib/Utils/messages-media.js +252 -368
  99. package/lib/Utils/messages.d.ts +13 -15
  100. package/lib/Utils/messages.js +274 -261
  101. package/lib/Utils/noise-handler.d.ts +13 -15
  102. package/lib/Utils/noise-handler.js +20 -26
  103. package/lib/Utils/process-message.d.ts +9 -8
  104. package/lib/Utils/process-message.js +157 -93
  105. package/lib/Utils/signal.d.ts +6 -5
  106. package/lib/Utils/signal.js +37 -29
  107. package/lib/Utils/use-multi-file-auth-state.d.ts +1 -2
  108. package/lib/Utils/use-multi-file-auth-state.js +12 -7
  109. package/lib/Utils/validate-connection.d.ts +5 -6
  110. package/lib/Utils/validate-connection.js +39 -97
  111. package/lib/WABinary/constants.d.ts +24 -27
  112. package/lib/WABinary/constants.js +1276 -13
  113. package/lib/WABinary/decode.d.ts +3 -4
  114. package/lib/WABinary/decode.js +28 -14
  115. package/lib/WABinary/encode.d.ts +1 -2
  116. package/lib/WABinary/encode.js +134 -147
  117. package/lib/WABinary/generic-utils.d.ts +4 -7
  118. package/lib/WABinary/generic-utils.js +40 -125
  119. package/lib/WABinary/jid-utils.d.ts +13 -8
  120. package/lib/WABinary/jid-utils.js +27 -16
  121. package/lib/WAM/BinaryInfo.d.ts +2 -11
  122. package/lib/WAM/constants.d.ts +3 -2
  123. package/lib/WAM/constants.js +2252 -2359
  124. package/lib/WAM/encode.d.ts +1 -2
  125. package/lib/WAM/encode.js +8 -11
  126. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +2 -2
  127. package/lib/WAUSync/Protocols/USyncContactProtocol.js +3 -4
  128. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +2 -2
  129. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +5 -5
  130. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +2 -2
  131. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +5 -5
  132. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +2 -2
  133. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +5 -6
  134. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +2 -2
  135. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +1 -1
  136. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +4 -3
  137. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
  138. package/lib/WAUSync/USyncQuery.d.ts +2 -2
  139. package/lib/WAUSync/USyncQuery.js +19 -15
  140. package/lib/WAUSync/USyncUser.d.ts +5 -5
  141. package/lib/WAUSync/index.d.ts +1 -1
  142. package/lib/WAUSync/index.js +1 -1
  143. package/package.json +102 -102
  144. package/lib/Defaults/baileys-version.json +0 -3
  145. package/lib/Defaults/phonenumber-mcc.json +0 -223
  146. package/lib/Signal/Group/queue-job.d.ts +0 -1
  147. package/lib/Signal/Group/queue-job.js +0 -57
  148. package/lib/Socket/Client/mobile-socket-client.d.ts +0 -13
  149. package/lib/Socket/Client/mobile-socket-client.js +0 -65
  150. package/lib/Socket/hbmods.d.ts +0 -253
  151. package/lib/Socket/hbmods.js +0 -1
  152. package/lib/Socket/registration.d.ts +0 -267
  153. package/lib/Socket/registration.js +0 -166
  154. package/lib/Socket/usync.d.ts +0 -36
  155. package/lib/Socket/usync.js +0 -70
  156. /package/lib/Socket/Client/{abstract-socket-client.js → types.js} +0 -0
@@ -1,7 +1,6 @@
1
- /// <reference types="node" />
2
- import { proto } from '../../WAProto';
3
- import { GroupMetadata, ParticipantAction, SocketConfig } from '../Types';
4
- import { BinaryNode } from '../WABinary';
1
+ import { proto } from '../../WAProto/index.js';
2
+ import type { GroupMetadata, ParticipantAction, SocketConfig, WAMessageKey } from '../Types';
3
+ import { type BinaryNode } from '../WABinary';
5
4
  export declare const makeGroupsSocket: (config: SocketConfig) => {
6
5
  groupMetadata: (jid: string) => Promise<GroupMetadata>;
7
6
  groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
@@ -10,7 +9,7 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
10
9
  groupRequestParticipantsList: (jid: string) => Promise<{
11
10
  [key: string]: string;
12
11
  }[]>;
13
- groupRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
12
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
14
13
  status: string;
15
14
  jid: string;
16
15
  }[]>;
@@ -23,93 +22,115 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
23
22
  groupInviteCode: (jid: string) => Promise<string | undefined>;
24
23
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
25
24
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
25
+ /**
26
+ * revoke a v4 invite for someone
27
+ * @param groupJid group jid
28
+ * @param invitedJid jid of person you invited
29
+ * @returns true if successful
30
+ */
31
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
26
32
  /**
27
33
  * accept a GroupInviteMessage
28
34
  * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
29
35
  * @param inviteMessage the message to accept
30
36
  */
31
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
37
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
32
38
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
33
39
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
34
- groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>;
35
- groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>;
36
- groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>;
40
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
41
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
42
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
37
43
  groupFetchAllParticipating: () => Promise<{
38
44
  [_: string]: GroupMetadata;
39
45
  }>;
46
+ createCallLink: (type: "audio" | "video", event?: {
47
+ startTime: number;
48
+ }, timeoutMs?: number) => Promise<string | undefined>;
49
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
40
50
  processingMutex: {
41
- mutex<T>(code: () => T | Promise<T>): Promise<T>;
51
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
42
52
  };
43
53
  fetchPrivacySettings: (force?: boolean) => Promise<{
44
54
  [_: string]: string;
45
55
  }>;
46
- upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
56
+ upsertMessage: (msg: import("../Types").WAMessage, type: import("../Types").MessageUpsertType) => Promise<void>;
47
57
  appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
48
- sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
49
- presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
50
- profilePictureUrl: (jid: string, type?: "image" | "preview", timeoutMs?: number | undefined) => Promise<string | undefined>;
51
- onWhatsApp: (...jids: string[]) => Promise<{
52
- jid: string;
53
- exists: unknown;
54
- lid: unknown;
55
- }[] | undefined>;
58
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
59
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
60
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
56
61
  fetchBlocklist: () => Promise<string[]>;
57
- fetchStatus: (jid: string) => Promise<{
58
- status: string | undefined;
59
- setAt: Date;
60
- } | undefined>;
61
- updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
62
+ fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
63
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
64
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload, dimensions?: {
65
+ width: number;
66
+ height: number;
67
+ }) => Promise<void>;
62
68
  removeProfilePicture: (jid: string) => Promise<void>;
63
69
  updateProfileStatus: (status: string) => Promise<void>;
64
70
  updateProfileName: (name: string) => Promise<void>;
65
71
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
72
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
73
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>;
74
+ updateMessagesPrivacy: (value: import("../Types").WAPrivacyMessagesValue) => Promise<void>;
66
75
  updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
67
76
  updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
68
77
  updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
69
78
  updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
70
79
  updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
71
- updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
80
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>;
72
81
  updateDefaultDisappearingMode: (duration: number) => Promise<void>;
73
- getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
74
- resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
82
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
83
+ resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
75
84
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
76
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
85
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
86
+ addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
87
+ removeContact: (jid: string) => Promise<void>;
88
+ addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
77
89
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
78
90
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
79
91
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
80
92
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
81
93
  star: (jid: string, messages: {
82
94
  id: string;
83
- fromMe?: boolean | undefined;
95
+ fromMe?: boolean;
84
96
  }[], star: boolean) => Promise<void>;
97
+ addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
98
+ removeQuickReply: (timestamp: string) => Promise<void>;
85
99
  type: "md";
86
- ws: any;
100
+ ws: import("./Client/websocket.js").WebSocketClient;
87
101
  ev: import("../Types").BaileysEventEmitter & {
88
102
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
89
103
  buffer(): void;
90
- createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
91
- flush(force?: boolean | undefined): boolean;
104
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
105
+ flush(): boolean;
92
106
  isBuffering(): boolean;
93
107
  };
94
108
  authState: {
95
109
  creds: import("../Types").AuthenticationCreds;
96
110
  keys: import("../Types").SignalKeyStoreWithTransaction;
97
111
  };
98
- signalRepository: import("../Types").SignalRepository;
112
+ signalRepository: import("../Types").SignalRepositoryWithLIDStore;
99
113
  user: import("../Types").Contact | undefined;
100
114
  generateMessageTag: () => string;
101
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
102
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
115
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
116
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
103
117
  waitForSocketOpen: () => Promise<void>;
104
118
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
105
119
  sendNode: (frame: BinaryNode) => Promise<void>;
106
- logout: (msg?: string | undefined) => Promise<void>;
120
+ logout: (msg?: string) => Promise<void>;
107
121
  end: (error: Error | undefined) => void;
108
- onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
109
- uploadPreKeys: (count?: number) => Promise<void>;
122
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
123
+ uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
110
124
  uploadPreKeysToServerIfRequired: () => Promise<void>;
111
- requestPairingCode: (phoneNumber: string) => Promise<string>;
112
- waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
113
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
125
+ requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
126
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
127
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
128
+ executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
129
+ onWhatsApp: (...jids: string[]) => Promise<{
130
+ jid: string;
131
+ exists: boolean;
132
+ lid: string;
133
+ }[] | undefined>;
114
134
  };
115
135
  export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata;
136
+ export type GroupsSocket = ReturnType<typeof makeGroupsSocket>;
@@ -1,24 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.extractGroupMetadata = exports.makeGroupsSocket = void 0;
4
- const WAProto_1 = require("../../WAProto");
4
+ const index_js_1 = require("../../WAProto/index.js");
5
5
  const Types_1 = require("../Types");
6
6
  const Utils_1 = require("../Utils");
7
7
  const WABinary_1 = require("../WABinary");
8
8
  const chats_1 = require("./chats");
9
- const WAUSync_1 = require("../WAUSync");
10
9
  const makeGroupsSocket = (config) => {
11
10
  const sock = (0, chats_1.makeChatsSocket)(config);
12
11
  const { authState, ev, query, upsertMessage } = sock;
13
- const groupQuery = async (jid, type, content) => (query({
12
+ const groupQuery = async (jid, type, content) => query({
14
13
  tag: 'iq',
15
14
  attrs: {
16
15
  type,
17
16
  xmlns: 'w:g2',
18
- to: jid,
17
+ to: jid
19
18
  },
20
19
  content
21
- }));
20
+ });
22
21
  const groupMetadata = async (jid) => {
23
22
  const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
24
23
  return (0, exports.extractGroupMetadata)(result);
@@ -29,7 +28,7 @@ const makeGroupsSocket = (config) => {
29
28
  attrs: {
30
29
  to: '@g.us',
31
30
  xmlns: 'w:g2',
32
- type: 'get',
31
+ type: 'get'
33
32
  },
34
33
  content: [
35
34
  {
@@ -70,7 +69,7 @@ const makeGroupsSocket = (config) => {
70
69
  ...sock,
71
70
  groupMetadata,
72
71
  groupCreate: async (subject, participants) => {
73
- const key = (0, Utils_1.generateMessageID)();
72
+ const key = (0, Utils_1.generateMessageIDV2)();
74
73
  const result = await groupQuery('@g.us', 'set', [
75
74
  {
76
75
  tag: 'create',
@@ -91,9 +90,7 @@ const makeGroupsSocket = (config) => {
91
90
  {
92
91
  tag: 'leave',
93
92
  attrs: {},
94
- content: [
95
- { tag: 'group', attrs: { id } }
96
- ]
93
+ content: [{ tag: 'group', attrs: { id } }]
97
94
  }
98
95
  ]);
99
96
  },
@@ -118,7 +115,8 @@ const makeGroupsSocket = (config) => {
118
115
  return participants.map(v => v.attrs);
119
116
  },
120
117
  groupRequestParticipantsUpdate: async (jid, participants, action) => {
121
- const result = await groupQuery(jid, 'set', [{
118
+ const result = await groupQuery(jid, 'set', [
119
+ {
122
120
  tag: 'membership_requests_action',
123
121
  attrs: {},
124
122
  content: [
@@ -131,7 +129,8 @@ const makeGroupsSocket = (config) => {
131
129
  }))
132
130
  }
133
131
  ]
134
- }]);
132
+ }
133
+ ]);
135
134
  const node = (0, WABinary_1.getBinaryNodeChild)(result, 'membership_requests_action');
136
135
  const nodeAction = (0, WABinary_1.getBinaryNodeChild)(node, action);
137
136
  const participantsAffected = (0, WABinary_1.getBinaryNodeChildren)(nodeAction, 'participant');
@@ -157,36 +156,45 @@ const makeGroupsSocket = (config) => {
157
156
  });
158
157
  },
159
158
  groupUpdateDescription: async (jid, description) => {
160
- var _a;
161
159
  const metadata = await groupMetadata(jid);
162
- const prev = (_a = metadata.descId) !== null && _a !== void 0 ? _a : null;
160
+ const prev = metadata.descId ?? null;
163
161
  await groupQuery(jid, 'set', [
164
162
  {
165
163
  tag: 'description',
166
164
  attrs: {
167
- ...(description ? { id: (0, Utils_1.generateMessageID)() } : { delete: 'true' }),
165
+ ...(description ? { id: (0, Utils_1.generateMessageIDV2)() } : { delete: 'true' }),
168
166
  ...(prev ? { prev } : {})
169
167
  },
170
- content: description ? [
171
- { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
172
- ] : undefined
168
+ content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
173
169
  }
174
170
  ]);
175
171
  },
176
172
  groupInviteCode: async (jid) => {
177
173
  const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
178
174
  const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
179
- return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
175
+ return inviteNode?.attrs.code;
180
176
  },
181
177
  groupRevokeInvite: async (jid) => {
182
178
  const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
183
179
  const inviteNode = (0, WABinary_1.getBinaryNodeChild)(result, 'invite');
184
- return inviteNode === null || inviteNode === void 0 ? void 0 : inviteNode.attrs.code;
180
+ return inviteNode?.attrs.code;
185
181
  },
186
182
  groupAcceptInvite: async (code) => {
187
183
  const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
188
184
  const result = (0, WABinary_1.getBinaryNodeChild)(results, 'group');
189
- return result === null || result === void 0 ? void 0 : result.attrs.jid;
185
+ return result?.attrs.jid;
186
+ },
187
+ /**
188
+ * revoke a v4 invite for someone
189
+ * @param groupJid group jid
190
+ * @param invitedJid jid of person you invited
191
+ * @returns true if successful
192
+ */
193
+ groupRevokeInviteV4: async (groupJid, invitedJid) => {
194
+ const result = await groupQuery(groupJid, 'set', [
195
+ { tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
196
+ ]);
197
+ return !!result;
190
198
  },
191
199
  /**
192
200
  * accept a GroupInviteMessage
@@ -195,19 +203,21 @@ const makeGroupsSocket = (config) => {
195
203
  */
196
204
  groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
197
205
  key = typeof key === 'string' ? { remoteJid: key } : key;
198
- const results = await groupQuery(inviteMessage.groupJid, 'set', [{
206
+ const results = await groupQuery(inviteMessage.groupJid, 'set', [
207
+ {
199
208
  tag: 'accept',
200
209
  attrs: {
201
210
  code: inviteMessage.inviteCode,
202
211
  expiration: inviteMessage.inviteExpiration.toString(),
203
212
  admin: key.remoteJid
204
213
  }
205
- }]);
214
+ }
215
+ ]);
206
216
  // if we have the full message key
207
217
  // update the invite message to be expired
208
218
  if (key.id) {
209
219
  // create new invite message that is expired
210
- inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage);
220
+ inviteMessage = index_js_1.proto.Message.GroupInviteMessage.create(inviteMessage);
211
221
  inviteMessage.inviteExpiration = 0;
212
222
  inviteMessage.inviteCode = '';
213
223
  ev.emit('messages.update', [
@@ -225,14 +235,12 @@ const makeGroupsSocket = (config) => {
225
235
  await upsertMessage({
226
236
  key: {
227
237
  remoteJid: inviteMessage.groupJid,
228
- id: (0, Utils_1.generateMessageID)(),
238
+ id: (0, Utils_1.generateMessageIDV2)(sock.user?.id),
229
239
  fromMe: false,
230
- participant: key.remoteJid,
240
+ participant: key.remoteJid
231
241
  },
232
242
  messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
233
- messageStubParameters: [
234
- authState.creds.me.id
235
- ],
243
+ messageStubParameters: [authState.creds.me.id],
236
244
  participant: key.remoteJid,
237
245
  messageTimestamp: (0, Utils_1.unixTimestampSeconds)()
238
246
  }, 'notify');
@@ -243,9 +251,9 @@ const makeGroupsSocket = (config) => {
243
251
  return (0, exports.extractGroupMetadata)(results);
244
252
  },
245
253
  groupToggleEphemeral: async (jid, ephemeralExpiration) => {
246
- const content = ephemeralExpiration ?
247
- { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
248
- { tag: 'not_ephemeral', attrs: {} };
254
+ const content = ephemeralExpiration
255
+ ? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
256
+ : { tag: 'not_ephemeral', attrs: {} };
249
257
  await groupQuery(jid, 'set', [content]);
250
258
  },
251
259
  groupSettingUpdate: async (jid, setting) => {
@@ -255,58 +263,63 @@ const makeGroupsSocket = (config) => {
255
263
  await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
256
264
  },
257
265
  groupJoinApprovalMode: async (jid, mode) => {
258
- await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }]);
266
+ await groupQuery(jid, 'set', [
267
+ { tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }
268
+ ]);
259
269
  },
260
270
  groupFetchAllParticipating
261
271
  };
262
272
  };
263
273
  exports.makeGroupsSocket = makeGroupsSocket;
264
274
  const extractGroupMetadata = (result) => {
265
- var _a, _b;
266
- const group = WABinary_1.getBinaryNodeChild(result, 'group');
267
- const descChild = WABinary_1.getBinaryNodeChild(group, 'description');
275
+ const group = (0, WABinary_1.getBinaryNodeChild)(result, 'group');
276
+ const descChild = (0, WABinary_1.getBinaryNodeChild)(group, 'description');
268
277
  let desc;
269
278
  let descId;
270
279
  let descOwner;
271
- let descOwnerLid;
280
+ let descOwnerPn;
272
281
  let descTime;
273
282
  if (descChild) {
274
- desc = WABinary_1.getBinaryNodeChildString(descChild, 'body');
275
- descOwner = WABinary_1.jidNormalizedUser(descChild.attrs.participant_pn || descChild.attrs.participant);
276
- if (group.attrs.addressing_mode === 'lid') {
277
- descOwnerLid = WABinary_1.jidNormalizedUser(descChild.attrs.participant);
278
- }
283
+ desc = (0, WABinary_1.getBinaryNodeChildString)(descChild, 'body');
284
+ descOwner = descChild.attrs.participant ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant) : undefined;
285
+ descOwnerPn = descChild.attrs.participant_pn ? (0, WABinary_1.jidNormalizedUser)(descChild.attrs.participant_pn) : undefined;
286
+ descTime = +descChild.attrs.t;
279
287
  descId = descChild.attrs.id;
280
- descTime = descChild.attrs.t ? +descChild.attrs.t : undefined;
281
288
  }
282
- const groupSize = group.attrs.size ? Number(group.attrs.size) : undefined;
283
289
  const groupId = group.attrs.id.includes('@') ? group.attrs.id : (0, WABinary_1.jidEncode)(group.attrs.id, 'g.us');
284
- const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
285
- const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add';
290
+ const eph = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral')?.attrs.expiration;
291
+ const memberAddMode = (0, WABinary_1.getBinaryNodeChildString)(group, 'member_add_mode') === 'all_member_add';
286
292
  const metadata = {
287
293
  id: groupId,
288
- addressingMode: group.attrs.addressing_mode,
294
+ notify: group.attrs.notify,
295
+ addressingMode: group.attrs.addressing_mode === 'lid' ? Types_1.WAMessageAddressingMode.LID : Types_1.WAMessageAddressingMode.PN,
289
296
  subject: group.attrs.subject,
290
- subjectOwner: WABinary_1.jidNormalizedUser(group.attrs.s_o_pn || group.attrs.s_o),
291
- ...(group.attrs.addressing_mode === 'lid' ? { subjectOwnerLid: WABinary_1.jidNormalizedUser(group.attrs.s_o) } : {}),
292
- subjectTime: group.attrs.s_t ? +group.attrs.s_t : undefined,
293
- size: groupSize || WABinary_1.getBinaryNodeChildren(group, 'participant').length,
294
- creation: group.attrs.creation ? +group.attrs.creation : undefined,
295
- owner: WABinary_1.jidNormalizedUser(group.attrs.creator_pn || group.attrs.creator),
296
- ...(group.attrs.addressing_mode === 'lid' ? { ownerLid: WABinary_1.jidNormalizedUser(group.attrs.creator) } : {}),
297
+ subjectOwner: group.attrs.s_o,
298
+ subjectOwnerPn: group.attrs.s_o_pn,
299
+ subjectTime: +group.attrs.s_t,
300
+ size: group.attrs.size ? +group.attrs.size : (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').length,
301
+ creation: +group.attrs.creation,
302
+ owner: group.attrs.creator ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator) : undefined,
303
+ ownerPn: group.attrs.creator_pn ? (0, WABinary_1.jidNormalizedUser)(group.attrs.creator_pn) : undefined,
304
+ owner_country_code: group.attrs.creator_country_code,
305
+ desc,
306
+ descId,
297
307
  descOwner,
298
- descOwnerLid,
299
- restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
300
- announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
301
- isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
302
- isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
303
- joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
308
+ descOwnerPn,
309
+ descTime,
310
+ linkedParent: (0, WABinary_1.getBinaryNodeChild)(group, 'linked_parent')?.attrs.jid || undefined,
311
+ restrict: !!(0, WABinary_1.getBinaryNodeChild)(group, 'locked'),
312
+ announce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'announcement'),
313
+ isCommunity: !!(0, WABinary_1.getBinaryNodeChild)(group, 'parent'),
314
+ isCommunityAnnounce: !!(0, WABinary_1.getBinaryNodeChild)(group, 'default_sub_group'),
315
+ joinApprovalMode: !!(0, WABinary_1.getBinaryNodeChild)(group, 'membership_approval_mode'),
304
316
  memberAddMode,
305
- participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
317
+ participants: (0, WABinary_1.getBinaryNodeChildren)(group, 'participant').map(({ attrs }) => {
306
318
  return {
307
319
  id: attrs.jid,
308
- jid: attrs.phone_number || attrs.jid,
309
- admin: (attrs.type || null),
320
+ phoneNumber: (0, WABinary_1.isLidUser)(attrs.jid) && (0, WABinary_1.isPnUser)(attrs.phone_number) ? attrs.phone_number : undefined,
321
+ lid: (0, WABinary_1.isPnUser)(attrs.jid) && (0, WABinary_1.isLidUser)(attrs.lid) ? attrs.lid : undefined,
322
+ admin: (attrs.type || null)
310
323
  };
311
324
  }),
312
325
  ephemeralDuration: eph ? +eph : undefined
@@ -314,4 +327,3 @@ const extractGroupMetadata = (result) => {
314
327
  return metadata;
315
328
  };
316
329
  exports.extractGroupMetadata = extractGroupMetadata;
317
-