@hbmodsofc/baileys 1.7.8 → 2.2.0

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