sanka-baileyss 2.3.2 → 2.3.4

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 (159) hide show
  1. package/WAProto/BotMetadata/BotMetadata.d.ts +594 -1
  2. package/WAProto/BotMetadata/BotMetadata.js +1910 -148
  3. package/WAProto/BotMetadata/BotMetadata.proto +36 -0
  4. package/WAProto/E2E/E2E.d.ts +570 -6
  5. package/WAProto/E2E/E2E.js +1591 -26
  6. package/WAProto/E2E/E2E.proto +10 -1
  7. package/WAProto/HistorySync/HistorySync.d.ts +806 -6
  8. package/WAProto/HistorySync/HistorySync.js +2193 -29
  9. package/WAProto/HistorySync/HistorySync.proto +2 -1
  10. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +570 -6
  11. package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.js +1591 -26
  12. package/WAProto/StatusAttributions/StatusAttributions.d.ts +2 -1
  13. package/WAProto/StatusAttributions/StatusAttributions.js +7 -0
  14. package/WAProto/StatusAttributions/StatusAttributions.proto +1 -0
  15. package/WAProto/SyncAction/SyncAction.d.ts +230 -0
  16. package/WAProto/SyncAction/SyncAction.js +578 -2
  17. package/WAProto/SyncAction/SyncAction.proto +13 -1
  18. package/WAProto/Web/Web.d.ts +570 -6
  19. package/WAProto/Web/Web.js +1591 -26
  20. package/lib/Defaults/baileys-version.json +2 -2
  21. package/lib/Defaults/index.d.ts +42 -25
  22. package/lib/Defaults/index.js +6 -2
  23. package/lib/Signal/Group/sender-key-record.js +23 -28
  24. package/lib/Signal/libsignal.d.ts +1 -0
  25. package/lib/Socket/Client/index.js +13 -9
  26. package/lib/Socket/Client/types.d.ts +11 -10
  27. package/lib/Socket/Client/types.js +11 -7
  28. package/lib/Socket/Client/websocket.d.ts +9 -8
  29. package/lib/Socket/Client/websocket.js +52 -47
  30. package/lib/Socket/business.d.ts +185 -182
  31. package/lib/Socket/business.js +258 -249
  32. package/lib/Socket/chats.d.ts +90 -87
  33. package/lib/Socket/chats.js +1095 -888
  34. package/lib/Socket/community.d.ts +131 -0
  35. package/lib/Socket/community.js +369 -0
  36. package/lib/Socket/groups.d.ts +50 -41
  37. package/lib/Socket/groups.js +10 -3
  38. package/lib/Socket/index.d.ts +5 -1
  39. package/lib/Socket/index.js +19 -5
  40. package/lib/Socket/messages-recv.d.ts +6 -2
  41. package/lib/Socket/messages-recv.js +31 -8
  42. package/lib/Socket/messages-send.d.ts +5 -1
  43. package/lib/Socket/messages-send.js +1293 -1351
  44. package/lib/Socket/newsletter.d.ts +142 -135
  45. package/lib/Socket/newsletter.js +274 -230
  46. package/lib/Socket/socket.d.ts +37 -35
  47. package/lib/Socket/usync.d.ts +31 -30
  48. package/lib/Socket/usync.js +74 -62
  49. package/lib/Types/Auth.d.ts +89 -72
  50. package/lib/Types/Auth.js +1 -0
  51. package/lib/Types/Call.d.ts +11 -10
  52. package/lib/Types/Call.js +1 -0
  53. package/lib/Types/Chat.d.ts +85 -62
  54. package/lib/Types/Chat.js +4 -1
  55. package/lib/Types/Contact.js +1 -0
  56. package/lib/Types/Events.d.ts +209 -191
  57. package/lib/Types/Events.js +1 -0
  58. package/lib/Types/GroupMetadata.d.ts +12 -27
  59. package/lib/Types/GroupMetadata.js +1 -0
  60. package/lib/Types/Label.d.ts +41 -39
  61. package/lib/Types/Label.js +24 -21
  62. package/lib/Types/LabelAssociation.d.ts +18 -12
  63. package/lib/Types/LabelAssociation.js +6 -3
  64. package/lib/Types/Message.d.ts +3 -2
  65. package/lib/Types/Message.js +7 -3
  66. package/lib/Types/MexUpdates.d.ts +9 -0
  67. package/lib/Types/MexUpdates.js +18 -0
  68. package/lib/Types/Newsletter.d.ts +84 -67
  69. package/lib/Types/Newsletter.js +30 -23
  70. package/lib/Types/Product.d.ts +70 -56
  71. package/lib/Types/Product.js +1 -0
  72. package/lib/Types/Signal.d.ts +46 -35
  73. package/lib/Types/Signal.js +1 -0
  74. package/lib/Types/Socket.d.ts +105 -101
  75. package/lib/Types/Socket.js +1 -0
  76. package/lib/Types/State.d.ts +37 -23
  77. package/lib/Types/State.js +13 -1
  78. package/lib/Types/USync.d.ts +21 -20
  79. package/lib/Types/USync.js +1 -0
  80. package/lib/Types/index.d.ts +51 -42
  81. package/lib/Types/index.js +25 -19
  82. package/lib/Utils/auth-utils.d.ts +14 -11
  83. package/lib/Utils/auth-utils.js +189 -182
  84. package/lib/Utils/baileys-event-stream.d.ts +12 -10
  85. package/lib/Utils/baileys-event-stream.js +52 -46
  86. package/lib/Utils/business.d.ts +15 -8
  87. package/lib/Utils/business.js +229 -217
  88. package/lib/Utils/chat-utils.d.ts +22 -12
  89. package/lib/Utils/chat-utils.js +57 -27
  90. package/lib/Utils/crypto.d.ts +31 -15
  91. package/lib/Utils/crypto.js +136 -107
  92. package/lib/Utils/decode-wa-message.d.ts +34 -245
  93. package/lib/Utils/decode-wa-message.js +205 -217
  94. package/lib/Utils/event-buffer.d.ts +30 -26
  95. package/lib/Utils/event-buffer.js +519 -515
  96. package/lib/Utils/history.d.ts +2 -8
  97. package/lib/Utils/index.js +13 -9
  98. package/lib/Utils/link-preview.d.ts +16 -14
  99. package/lib/Utils/link-preview.js +100 -92
  100. package/lib/Utils/logger.d.ts +9 -7
  101. package/lib/Utils/logger.js +1 -1
  102. package/lib/Utils/lt-hash.d.ts +10 -8
  103. package/lib/Utils/lt-hash.js +49 -44
  104. package/lib/Utils/make-mutex.d.ts +4 -2
  105. package/lib/Utils/make-mutex.js +43 -39
  106. package/lib/Utils/messages-media.d.ts +75 -50
  107. package/lib/Utils/messages.d.ts +60 -35
  108. package/lib/Utils/messages.js +87 -8
  109. package/lib/Utils/noise-handler.d.ts +13 -12
  110. package/lib/Utils/noise-handler.js +143 -138
  111. package/lib/Utils/process-message.d.ts +32 -24
  112. package/lib/Utils/process-message.js +387 -367
  113. package/lib/Utils/signal.d.ts +24 -15
  114. package/lib/Utils/signal.js +143 -131
  115. package/lib/Utils/use-mongo-file-auth-state.d.ts +3 -2
  116. package/lib/Utils/use-mongo-file-auth-state.js +72 -63
  117. package/lib/Utils/use-multi-file-auth-state.d.ts +9 -8
  118. package/lib/Utils/use-multi-file-auth-state.js +110 -102
  119. package/lib/Utils/use-single-file-auth-state.d.ts +8 -7
  120. package/lib/Utils/use-single-file-auth-state.js +66 -61
  121. package/lib/Utils/validate-connection.d.ts +5 -2
  122. package/lib/Utils/validate-connection.js +7 -6
  123. package/lib/WABinary/constants.d.ts +24 -21
  124. package/lib/WABinary/constants.js +1302 -31
  125. package/lib/WABinary/decode.d.ts +4 -1
  126. package/lib/WABinary/decode.js +267 -234
  127. package/lib/WABinary/encode.d.ts +1 -0
  128. package/lib/WABinary/encode.js +248 -226
  129. package/lib/WABinary/generic-utils.d.ts +13 -1
  130. package/lib/WABinary/generic-utils.js +113 -96
  131. package/lib/WABinary/index.js +13 -9
  132. package/lib/WABinary/jid-utils.d.ts +23 -4
  133. package/lib/WABinary/jid-utils.js +58 -39
  134. package/lib/WABinary/types.d.ts +15 -11
  135. package/lib/WABinary/types.js +1 -0
  136. package/lib/WAM/BinaryInfo.d.ts +14 -14
  137. package/lib/WAM/BinaryInfo.js +11 -8
  138. package/lib/WAM/constants.d.ts +34 -26
  139. package/lib/WAM/constants.js +15358 -15349
  140. package/lib/WAM/encode.d.ts +1 -0
  141. package/lib/WAM/encode.js +153 -144
  142. package/lib/WAM/index.js +13 -9
  143. package/lib/index.js +11 -11
  144. package/package.json +1 -66
  145. package/WASignalGroup/GroupProtocol.js +0 -1771
  146. package/WASignalGroup/ciphertext_message.js +0 -10
  147. package/WASignalGroup/group_cipher.js +0 -103
  148. package/WASignalGroup/group_session_builder.js +0 -39
  149. package/WASignalGroup/index.js +0 -5
  150. package/WASignalGroup/keyhelper.js +0 -17
  151. package/WASignalGroup/protobufs.js +0 -2
  152. package/WASignalGroup/queue_job.js +0 -64
  153. package/WASignalGroup/sender_chain_key.js +0 -38
  154. package/WASignalGroup/sender_key_distribution_message.js +0 -68
  155. package/WASignalGroup/sender_key_message.js +0 -79
  156. package/WASignalGroup/sender_key_name.js +0 -59
  157. package/WASignalGroup/sender_key_record.js +0 -47
  158. package/WASignalGroup/sender_key_state.js +0 -110
  159. package/WASignalGroup/sender_message_key.js +0 -30
