@neelegirl/baileys 1.5.5 → 1.5.7

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 (203) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +183 -10
  3. package/WAProto/WAProto.proto +5007 -0
  4. package/WAProto/index.d.ts +57712 -0
  5. package/WAProto/index.js +178969 -0
  6. package/lib/Defaults/baileys-version.json +3 -0
  7. package/lib/Defaults/index.d.ts +68 -0
  8. package/lib/Defaults/index.js +137 -0
  9. package/lib/Defaults/phonenumber-mcc.json +223 -0
  10. package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
  11. package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
  12. package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
  13. package/lib/Signal/WASignalGroup/group.proto +42 -0
  14. package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
  15. package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
  16. package/lib/Signal/WASignalGroup/index.js +6 -0
  17. package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
  18. package/lib/Signal/WASignalGroup/protobufs.js +3 -0
  19. package/lib/Signal/WASignalGroup/queue_job.js +69 -0
  20. package/lib/Signal/WASignalGroup/readme.md +6 -0
  21. package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
  22. package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
  23. package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
  24. package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
  25. package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
  26. package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
  27. package/lib/Signal/WASignalGroup/sender_message_key.js +39 -0
  28. package/lib/Signal/libsignal.d.ts +4 -0
  29. package/lib/Signal/libsignal.js +162 -0
  30. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  31. package/lib/Socket/Client/abstract-socket-client.js +13 -0
  32. package/lib/Socket/Client/index.d.ts +2 -0
  33. package/lib/Socket/Client/index.js +22 -0
  34. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  35. package/lib/Socket/Client/mobile-socket-client.js +65 -0
  36. package/lib/Socket/Client/types.d.ts +16 -0
  37. package/lib/Socket/Client/types.js +18 -0
  38. package/lib/Socket/Client/websocket.d.ts +13 -0
  39. package/lib/Socket/Client/websocket.js +62 -0
  40. package/lib/Socket/business.d.ts +187 -0
  41. package/lib/Socket/business.js +268 -0
  42. package/lib/Socket/chats.d.ts +98 -0
  43. package/lib/Socket/chats.js +1113 -0
  44. package/lib/Socket/communities.d.ts +223 -0
  45. package/lib/Socket/communities.js +433 -0
  46. package/lib/Socket/groups.d.ts +131 -0
  47. package/lib/Socket/groups.js +352 -0
  48. package/lib/Socket/index.d.ts +191 -0
  49. package/lib/Socket/index.js +23 -0
  50. package/lib/Socket/messages-recv.d.ts +177 -0
  51. package/lib/Socket/messages-recv.js +1764 -0
  52. package/lib/Socket/messages-send.d.ts +168 -0
  53. package/lib/Socket/messages-send.js +1303 -0
  54. package/lib/Socket/mex.d.ts +2 -0
  55. package/lib/Socket/mex.js +47 -0
  56. package/lib/Socket/newsletter.d.ts +147 -0
  57. package/lib/Socket/newsletter.js +286 -0
  58. package/lib/Socket/registration.d.ts +266 -0
  59. package/lib/Socket/registration.js +166 -0
  60. package/lib/Socket/socket.d.ts +45 -0
  61. package/lib/Socket/socket.js +766 -0
  62. package/lib/Socket/usync.d.ts +37 -0
  63. package/lib/Socket/usync.js +83 -0
  64. package/lib/Store/index.d.ts +4 -0
  65. package/lib/Store/index.js +24 -0
  66. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  67. package/lib/Store/make-cache-manager-store.js +90 -0
  68. package/lib/Store/make-in-memory-store.d.ts +123 -0
  69. package/lib/Store/make-in-memory-store.js +429 -0
  70. package/lib/Store/make-ordered-dictionary.d.ts +12 -0
  71. package/lib/Store/make-ordered-dictionary.js +86 -0
  72. package/lib/Store/object-repository.d.ts +10 -0
  73. package/lib/Store/object-repository.js +31 -0
  74. package/lib/Types/Auth.d.ts +120 -0
  75. package/lib/Types/Auth.js +3 -0
  76. package/lib/Types/Call.d.ts +14 -0
  77. package/lib/Types/Call.js +3 -0
  78. package/lib/Types/Chat.d.ts +138 -0
  79. package/lib/Types/Chat.js +9 -0
  80. package/lib/Types/Contact.d.ts +20 -0
  81. package/lib/Types/Contact.js +3 -0
  82. package/lib/Types/Events.d.ts +229 -0
  83. package/lib/Types/Events.js +3 -0
  84. package/lib/Types/GroupMetadata.d.ts +66 -0
  85. package/lib/Types/GroupMetadata.js +3 -0
  86. package/lib/Types/Label.d.ts +48 -0
  87. package/lib/Types/Label.js +31 -0
  88. package/lib/Types/LabelAssociation.d.ts +35 -0
  89. package/lib/Types/LabelAssociation.js +13 -0
  90. package/lib/Types/Message.d.ts +473 -0
  91. package/lib/Types/Message.js +13 -0
  92. package/lib/Types/MexUpdates.d.ts +9 -0
  93. package/lib/Types/MexUpdates.js +18 -0
  94. package/lib/Types/Newsletter.d.ts +109 -0
  95. package/lib/Types/Newsletter.js +40 -0
  96. package/lib/Types/Product.d.ts +92 -0
  97. package/lib/Types/Product.js +3 -0
  98. package/lib/Types/Signal.d.ts +68 -0
  99. package/lib/Types/Signal.js +3 -0
  100. package/lib/Types/Socket.d.ts +122 -0
  101. package/lib/Types/Socket.js +3 -0
  102. package/lib/Types/State.d.ts +41 -0
  103. package/lib/Types/State.js +14 -0
  104. package/lib/Types/USync.d.ts +26 -0
  105. package/lib/Types/USync.js +3 -0
  106. package/lib/Types/index.d.ts +79 -0
  107. package/lib/Types/index.js +48 -0
  108. package/lib/Utils/auth-utils.d.ts +21 -0
  109. package/lib/Utils/auth-utils.js +205 -0
  110. package/lib/Utils/baileys-event-stream.d.ts +18 -0
  111. package/lib/Utils/baileys-event-stream.js +70 -0
  112. package/lib/Utils/business.d.ts +29 -0
  113. package/lib/Utils/business.js +255 -0
  114. package/lib/Utils/chat-utils.d.ts +82 -0
  115. package/lib/Utils/chat-utils.js +781 -0
  116. package/lib/Utils/check-npm-version.d.ts +15 -0
  117. package/lib/Utils/check-npm-version.js +52 -0
  118. package/lib/Utils/crypto.d.ts +56 -0
  119. package/lib/Utils/crypto.js +179 -0
  120. package/lib/Utils/decode-wa-message.d.ts +41 -0
  121. package/lib/Utils/decode-wa-message.js +253 -0
  122. package/lib/Utils/event-buffer.d.ts +39 -0
  123. package/lib/Utils/event-buffer.js +565 -0
  124. package/lib/Utils/generics.d.ts +129 -0
  125. package/lib/Utils/generics.js +618 -0
  126. package/lib/Utils/history.d.ts +23 -0
  127. package/lib/Utils/history.js +110 -0
  128. package/lib/Utils/index.d.ts +19 -0
  129. package/lib/Utils/index.js +41 -0
  130. package/lib/Utils/link-preview.d.ts +23 -0
  131. package/lib/Utils/link-preview.js +120 -0
  132. package/lib/Utils/logger.d.ts +13 -0
  133. package/lib/Utils/logger.js +7 -0
  134. package/lib/Utils/lt-hash.d.ts +14 -0
  135. package/lib/Utils/lt-hash.js +58 -0
  136. package/lib/Utils/make-mutex.d.ts +9 -0
  137. package/lib/Utils/make-mutex.js +49 -0
  138. package/lib/Utils/message-retry-manager.d.ts +82 -0
  139. package/lib/Utils/message-retry-manager.js +177 -0
  140. package/lib/Utils/messages-media.d.ts +129 -0
  141. package/lib/Utils/messages-media.js +806 -0
  142. package/lib/Utils/messages.d.ts +103 -0
  143. package/lib/Utils/messages.js +1579 -0
  144. package/lib/Utils/noise-handler.d.ts +20 -0
  145. package/lib/Utils/noise-handler.js +155 -0
  146. package/lib/Utils/process-message.d.ts +49 -0
  147. package/lib/Utils/process-message.js +428 -0
  148. package/lib/Utils/signal.d.ts +42 -0
  149. package/lib/Utils/signal.js +166 -0
  150. package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
  151. package/lib/Utils/use-mongo-file-auth-state.js +84 -0
  152. package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
  153. package/lib/Utils/use-multi-file-auth-state.js +238 -0
  154. package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
  155. package/lib/Utils/use-single-file-auth-state.js +80 -0
  156. package/lib/Utils/validate-connection.d.ts +13 -0
  157. package/lib/Utils/validate-connection.js +187 -0
  158. package/lib/WABinary/constants.d.ts +30 -0
  159. package/lib/WABinary/constants.js +1316 -0
  160. package/lib/WABinary/decode.d.ts +9 -0
  161. package/lib/WABinary/decode.js +288 -0
  162. package/lib/WABinary/encode.d.ts +3 -0
  163. package/lib/WABinary/encode.js +265 -0
  164. package/lib/WABinary/generic-utils.d.ts +28 -0
  165. package/lib/WABinary/generic-utils.js +142 -0
  166. package/lib/WABinary/index.d.ts +5 -0
  167. package/lib/WABinary/index.js +25 -0
  168. package/lib/WABinary/jid-utils.d.ts +53 -0
  169. package/lib/WABinary/jid-utils.js +92 -0
  170. package/lib/WABinary/types.d.ts +22 -0
  171. package/lib/WABinary/types.js +3 -0
  172. package/lib/WAM/BinaryInfo.d.ts +16 -0
  173. package/lib/WAM/BinaryInfo.js +17 -0
  174. package/lib/WAM/constants.d.ts +47 -0
  175. package/lib/WAM/constants.js +15371 -0
  176. package/lib/WAM/encode.d.ts +3 -0
  177. package/lib/WAM/encode.js +165 -0
  178. package/lib/WAM/index.d.ts +3 -0
  179. package/lib/WAM/index.js +23 -0
  180. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
  181. package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
  182. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
  183. package/lib/WAUSync/Protocols/USyncContactProtocol.js +36 -0
  184. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
  185. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
  186. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
  187. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
  188. package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
  189. package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
  190. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
  191. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
  192. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  193. package/lib/WAUSync/Protocols/index.js +26 -0
  194. package/lib/WAUSync/USyncQuery.d.ts +31 -0
  195. package/lib/WAUSync/USyncQuery.js +92 -0
  196. package/lib/WAUSync/USyncUser.d.ts +12 -0
  197. package/lib/WAUSync/USyncUser.js +30 -0
  198. package/lib/WAUSync/index.d.ts +3 -0
  199. package/lib/WAUSync/index.js +23 -0
  200. package/lib/index.d.ts +13 -0
  201. package/lib/index.js +33 -0
  202. package/package.json +88 -10
  203. package/index.js +0 -38
