@neelegirl/baileys 1.5.3 → 1.5.5

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