@@ -0,0 +1,131 @@
1
+ import { proto } from '../../WAProto'
2
+ import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction } from '../Types'
3
+ import { BinaryNode } from '../WABinary'
4
+
5
+ export declare const makeCommunitiesSocket: (config: SocketConfig) => {
6
+ communityQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
7
+ communityMetadata: (jid: string) => Promise<GroupMetadata>
8
+ communityCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>
9
+ communityLeave: (id: string) => Promise<void>
10
+ communityUpdateSubject: (jid: string, subject: string) => Promise<void>
11
+ communityRequestParticipantsList: (jid: string) => Promise<{
12
+ [key: string]: string
13
+ }[]>
14
+ communityRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
15
+ status: string
16
+ jid: string
17
+ }[]>
18
+ communityParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
19
+ status: string
20
+ jid: string
21
+ content: BinaryNode
22
+ }[]>
23
+ communityUpdateDescription: (jid: string, description?: string) => Promise<void>
24
+ communityInviteCode: (jid: string) => Promise<string | undefined>
25
+ communityRevokeInvite: (jid: string) => Promise<string | undefined>
26
+ communityAcceptInvite: (code: string) => Promise<string | undefined>
27
+ /**
28
+ * revoke a v4 invite for someone
29
+ * @param communityJid community jid
30
+ * @param invitedJid jid of person you invited
31
+ * @returns true if successful
32
+ */
33
+ communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>
34
+ /**
35
+ * accept a GroupInviteMessage
36
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
37
+ * @param inviteMessage the message to accept
38
+ */
39
+ communityAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>
40
+ communityGetInviteInfo: (code: string) => Promise<GroupMetadata>
41
+ communityToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
42
+ communitySettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>
43
+ communityMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>
44
+ communityJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>
45
+ communityFetchAllParticipating: () => Promise<{
46
+ [_: string]: GroupMetadata
47
+ }>
48
+ processingMutex: {
49
+ mutex<T>(code: () => T | Promise<T>): Promise<T>
50
+ }
51
+ fetchPrivacySettings: (force?: boolean) => Promise<{
52
+ [_: string]: string
53
+ }>
54
+ upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
55
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
56
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
57
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
58
+ getLidUser: (jid: string) => Promise<{
59
+ lid: string
60
+ id: string
61
+ }[] | undefined>
62
+ onWhatsApp: (...jids: string[]) => Promise<{
63
+ jid: string
64
+ exists: unknown
65
+ }[] | undefined>
66
+ fetchBlocklist: () => Promise<string[]>
67
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
68
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
69
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
70
+ removeProfilePicture: (jid: string) => Promise<void>
71
+ updateProfileStatus: (status: string) => Promise<void>
72
+ updateProfileName: (name: string) => Promise<void>
73
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
74
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
75
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
76
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
77
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
78
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
79
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
80
+ updatecommunitysAddPrivacy: (value: import("../Types").WAPrivacycommunityAddValue) => Promise<void>
81
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>
82
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>
83
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
84
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
85
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
86
+ cleanDirtyBits: (type: "account_sync" | "communitys", fromTimestamp?: string | number | undefined) => Promise<void>
87
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>
88
+ addChatLabel: (jid: string, labelId: string) => Promise<void>
89
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>
90
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
91
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
92
+ clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
93
+ star: (jid: string, messages: {
94
+ id: string
95
+ fromMe?: boolean | undefined
96
+ }[], star: boolean) => Promise<void>
97
+ addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>
98
+ removeContact: (jid: string) => Promise<void>
99
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>
100
+ type: "md"
101
+ ws: import("./Client").WebSocketClient
102
+ ev: import("../Types").BaileysEventEmitter & {
103
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
104
+ buffer(): void
105
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
106
+ flush(force?: boolean | undefined): boolean
107
+ isBuffering(): boolean
108
+ }
109
+ authState: {
110
+ creds: import("../Types").AuthenticationCreds
111
+ keys: import("../Types").SignalKeyStoreWithTransaction
112
+ }
113
+ signalRepository: import("../Types").SignalRepository
114
+ user: import("../Types").Contact | undefined
115
+ generateMessageTag: () => string
116
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
117
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
118
+ waitForSocketOpen: () => Promise<void>
119
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
120
+ sendNode: (frame: BinaryNode) => Promise<void>
121
+ logout: (msg?: string | undefined) => Promise<void>
122
+ end: (error: Error | undefined) => void
123
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
124
+ uploadPreKeys: (count?: number) => Promise<void>
125
+ uploadPreKeysToServerIfRequired: () => Promise<void>
126
+ requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
127
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
128
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
129
+ }
130
+
131
+ export declare const extractCommunityMetadata: (result: BinaryNode) => GroupMetadata
@@ -0,0 +1,369 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+
4
+ const WAProto_1 = require("../../WAProto")
5
+ const Types_1 = require("../Types")
6
+ const Utils_1 = require("../Utils")
7
+ const WABinary_1 = require("../WABinary")
8
+ const business_1 = require("./business")
9
+
10
+ const makeCommunitiesSocket = (config) => {
11
+ const suki = business_1.makeBusinessSocket(config)
12
+ const { authState, ev, query, groupMetadata, upsertMessage } = suki
13
+
14
+ const communityQuery = async (jid, type, content) => (query({
15
+ tag: 'iq',
16
+ attrs: {
17
+ type,
18
+ xmlns: 'w:g2',
19
+ to: jid,
20
+ },
21
+ content
22
+ }))
23
+
24
+ const communityMetadata = async (jid) => {
25
+ const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
26
+ return extractCommunityMetadata(result)
27
+ }
28
+
29
+ const communityFetchAllParticipating = async () => {
30
+ const result = await query({
31
+ tag: 'iq',
32
+ attrs: {
33
+ to: '@g.us',
34
+ xmlns: 'w:g2',
35
+ type: 'get',
36
+ },
37
+ content: [
38
+ {
39
+ tag: 'participating',
40
+ attrs: {},
41
+ content: [
42
+ { tag: 'participants', attrs: {} },
43
+ { tag: 'description', attrs: {} }
44
+ ]
45
+ }
46
+ ]
47
+ })
48
+
49
+ const data = {}
50
+ const communitiesChild = WABinary_1.getBinaryNodeChild(result, 'communities')
51
+
52
+ if (communitiesChild) {
53
+ const communities = WABinary_1.getBinaryNodeChildren(communitiesChild, 'community')
54
+ for (const communityNode of communities) {
55
+ const meta = extractCommunityMetadata({
56
+ tag: 'result',
57
+ attrs: {},
58
+ content: [communityNode]
59
+ })
60
+ data[meta.id] = meta
61
+ }
62
+ }
63
+
64
+ suki.ev.emit('groups.update', Object.values(data))
65
+ return data
66
+ }
67
+
68
+ suki.ws.on('CB:ib,,dirty', async (node) => {
69
+ const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
70
+
71
+ if (attrs.type !== 'communities') {
72
+ return
73
+ }
74
+
75
+ await communityFetchAllParticipating()
76
+ await suki.cleanDirtyBits('groups')
77
+ })
78
+
79
+ return {
80
+ ...suki,
81
+ communityQuery,
82
+ communityMetadata,
83
+ communityCreate: async (subject, body) => {
84
+ const descriptionId = Utils_1.generateMessageID().substring(0, 12)
85
+
86
+ const result = await communityQuery('@g.us', 'set', [
87
+ {
88
+ tag: 'create',
89
+ attrs: { subject },
90
+ content: [{
91
+ tag: 'description',
92
+ attrs: {
93
+ id: descriptionId
94
+ },
95
+ content: [{
96
+ tag: 'body',
97
+ attrs: {},
98
+ content: Buffer.from(body || '', 'utf-8')
99
+ }]
100
+ },
101
+ {
102
+ tag: 'parent',
103
+ attrs: {
104
+ default_membership_approval_mode: 'request_required'
105
+ }
106
+ },
107
+ {
108
+ tag: 'allow_non_admin_sub_group_creation',
109
+ attrs: {}
110
+ },
111
+ {
112
+ tag: 'create_general_chat',
113
+ attrs: {}
114
+ }]
115
+ }
116
+ ])
117
+
118
+ return extractCommunityMetadata(result)
119
+ },
120
+ communityLeave: async (id) => {
121
+ await communityQuery('@g.us', 'set', [
122
+ {
123
+ tag: 'leave',
124
+ attrs: {},
125
+ content: [
126
+ { tag: 'community', attrs: { id } }
127
+ ]
128
+ }
129
+ ])
130
+ },
131
+ communityUpdateSubject: async (jid, subject) => {
132
+ await communityQuery(jid, 'set', [
133
+ {
134
+ tag: 'subject',
135
+ attrs: {},
136
+ content: Buffer.from(subject, 'utf-8')
137
+ }
138
+ ])
139
+ },
140
+ communityRequestParticipantsList: async (jid) => {
141
+ const result = await communityQuery(jid, 'get', [
142
+ {
143
+ tag: 'membership_approval_requests',
144
+ attrs: {}
145
+ }
146
+ ])
147
+
148
+ const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
149
+ const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
150
+
151
+ return participants.map(v => v.attrs)
152
+ },
153
+ communityRequestParticipantsUpdate: async (jid, participants, action) => {
154
+ const result = await communityQuery(jid, 'set', [{
155
+ tag: 'membership_requests_action',
156
+ attrs: {},
157
+ content: [
158
+ {
159
+ tag: action,
160
+ attrs: {},
161
+ content: participants.map(jid => ({
162
+ tag: 'participant',
163
+ attrs: { jid }
164
+ }))
165
+ }
166
+ ]
167
+ }])
168
+
169
+ const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
170
+ const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
171
+ const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
172
+
173
+ return participantsAffected.map(p => {
174
+ return { status: p.attrs.error || '200', jid: p.attrs.jid }
175
+ })
176
+ },
177
+ communityParticipantsUpdate: async (jid, participants, action) => {
178
+ const result = await communityQuery(jid, 'set', [
179
+ {
180
+ tag: action,
181
+ attrs: {},
182
+ content: participants.map(jid => ({
183
+ tag: 'participant',
184
+ attrs: { jid }
185
+ }))
186
+ }
187
+ ])
188
+ const node = WABinary_1.getBinaryNodeChild(result, action)
189
+ const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
190
+
191
+ return participantsAffected.map(p => {
192
+ return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
193
+ })
194
+ },
195
+ communityUpdateDescription: async (jid, description) => {
196
+ const metadata = await communityMetadata(jid)
197
+ const prev = metadata.descId ? metadata.descId : null
198
+
199
+ await communityQuery(jid, 'set', [
200
+ {
201
+ tag: 'description',
202
+ attrs: {
203
+ ...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
204
+ ...(prev ? { prev } : {})
205
+ },
206
+ content: description ? [
207
+ { tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
208
+ ] : undefined
209
+ }
210
+ ])
211
+ },
212
+ communityInviteCode: async (jid) => {
213
+ const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
214
+ const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
215
+
216
+ return inviteNode?.attrs?.code
217
+ },
218
+ communityRevokeInvite: async (jid) => {
219
+ const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
220
+ const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
221
+
222
+ return inviteNode?.attrs?.code
223
+ },
224
+ communityAcceptInvite: async (code) => {
225
+ const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
226
+ const result = WABinary_1.getBinaryNodeChild(results, 'community')
227
+
228
+ return result?.attrs?.jid
229
+ },
230
+ /**
231
+ * revoke a v4 invite for someone
232
+ * @param communityJid community jid
233
+ * @param invitedJid jid of person you invited
234
+ * @returns true if successful
235
+ */
236
+ communityRevokeInviteV4: async (communityJid, invitedJid) => {
237
+ const result = await communityQuery(communityJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
238
+
239
+ return !!result
240
+ },
241
+ /**
242
+ * accept a GroupInviteMessage
243
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
244
+ * @param inviteMessage the message to accept
245
+ */
246
+ communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
247
+ key = typeof key === 'string' ? { remoteJid: key } : key
248
+ const results = await communityQuery(inviteMessage.groupJid, 'set', [{
249
+ tag: 'accept',
250
+ attrs: {
251
+ code: inviteMessage.inviteCode,
252
+ expiration: inviteMessage.inviteExpiration.toString(),
253
+ admin: key.remoteJid
254
+ }
255
+ }])
256
+
257
+ // if we have the full message key
258
+ // update the invite message to be expired
259
+ if (key.id) {
260
+ // create new invite message that is expired
261
+ inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
262
+ inviteMessage.inviteExpiration = 0
263
+ inviteMessage.inviteCode = ''
264
+ ev.emit('messages.update', [
265
+ {
266
+ key,
267
+ update: {
268
+ message: {
269
+ groupInviteMessage: inviteMessage
270
+ }
271
+ }
272
+ }
273
+ ])
274
+ }
275
+
276
+ // generate the group add message
277
+ await upsertMessage({
278
+ key: {
279
+ remoteJid: inviteMessage.groupJid,
280
+ id: Utils_1.generateMessageID(authState.creds.me?.id),
281
+ fromMe: false,
282
+ participant: key.remoteJid,
283
+ },
284
+ messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
285
+ messageStubParameters: [
286
+ authState.creds.me.id
287
+ ],
288
+ participant: key.remoteJid,
289
+ messageTimestamp: Utils_1.unixTimestampSeconds()
290
+ }, 'notify')
291
+
292
+ return results.attrs.from
293
+ }),
294
+ communityGetInviteInfo: async (code) => {
295
+ const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
296
+
297
+ return extractCommunityMetadata(results)
298
+ },
299
+ communityToggleEphemeral: async (jid, ephemeralExpiration) => {
300
+ const content = ephemeralExpiration ?
301
+ { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
302
+ { tag: 'not_ephemeral', attrs: {} }
303
+ await communityQuery(jid, 'set', [content])
304
+ },
305
+ communitySettingUpdate: async (jid, setting) => {
306
+ await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }])
307
+ },
308
+ communityMemberAddMode: async (jid, mode) => {
309
+ await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
310
+ },
311
+ communityJoinApprovalMode: async (jid, mode) => {
312
+ await communityQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }])
313
+ },
314
+ communityFetchAllParticipating
315
+ }
316
+ }
317
+
318
+ const extractCommunityMetadata = (result) => {
319
+ const community = WABinary_1.getBinaryNodeChild(result, 'group')
320
+ const descChild = WABinary_1.getBinaryNodeChild(community, 'description')
321
+
322
+ let desc
323
+ let descId
324
+
325
+ if (descChild) {
326
+ desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
327
+ descId = descChild.attrs.id
328
+ }
329
+
330
+ const mode = community.attrs.addressing_mode
331
+ const communityId = community.attrs.id.includes('@') ? community.attrs.id : WABinary_1.jidEncode(community.attrs.id, 'g.us')
332
+ const eph = WABinary_1.getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration
333
+ const memberAddMode = WABinary_1.getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add'
334
+
335
+ const metadata = {
336
+ id: communityId,
337
+ addressingMode: mode,
338
+ subject: community.attrs.subject,
339
+ subjectOwner: mode === 'lid' ? community.attrs.s_o_pn : community.attrs.s_o,
340
+ subjectTime: +community.attrs.s_t,
341
+ size: community.attrs?.size ? +community.attrs.size : WABinary_1.getBinaryNodeChildren(community, 'participant').length,
342
+ creation: +community.attrs.creation,
343
+ owner: community.attrs.creator ? WABinary_1.jidNormalizedUser(mode === 'lid' ? community.attrs.creator_pn : community.attrs.creator) : undefined,
344
+ desc,
345
+ descId,
346
+ linkedParent: WABinary_1.getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
347
+ restrict: !!WABinary_1.getBinaryNodeChild(community, 'locked'),
348
+ announce: !!WABinary_1.getBinaryNodeChild(community, 'announcement'),
349
+ isCommunity: !!WABinary_1.getBinaryNodeChild(community, 'parent'),
350
+ isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(community, 'default_sub_group'),
351
+ joinApprovalMode: !!WABinary_1.getBinaryNodeChild(community, 'membership_approval_mode'),
352
+ memberAddMode,
353
+ participants: WABinary_1.getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
354
+ return {
355
+ id: mode === 'lid' ? community.phone_number : attrs.jid,
356
+ lid: mode === 'lid' ? community.jid : attrs.lid,
357
+ admin: (attrs.type || null),
358
+ }
359
+ }),
360
+ ephemeralDuration: eph ? +eph : undefined,
361
+ }
362
+
363
+ return metadata
364
+ }
365
+
366
+ module.exports = {
367
+ makeCommunitiesSocket,
368
+ extractCommunityMetadata
369
+ }
@@ -1,7 +1,6 @@
1
1
  import { proto } from '../../WAProto'