@@ -0,0 +1,2 @@
1
+ import type { BinaryNode } from '../WABinary/index.js';
2
+ export declare const executeWMexQuery: <T>(variables: Record<string, unknown>, queryId: string, dataPath: string, query: (node: BinaryNode) => Promise<BinaryNode>, generateMessageTag: () => string) => Promise<T>;
@@ -0,0 +1,47 @@
1
+ "use strict"
2
+ Object.defineProperty(exports, "__esModule", { value: true })
3
+
4
+ const { Boom } = require("@hapi/boom")
5
+ const { getBinaryNodeChild, S_WHATSAPP_NET }= require("../WABinary/index.js")
6
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
7
+ return query({
8
+ tag: 'iq',
9
+ attrs: {
10
+ id: generateMessageTag(),
11
+ type: 'get',
12
+ to: S_WHATSAPP_NET,
13
+ xmlns: 'w:mex'
14
+ },
15
+ content: [
16
+ {
17
+ tag: 'query',
18
+ attrs: { query_id: queryId },
19
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
20
+ }
21
+ ]
22
+ });
23
+ };
24
+ const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
25
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
26
+ const child = getBinaryNodeChild(result, 'result');
27
+ if (child?.content) {
28
+ const data = JSON.parse(child.content.toString());
29
+ if (data.errors && data.errors.length > 0) {
30
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
31
+ const firstError = data.errors[0];
32
+ const errorCode = firstError.extensions?.error_code || 400;
33
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
34
+ }
35
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
36
+ if (typeof response !== 'undefined') {
37
+ return response;
38
+ }
39
+ }
40
+ const action = (dataPath || '').startsWith('xwa2_')
41
+ ? dataPath.substring(5).replace(/_/g, ' ')
42
+ : dataPath?.replace(/_/g, ' ');
43
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
44
+ };
45
+ module.exports = {
46
+ executeWMexQuery
47
+ }
@@ -0,0 +1,147 @@
1
+ import { SocketConfig, WAMediaUpload, NewsletterMetadata, NewsletterReactionMode, NewsletterViewRole, NewsletterFetchedUpdate, ContactAction } from '../Types'
2
+ import { BinaryNode } from '../WABinary'
3
+
4
+ export declare const makeNewsletterSocket: (config: SocketConfig) => {
5
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
6
+ duration: string
7
+ }>
8
+ newsletterReactionMode: (jid: string, mode: NewsletterReactionMode) => Promise<void>
9
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>
10
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>
11
+ newsletterUpdatePicture: (jid: string, content: WAMediaUpload) => Promise<void>
12
+ newsletterRemovePicture: (jid: string) => Promise<void>
13
+ newsletterUnfollow: (jid: string) => Promise<void>
14
+ newsletterFollow: (jid: string) => Promise<void>
15
+ newsletterUnmute: (jid: string) => Promise<void>
16
+ newsletterMute: (jid: string) => Promise<void>
17
+ newsletterCreate: (name: string, description?: string, picture?: WAMediaUpload) => Promise<NewsletterMetadata>
18
+ newsletterQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
19
+ newsletterWMexQuery: (jid?: string | undefined, query_id: number, content: BinaryNode) => Promise<BinaryNode>
20
+ newsletterMetadata: (type: 'invite' | 'jid', key: string, role?: NewsletterViewRole) => Promise<NewsletterMetadata>
21
+ newsletterFetchAllParticipating: () => Promise<{
22
+ [_: string]: NewsletterMetadata
23
+ }>
24
+ newsletterAdminCount: (jid: string) => Promise<number>
25
+ newsletterChangeOwner: (jid: string, userLid: string) => Promise<void>
26
+ newsletterDemote: (jid: string, userLid: string) => Promise<void>
27
+ newsletterDelete: (jid: string) => Promise<void>
28
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
29
+ newsletterReactMessage: (jid: string, server_id: string, code?: string) => Promise<void>
30
+ newsletterFetchMessages: (type: 'invite' | 'jid', key: string, count: number, after?: number) => Promise<NewsletterFetchedUpdate[]>
31
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<NewsletterFetchedUpdate[]>
32
+ groupQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
33
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>
34
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>
35
+ groupLeave: (id: string) => Promise<void>
36
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>
37
+ groupRequestParticipantsList: (jid: string) => Promise<{
38
+ [key: string]: string
39
+ }[]>
40
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
41
+ status: string
42
+ jid: string
43
+ }[]>
44
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
45
+ status: string
46
+ jid: string
47
+ content: BinaryNode
48
+ }[]>
49
+ groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>
50
+ groupInviteCode: (jid: string) => Promise<string | undefined>
51
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>
52
+ groupAcceptInvite: (code: string) => Promise<string | undefined>
53
+ groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>
54
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>
55
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>
56
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
57
+ groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>
58
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>
59
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>
60
+ groupFetchAllParticipating: () => Promise<{
61
+ [_: string]: import("../Types").GroupMetadata
62
+ }>
63
+ processingMutex: {
64
+ mutex<T>(code: () => T | Promise<T>): Promise<T>
65
+ }
66
+ fetchPrivacySettings: (force?: boolean) => Promise<{
67
+ [_: string]: string
68
+ }>
69
+ upsertMessage: (msg: import("../Types").WAProto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
70
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
71
+ createCallLink: (type: 'audio' | 'video', event?: number, timeoutMs?: number) => Promise<void>
72
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
73
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
74
+ getBotListV2: () => Promise<BotListInfo[]>
75
+ getLidUser: (jid: string) => Promise<{
76
+ lid: string
77
+ id: string
78
+ }[] | undefined>
79
+ onWhatsApp: (...jids: string[]) => Promise<{
80
+ jid: string
81
+ exists: unknown
82
+ }[] | undefined>
83
+ fetchBlocklist: () => Promise<string[]>
84
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>
85
+ fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>
86
+ updateProfilePicture: (jid: string, content: WAMediaUpload) => Promise<void>
87
+ removeProfilePicture: (jid: string) => Promise<void>
88
+ updateProfileStatus: (status: string) => Promise<void>
89
+ updateProfileName: (name: string) => Promise<void>
90
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
91
+ updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
92
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
93
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
94
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
95
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
96
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
97
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>
98
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>
99
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>
100
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
101
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
102
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
103
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>
104
+ addChatLabel: (jid: string, labelId: string) => Promise<void>
105
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>
106
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
107
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
108
+ clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
109
+ star: (jid: string, messages: {
110
+ id: string
111
+ fromMe?: boolean | undefined
112
+ }[], star: boolean) => Promise<void>
113
+ addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>
114
+ removeContact: (jid: string) => Promise<void>
115
+ executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>
116
+ type: "md"
117
+ ws: any
118
+ ev: import("../Types").BaileysEventEmitter & {
119
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
120
+ buffer(): void
121
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
122
+ flush(force?: boolean | undefined): boolean
123
+ isBuffering(): boolean
124
+ }
125
+ authState: {
126
+ creds: import("../Types").AuthenticationCreds
127
+ keys: import("../Types").SignalKeyStoreWithTransaction
128
+ }
129
+ signalRepository: import("../Types").SignalRepository
130
+ user: import("../Types").Contact | undefined
131
+ generateMessageTag: () => string
132
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
133
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
134
+ waitForSocketOpen: () => Promise<void>
135
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
136
+ sendNode: (frame: BinaryNode) => Promise<void>
137
+ logout: (msg?: string | undefined) => Promise<void>
138
+ end: (error: Error | undefined) => void
139
+ onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
140
+ uploadPreKeys: (count?: number) => Promise<void>
141
+ uploadPreKeysToServerIfRequired: () => Promise<void>
142
+ requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
143
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
144
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
145
+ }
146
+
147
+ export declare const extractNewsletterMetadata: (node: BinaryNode, isCreate?: boolean) => NewsletterMetadata
@@ -0,0 +1,286 @@
1
+ "use strict"
2
+
3
+ Object.defineProperty(exports, "__esModule", { value: true })
4
+
5
+ const Types_1 = require("../Types")
6
+ const Utils_1 = require("../Utils")
7
+ const WABinary_1 = require("../WABinary")
8
+ const groups_1 = require("./groups")
9
+
10
+ const makeNewsletterSocket = (config) => {
11
+ const Neele = groups_1.makeGroupsSocket(config)
12
+ const { authState, signalRepository, query, generateMessageTag } = Neele
13
+ const encoder = new TextEncoder()
14
+
15
+ const newsletterQuery = async (jid, type, content) => (query({
16
+ tag: 'iq',
17
+ attrs: {
18
+ id: generateMessageTag(),
19
+ type,
20
+ xmlns: 'newsletter',
21
+ to: jid,
22
+ },
23
+ content
24
+ }))
25
+
26
+ const newsletterWMexQuery = async (jid, queryId, content) => (query({
27
+ tag: 'iq',
28
+ attrs: {
29
+ id: generateMessageTag(),
30
+ type: 'get',
31
+ xmlns: 'w:mex',
32
+ to: WABinary_1.S_WHATSAPP_NET,
33
+ },
34
+ content: [
35
+ {
36
+ tag: 'query',
37
+ attrs: { 'query_id': queryId },
38
+ content: encoder.encode(JSON.stringify({
39
+ variables: {
40
+ 'newsletter_id': jid,
41
+ ...content
42
+ }
43
+ }))
44
+ }
45
+ ]
46
+ }))
47
+
48
+ const parseFetchedUpdates = async (node, type) => {
49
+ let child
50
+ if (type === 'messages') {
51
+ child = WABinary_1.getBinaryNodeChild(node, 'messages')
52
+ }
53
+
54
+ else {
55
+ const parent = WABinary_1.getBinaryNodeChild(node, 'message_updates')
56
+ child = WABinary_1.getBinaryNodeChild(parent, 'messages')
57
+ }
58
+
59
+ return await Promise.all(WABinary_1.getAllBinaryNodeChildren(child).map(async (messageNode) => {
60
+ messageNode.attrs.from = child?.attrs.jid
61
+
62
+ const views = parseInt(WABinary_1.getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0')
63
+ const reactionNode = WABinary_1.getBinaryNodeChild(messageNode, 'reactions')
64
+ const reactions = WABinary_1.getBinaryNodeChildren(reactionNode, 'reaction')
65
+ .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }))
66
+
67
+ const data = {
68
+ 'server_id': messageNode.attrs.server_id,
69
+ views,
70
+ reactions
71
+ }
72
+
73
+ if (type === 'messages') {
74
+ const { fullMessage: message, decrypt } = await Utils_1.decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger)
75
+ await decrypt()
76
+ data.message = message
77
+ }
78
+
79
+ return data
80
+ }))
81
+ }
82
+
83
+ const newsletterMetadata = async (type, key, role) => {
84
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
85
+ input: {
86
+ key,
87
+ type: type.toUpperCase(),
88
+ view_role: role || 'GUEST'
89
+ },
90
+ fetch_viewer_metadata: true,
91
+ fetch_full_image: true,
92
+ fetch_creation_time: true
93
+ })
94
+
95
+ return extractNewsletterMetadata(result)
96
+ }
97
+
98
+ return {
99
+ ...Neele,
100
+ newsletterQuery,
101
+ newsletterWMexQuery,
102
+ subscribeNewsletterUpdates: async (jid) => {
103
+ const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }])
104
+
105
+ return WABinary_1.getBinaryNodeChild(result, 'live_updates')?.attrs
106
+ },
107
+ newsletterReactionMode: async (jid, mode) => {
108
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
109
+ updates: { settings: { 'reaction_codes': { value: mode } } }
110
+ })
111
+ },
112
+ newsletterUpdateDescription: async (jid, description) => {
113
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
114
+ updates: { description: description || '', settings: null }
115
+ })
116
+ },
117
+ newsletterUpdateName: async (jid, name) => {
118
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
119
+ updates: { name, settings: null }
120
+ })
121
+ },
122
+ newsletterUpdatePicture: async (jid, content) => {
123
+ const { img } = await Utils_1.generateProfilePicture(content)
124
+
125
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
126
+ updates: { picture: img.toString('base64'), settings: null }
127
+ })
128
+ },
129
+ newsletterRemovePicture: async (jid) => {
130
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
131
+ updates: { picture: '', settings: null }
132
+ })
133
+ },
134
+ newsletterUnfollow: async (jid) => {
135
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW)
136
+ },
137
+ newsletterFollow: async (jid) => {
138
+ await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW)
139
+ },
140
+ newsletterUnmute: async (jid) => {
141
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE)
142
+ },
143
+ newsletterMute: async (jid) => {
144
+ await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE)
145
+ },
146
+ newsletterAction: async (jid, type) => {
147
+ await newsletterWMexQuery(jid, Types_1.QueryIds[type.toUpperCase()])
148
+ },
149
+ newsletterCreate: async (name, description, picture) => {
150
+ //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
151
+ /**tos query */
152
+ await query({
153
+ tag: 'iq',
154
+ attrs: {
155
+ to: WABinary_1.S_WHATSAPP_NET,
156
+ xmlns: 'tos',
157
+ id: generateMessageTag(),
158
+ type: 'set'
159
+ },
160
+ content: [
161
+ {
162
+ tag: 'notice',
163
+ attrs: {
164
+ id: '20601218',
165
+ stage: '5'
166
+ },
167
+ content: []
168
+ }
169
+ ]
170
+ })
171
+
172
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
173
+ input: {
174
+ name,
175
+ description: description || null,
176
+ picture: picture ? (await Utils_1.generateProfilePicture(picture)).img.toString('base64') : null,
177
+ settings: {
178
+ reaction_codes: {
179
+ value: 'ALL'
180
+ }
181
+ }
182
+ }
183
+ })
184
+
185
+ return extractNewsletterMetadata(result, true)
186
+ },
187
+ newsletterMetadata,
188
+ newsletterFetchAllParticipating: async () => {
189
+ const data = {}
190
+
191
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.SUBSCRIBED)
192
+ const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
193
+ const newsletters = child.data[Types_1.XWAPaths.SUBSCRIBED]
194
+
195
+ for (const i of newsletters) {
196
+ if (!WABinary_1.isJidNewsletter(i.id)) {
197
+ continue
198
+ }
199
+
200
+ const metadata = await newsletterMetadata('JID', i.id)
201
+ data[metadata.id] = metadata
202
+ }
203
+
204
+ return data
205
+ },
206
+ newsletterAdminCount: async (jid) => {
207
+ const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT)
208
+ const buff = WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString()
209
+
210
+ return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count
211
+ },
212
+ newsletterChangeOwner: async (jid, userLid) => {
213
+ await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
214
+ user_id: userLid
215
+ })
216
+ },
217
+ newsletterDemote: async (jid, userLid) => {
218
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
219
+ user_id: userLid
220
+ })
221
+ },
222
+ newsletterDelete: async (jid) => {
223
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE)
224
+ },
225
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
226
+ newsletterReactMessage: async (jid, serverId, code) => {
227
+ await query({
228
+ tag: 'message',
229
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id: serverId, id: Utils_1.generateMessageID() },
230
+ content: [{
231
+ tag: 'reaction',
232
+ attrs: code ? { code } : {}
233
+ }]
234
+ })
235
+ },
236
+ newsletterFetchMessages: async (type, key, count, after) => {
237
+ const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
238
+ {
239
+ tag: 'messages',
240
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: after?.toString() || '100' }
241
+ }
242
+ ])
243
+
244
+ return await parseFetchedUpdates(result, 'messages')
245
+ },
246
+ newsletterFetchUpdates: async (jid, count, after, since) => {
247
+ const result = await newsletterQuery(jid, 'get', [
248
+ {
249
+ tag: 'message_updates',
250
+ attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
251
+ }
252
+ ])
253
+
254
+ return await parseFetchedUpdates(result, 'updates')
255
+ }
256
+ }
257
+ }
258
+
259
+ const extractNewsletterMetadata = (node, isCreate) => {
260
+ const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
261
+ const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
262
+
263
+ const metadata = {
264
+ id: metadataPath.id,
265
+ state: metadataPath.state.type,
266
+ creation_time: +metadataPath.thread_metadata.creation_time,
267
+ name: metadataPath.thread_metadata.name.text,
268
+ nameTime: +metadataPath.thread_metadata.name.update_time,
269
+ description: metadataPath.thread_metadata.description.text,
270
+ descriptionTime: +metadataPath.thread_metadata.description.update_time,
271
+ invite: metadataPath.thread_metadata.invite,
272
+ handle: metadataPath.thread_metadata.handle,
273
+ picture: Utils_1.getUrlFromDirectPath(metadataPath.thread_metadata.picture?.direct_path || ''),
274
+ preview: Utils_1.getUrlFromDirectPath(metadataPath.thread_metadata.preview?.direct_path || ''),
275
+ reaction_codes: metadataPath.thread_metadata?.settings?.reaction_codes?.value,
276
+ subscribers: +metadataPath.thread_metadata.subscribers_count,
277
+ verification: metadataPath.thread_metadata.verification,
278
+ viewer_metadata: metadataPath.viewer_metadata
279
+ }
280
+ return metadata
281
+ }
282
+
283
+ module.exports = {
284
+ makeNewsletterSocket,
285
+ extractNewsletterMetadata
286
+ }