2
- import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction, WAPrivacyValue, WAPrivacyOnlineValue, WAPrivacyCallValue, WAReadReceiptsValue, WAPrivacyGroupAddValue, WABusinessProfile, WAMessageStubType, MessageUpsertType, WAPresence, WAMediaUpload, USyncQuery, USyncQueryResult, USyncQueryResultList } from '../Types'
2
+ import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction } from '../Types'
3
3
  import { BinaryNode } from '../WABinary'
4
- import { BaileysEventEmitter, AuthenticationCreds, SignalKeyStoreWithTransaction, SignalRepository, Contact, ChatModification, LabelActionBody } from '../Types'
5
4
 
6
5
  export declare const makeGroupsSocket: (config: SocketConfig) => {
7
6
  groupQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
@@ -25,7 +24,18 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
25
24
  groupInviteCode: (jid: string) => Promise<string | undefined>
26
25
  groupRevokeInvite: (jid: string) => Promise<string | undefined>
27
26
  groupAcceptInvite: (code: string) => Promise<string | undefined>
27
+ /**
28
+ * revoke a v4 invite for someone
29
+ * @param groupJid group jid
30
+ * @param invitedJid jid of person you invited
31
+ * @returns true if successful
32
+ */
28
33
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>
34
+ /**
35
+ * accept a GroupInviteMessage
36
+ * @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
37
+ * @param inviteMessage the message to accept
38
+ */
29
39
  groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>
30
40
  groupGetInviteInfo: (code: string) => Promise<GroupMetadata>
31
41
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
@@ -41,81 +51,80 @@ export declare const makeGroupsSocket: (config: SocketConfig) => {
41
51
  fetchPrivacySettings: (force?: boolean) => Promise<{
42
52
  [_: string]: string
43
53
  }>
44
- upsertMessage: (msg: proto.IWebMessageInfo, type: MessageUpsertType) => Promise<void>
45
- appPatch: (patchCreate: WAPatchCreate) => Promise<void>
46
- sendPresenceUpdate: (type: WAPresence, toJid?: string) => Promise<void>
47
- presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>
54
+ upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
55
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
56
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
57
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
48
58
  getLidUser: (jid: string) => Promise<{
49
- lid: string
59
+ lid: string
50
60
  id: string
51
61
  }[] | undefined>
52
62
  onWhatsApp: (...jids: string[]) => Promise<{
53
63
  jid: string
54
- exists: boolean
64
+ exists: unknown
55
65
  }[] | undefined>
56
66
  fetchBlocklist: () => Promise<string[]>
57
- fetchStatus: (...jids: string[]) => Promise<USyncQueryResultList[] | undefined>
58
- fetchDisappearingDuration: (...jids: string[]) => Promise<USyncQueryResultList[] | undefined>
59
- updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>
67
+ fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
68
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
69
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
60
70
  removeProfilePicture: (jid: string) => Promise<void>
61
71
  updateProfileStatus: (status: string) => Promise<void>
62
72
  updateProfileName: (name: string) => Promise<void>
63
73
  updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
64
- updateCallPrivacy: (value: WAPrivacyCallValue) => Promise<void>
65
- updateLastSeenPrivacy: (value: WAPrivacyValue) => Promise<void>
66
- updateOnlinePrivacy: (value: WAPrivacyOnlineValue) => Promise<void>
67
- updateProfilePicturePrivacy: (value: WAPrivacyValue) => Promise<void>
68
- updateStatusPrivacy: (value: WAPrivacyValue) => Promise<void>
69
- updateReadReceiptsPrivacy: (value: WAReadReceiptsValue) => Promise<void>
70
- updateGroupsAddPrivacy: (value: WAPrivacyGroupAddValue) => Promise<void>
74
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
75
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
76
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
77
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
78
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
79
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
80
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>
71
81
  updateDefaultDisappearingMode: (duration: number) => Promise<void>
72
- getBusinessProfile: (jid: string) => Promise<void | WABusinessProfile>
82
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>
83
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
73
84
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
74
- chatModify: (mod: ChatModification, jid: string) => Promise<void>
75
- cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number) => Promise<void>
76
- addLabel: (jid: string, labels: LabelActionBody) => Promise<void>
85
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
86
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>
87
+ addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>
77
88
  addChatLabel: (jid: string, labelId: string) => Promise<void>
78
89
  removeChatLabel: (jid: string, labelId: string) => Promise<void>
79
90
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
80
91
  removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
81
- clearMessage: (jid: string, key: proto.IMessageKey, timeStamp: number | Long) => Promise<void>
92
+ clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
82
93
  star: (jid: string, messages: {
83
94
  id: string
84
- fromMe?: boolean
95
+ fromMe?: boolean | undefined
85
96
  }[], star: boolean) => Promise<void>
86
97
  addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>
87
98
  removeContact: (jid: string) => Promise<void>
88
- executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<USyncQueryResult | undefined>
89
-
90
- // Socket properties
99
+ executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>
91
100
  type: "md"
92
- ws: any // WebSocketClient type would need to be imported/defined
93
- ev: BaileysEventEmitter & {
94
- process(handler: (events: Partial<BaileysEventMap>) => void | Promise<void>): () => void
101
+ ws: import("./Client").WebSocketClient
102
+ ev: import("../Types").BaileysEventEmitter & {
103
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
95
104
  buffer(): void
96
- createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>
97
- flush(force?: boolean): boolean
105
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
106
+ flush(force?: boolean | undefined): boolean
98
107
  isBuffering(): boolean
99
108
  }
100
109
  authState: {
101
- creds: AuthenticationCreds
102
- keys: SignalKeyStoreWithTransaction
110
+ creds: import("../Types").AuthenticationCreds
111
+ keys: import("../Types").SignalKeyStoreWithTransaction
103
112
  }
104
- signalRepository: SignalRepository
105
- user: Contact | undefined
113
+ signalRepository: import("../Types").SignalRepository
114
+ user: import("../Types").Contact | undefined
106
115
  generateMessageTag: () => string
107
- query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>
108
- waitForMessage: <T>(msgId: string, timeoutMs?: number) => Promise<T>
116
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
117
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
109
118
  waitForSocketOpen: () => Promise<void>
110
119
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
111
120
  sendNode: (frame: BinaryNode) => Promise<void>
112
- logout: (msg?: string) => Promise<void>
121
+ logout: (msg?: string | undefined) => Promise<void>
113
122
  end: (error: Error | undefined) => void
114
- onUnexpectedError: (err: Error | Boom<any>, msg: string) => void
123
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
115
124
  uploadPreKeys: (count?: number) => Promise<void>
116
125
  uploadPreKeysToServerIfRequired: () => Promise<void>
117
126
  requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
118
- waitForConnectionUpdate: (check: (u: Partial<ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>
127
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
119
128
  sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
120
129
  }
121
130