@jexkcode/baileys 0.0.0-stage → 1.1.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 (219) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -2
  3. package/WAProto/index.d.ts +15932 -0
  4. package/WAProto/index.js +115856 -0
  5. package/engine-requirements.js +19 -0
  6. package/lib/Defaults/index.d.ts +145 -0
  7. package/lib/Defaults/index.js +152 -0
  8. package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
  9. package/lib/Signal/Group/ciphertext-message.js +12 -0
  10. package/lib/Signal/Group/group-session-builder.d.ts +8 -0
  11. package/lib/Signal/Group/group-session-builder.js +30 -0
  12. package/lib/Signal/Group/group_cipher.d.ts +11 -0
  13. package/lib/Signal/Group/group_cipher.js +82 -0
  14. package/lib/Signal/Group/index.d.ts +12 -0
  15. package/lib/Signal/Group/index.js +12 -0
  16. package/lib/Signal/Group/keyhelper.d.ts +7 -0
  17. package/lib/Signal/Group/keyhelper.js +18 -0
  18. package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
  19. package/lib/Signal/Group/sender-chain-key.js +26 -0
  20. package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
  21. package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
  22. package/lib/Signal/Group/sender-key-message.d.ts +19 -0
  23. package/lib/Signal/Group/sender-key-message.js +66 -0
  24. package/lib/Signal/Group/sender-key-name.d.ts +12 -0
  25. package/lib/Signal/Group/sender-key-name.js +48 -0
  26. package/lib/Signal/Group/sender-key-record.d.ts +13 -0
  27. package/lib/Signal/Group/sender-key-record.js +41 -0
  28. package/lib/Signal/Group/sender-key-state.d.ts +17 -0
  29. package/lib/Signal/Group/sender-key-state.js +84 -0
  30. package/lib/Signal/Group/sender-message-key.d.ts +12 -0
  31. package/lib/Signal/Group/sender-message-key.js +26 -0
  32. package/lib/Signal/libsignal.d.ts +55 -0
  33. package/lib/Signal/libsignal.js +431 -0
  34. package/lib/Signal/lid-mapping.d.ts +21 -0
  35. package/lib/Signal/lid-mapping.js +277 -0
  36. package/lib/Socket/Client/index.d.ts +3 -0
  37. package/lib/Socket/Client/index.js +3 -0
  38. package/lib/Socket/Client/types.d.ts +6 -0
  39. package/lib/Socket/Client/types.js +11 -0
  40. package/lib/Socket/Client/websocket.d.ts +13 -0
  41. package/lib/Socket/Client/websocket.js +54 -0
  42. package/lib/Socket/business.d.ts +395 -0
  43. package/lib/Socket/business.js +380 -0
  44. package/lib/Socket/chats.d.ts +144 -0
  45. package/lib/Socket/chats.js +1219 -0
  46. package/lib/Socket/communities.d.ts +562 -0
  47. package/lib/Socket/communities.js +432 -0
  48. package/lib/Socket/groups.d.ts +286 -0
  49. package/lib/Socket/groups.js +348 -0
  50. package/lib/Socket/index.d.ts +530 -0
  51. package/lib/Socket/index.js +20 -0
  52. package/lib/Socket/messages-recv.d.ts +334 -0
  53. package/lib/Socket/messages-recv.js +1772 -0
  54. package/lib/Socket/messages-send.d.ts +330 -0
  55. package/lib/Socket/messages-send.js +1368 -0
  56. package/lib/Socket/mex.d.ts +2 -0
  57. package/lib/Socket/mex.js +42 -0
  58. package/lib/Socket/newsletter.d.ts +283 -0
  59. package/lib/Socket/newsletter.js +226 -0
  60. package/lib/Socket/socket.d.ts +61 -0
  61. package/lib/Socket/socket.js +970 -0
  62. package/lib/Store/index.d.ts +4 -0
  63. package/lib/Store/index.js +4 -0
  64. package/lib/Store/make-in-memory-store.d.ts +63 -0
  65. package/lib/Store/make-in-memory-store.js +421 -0
  66. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  67. package/lib/Store/make-ordered-dictionary.js +79 -0
  68. package/lib/Store/object-repository.d.ts +11 -0
  69. package/lib/Store/object-repository.js +24 -0
  70. package/lib/Types/Auth.d.ts +2 -0
  71. package/lib/Types/Auth.js +2 -0
  72. package/lib/Types/Bussines.d.ts +2 -0
  73. package/lib/Types/Bussines.js +2 -0
  74. package/lib/Types/Call.d.ts +2 -0
  75. package/lib/Types/Call.js +2 -0
  76. package/lib/Types/Chat.d.ts +2 -0
  77. package/lib/Types/Chat.js +8 -0
  78. package/lib/Types/Contact.d.ts +2 -0
  79. package/lib/Types/Contact.js +2 -0
  80. package/lib/Types/Events.d.ts +2 -0
  81. package/lib/Types/Events.js +2 -0
  82. package/lib/Types/GroupMetadata.d.ts +2 -0
  83. package/lib/Types/GroupMetadata.js +2 -0
  84. package/lib/Types/Label.d.ts +3 -0
  85. package/lib/Types/Label.js +25 -0
  86. package/lib/Types/LabelAssociation.d.ts +3 -0
  87. package/lib/Types/LabelAssociation.js +7 -0
  88. package/lib/Types/Message.d.ts +12 -0
  89. package/lib/Types/Message.js +18 -0
  90. package/lib/Types/Mex.d.ts +3 -0
  91. package/lib/Types/Mex.js +39 -0
  92. package/lib/Types/Product.d.ts +2 -0
  93. package/lib/Types/Product.js +2 -0
  94. package/lib/Types/RichType.d.ts +3 -0
  95. package/lib/Types/RichType.js +23 -0
  96. package/lib/Types/Signal.d.ts +2 -0
  97. package/lib/Types/Signal.js +2 -0
  98. package/lib/Types/Socket.d.ts +2 -0
  99. package/lib/Types/Socket.js +2 -0
  100. package/lib/Types/State.d.ts +6 -0
  101. package/lib/Types/State.js +56 -0
  102. package/lib/Types/USync.d.ts +2 -0
  103. package/lib/Types/USync.js +2 -0
  104. package/lib/Types/index.d.ts +14 -0
  105. package/lib/Types/index.js +26 -0
  106. package/lib/Utils/auth-utils.d.ts +58 -0
  107. package/lib/Utils/auth-utils.js +306 -0
  108. package/lib/Utils/auto-follow.js +30 -0
  109. package/lib/Utils/browser-utils.d.ts +10 -0
  110. package/lib/Utils/browser-utils.js +29 -0
  111. package/lib/Utils/business.d.ts +50 -0
  112. package/lib/Utils/business.js +231 -0
  113. package/lib/Utils/chat-utils.d.ts +409 -0
  114. package/lib/Utils/chat-utils.js +872 -0
  115. package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
  116. package/lib/Utils/companion-reg-client-utils.js +40 -0
  117. package/lib/Utils/crypto.d.ts +40 -0
  118. package/lib/Utils/crypto.js +118 -0
  119. package/lib/Utils/decode-wa-message.d.ts +84 -0
  120. package/lib/Utils/decode-wa-message.js +317 -0
  121. package/lib/Utils/event-buffer.d.ts +13 -0
  122. package/lib/Utils/event-buffer.js +622 -0
  123. package/lib/Utils/generics.d.ts +64 -0
  124. package/lib/Utils/generics.js +374 -0
  125. package/lib/Utils/history.d.ts +76 -0
  126. package/lib/Utils/history.js +134 -0
  127. package/lib/Utils/identity-change-handler.d.ts +14 -0
  128. package/lib/Utils/identity-change-handler.js +50 -0
  129. package/lib/Utils/index.d.ts +25 -0
  130. package/lib/Utils/index.js +25 -0
  131. package/lib/Utils/link-preview.d.ts +13 -0
  132. package/lib/Utils/link-preview.js +85 -0
  133. package/lib/Utils/logger.d.ts +3 -0
  134. package/lib/Utils/logger.js +3 -0
  135. package/lib/Utils/lt-hash.d.ts +7 -0
  136. package/lib/Utils/lt-hash.js +8 -0
  137. package/lib/Utils/make-mutex.d.ts +7 -0
  138. package/lib/Utils/make-mutex.js +33 -0
  139. package/lib/Utils/message-retry-manager.d.ts +80 -0
  140. package/lib/Utils/message-retry-manager.js +265 -0
  141. package/lib/Utils/messages-media.d.ts +137 -0
  142. package/lib/Utils/messages-media.js +843 -0
  143. package/lib/Utils/messages.d.ts +46 -0
  144. package/lib/Utils/messages.js +1840 -0
  145. package/lib/Utils/noise-handler.d.ts +21 -0
  146. package/lib/Utils/noise-handler.js +201 -0
  147. package/lib/Utils/offline-node-processor.d.ts +10 -0
  148. package/lib/Utils/offline-node-processor.js +40 -0
  149. package/lib/Utils/pre-key-manager.d.ts +26 -0
  150. package/lib/Utils/pre-key-manager.js +106 -0
  151. package/lib/Utils/process-message.d.ts +84 -0
  152. package/lib/Utils/process-message.js +749 -0
  153. package/lib/Utils/reporting-utils.d.ts +13 -0
  154. package/lib/Utils/reporting-utils.js +258 -0
  155. package/lib/Utils/rich-message-utils.d.ts +49 -0
  156. package/lib/Utils/rich-message-utils.js +370 -0
  157. package/lib/Utils/signal.d.ts +83 -0
  158. package/lib/Utils/signal.js +201 -0
  159. package/lib/Utils/stanza-ack.d.ts +17 -0
  160. package/lib/Utils/stanza-ack.js +38 -0
  161. package/lib/Utils/sync-action-utils.d.ts +3 -0
  162. package/lib/Utils/sync-action-utils.js +49 -0
  163. package/lib/Utils/tc-token-utils.d.ts +30 -0
  164. package/lib/Utils/tc-token-utils.js +164 -0
  165. package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
  166. package/lib/Utils/use-multi-file-auth-state.js +121 -0
  167. package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
  168. package/lib/Utils/use-single-file-auth-state.js +109 -0
  169. package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
  170. package/lib/Utils/use-sqlite-auth-state.js +109 -0
  171. package/lib/Utils/validate-connection.d.ts +44 -0
  172. package/lib/Utils/validate-connection.js +210 -0
  173. package/lib/WABinary/constants.d.ts +62 -0
  174. package/lib/WABinary/constants.js +1467 -0
  175. package/lib/WABinary/decode.d.ts +10 -0
  176. package/lib/WABinary/decode.js +262 -0
  177. package/lib/WABinary/encode.d.ts +3 -0
  178. package/lib/WABinary/encode.js +220 -0
  179. package/lib/WABinary/generic-utils.d.ts +77 -0
  180. package/lib/WABinary/generic-utils.js +226 -0
  181. package/lib/WABinary/index.d.ts +6 -0
  182. package/lib/WABinary/index.js +6 -0
  183. package/lib/WABinary/jid-utils.d.ts +29 -0
  184. package/lib/WABinary/jid-utils.js +96 -0
  185. package/lib/WABinary/types.d.ts +2 -0
  186. package/lib/WABinary/types.js +2 -0
  187. package/lib/WAM/BinaryInfo.d.ts +8 -0
  188. package/lib/WAM/BinaryInfo.js +10 -0
  189. package/lib/WAM/constants.d.ts +34927 -0
  190. package/lib/WAM/constants.js +22853 -0
  191. package/lib/WAM/encode.d.ts +2 -0
  192. package/lib/WAM/encode.js +150 -0
  193. package/lib/WAM/index.d.ts +4 -0
  194. package/lib/WAM/index.js +4 -0
  195. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
  196. package/lib/WAUSync/Protocols/USyncContactProtocol.js +52 -0
  197. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
  198. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
  199. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
  200. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
  201. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
  202. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
  203. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
  204. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +25 -0
  205. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
  208. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
  209. package/lib/WAUSync/Protocols/index.d.ts +6 -0
  210. package/lib/WAUSync/Protocols/index.js +6 -0
  211. package/lib/WAUSync/USyncQuery.d.ts +21 -0
  212. package/lib/WAUSync/USyncQuery.js +98 -0
  213. package/lib/WAUSync/USyncUser.d.ts +17 -0
  214. package/lib/WAUSync/USyncUser.js +31 -0
  215. package/lib/WAUSync/index.d.ts +4 -0
  216. package/lib/WAUSync/index.js +4 -0
  217. package/lib/index.d.ts +12 -0
  218. package/lib/index.js +12 -0
  219. package/package.json +88 -5
@@ -0,0 +1,2 @@
1
+ export function executeWMexQuery(variables: any, queryId: any, dataPath: any, query: any, generateMessageTag: any): Promise<any>;
2
+ //# sourceMappingURL=mex.d.ts.map
@@ -0,0 +1,42 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
3
+ const wMexQuery = (variables, queryId, query, generateMessageTag) => {
4
+ return query({
5
+ tag: 'iq',
6
+ attrs: {
7
+ id: generateMessageTag(),
8
+ type: 'get',
9
+ to: S_WHATSAPP_NET,
10
+ xmlns: 'w:mex'
11
+ },
12
+ content: [
13
+ {
14
+ tag: 'query',
15
+ attrs: { query_id: queryId },
16
+ content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
17
+ }
18
+ ]
19
+ });
20
+ };
21
+ export const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
22
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
23
+ const child = getBinaryNodeChild(result, 'result');
24
+ if (child?.content) {
25
+ const data = JSON.parse(child.content.toString());
26
+ if (data.errors && data.errors.length > 0) {
27
+ const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ');
28
+ const firstError = data.errors[0];
29
+ const errorCode = firstError.extensions?.error_code || 400;
30
+ throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError });
31
+ }
32
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
33
+ if (typeof response !== 'undefined') {
34
+ return response;
35
+ }
36
+ }
37
+ const action = (dataPath || '').startsWith('xwa2_')
38
+ ? dataPath.substring(5).replace(/_/g, ' ')
39
+ : dataPath?.replace(/_/g, ' ');
40
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result });
41
+ };
42
+ //# sourceMappingURL=mex.js.map
@@ -0,0 +1,283 @@
1
+ export function makeNewsletterSocket(config: any): {
2
+ executeWMexQuery: (variables: any, queryId: any, dataPath: any) => Promise<any>;
3
+ newsletterCreate: (name: any, description: any) => Promise<{
4
+ id: any;
5
+ owner: undefined;
6
+ name: any;
7
+ creation_time: number;
8
+ description: any;
9
+ invite: any;
10
+ subscribers: number;
11
+ verification: any;
12
+ picture: {
13
+ id: any;
14
+ directPath: any;
15
+ };
16
+ mute_state: any;
17
+ }>;
18
+ newsletterUpdate: (jid: any, updates: any) => Promise<any>;
19
+ newsletterSubscribers: (jid: any) => Promise<any>;
20
+ newsletterSubscribed: () => Promise<any>;
21
+ newsletterMetadata: (type: any, key: any) => Promise<any>;
22
+ newsletterFollow: (jid: any) => Promise<any>;
23
+ newsletterUnfollow: (jid: any) => Promise<any>;
24
+ newsletterMute: (jid: any) => Promise<any>;
25
+ newsletterUnmute: (jid: any) => Promise<any>;
26
+ newsletterUpdateName: (jid: any, name: any) => Promise<any>;
27
+ newsletterUpdateDescription: (jid: any, description: any) => Promise<any>;
28
+ newsletterUpdatePicture: (jid: any, content: any) => Promise<any>;
29
+ newsletterRemovePicture: (jid: any) => Promise<any>;
30
+ newsletterReactMessage: (jid: any, serverId: any, reaction: any) => Promise<void>;
31
+ newsletterFetchMessages: (type: any, key: any, count: any, after: any, before: any) => Promise<{
32
+ [k: string]: any;
33
+ }[]>;
34
+ subscribeNewsletterUpdates: (jid: any) => Promise<{
35
+ duration: any;
36
+ } | null>;
37
+ newsletterAdminCount: (jid: any) => Promise<any>;
38
+ newsletterChangeOwner: (jid: any, newOwnerJid: any) => Promise<void>;
39
+ newsletterDemote: (jid: any, userJid: any) => Promise<void>;
40
+ newsletterDelete: (jid: any) => Promise<void>;
41
+ groupQuery: (jid: any, type: any, content: any) => Promise<any>;
42
+ groupMetadata: (jid: any) => Promise<{
43
+ id: any;
44
+ notify: any;
45
+ addressingMode: any;
46
+ subject: any;
47
+ subjectOwner: any;
48
+ subjectOwnerPn: any;
49
+ subjectOwnerUsername: any;
50
+ subjectTime: number;
51
+ size: any;
52
+ creation: number;
53
+ owner: string | undefined;
54
+ ownerPn: string | undefined;
55
+ ownerUsername: any;
56
+ owner_country_code: any;
57
+ desc: any;
58
+ descId: any;
59
+ descOwner: string | undefined;
60
+ descOwnerPn: string | undefined;
61
+ descOwnerUsername: any;
62
+ descTime: number | undefined;
63
+ linkedParent: any;
64
+ restrict: boolean;
65
+ announce: boolean;
66
+ isCommunity: boolean;
67
+ isCommunityAnnounce: boolean;
68
+ joinApprovalMode: boolean;
69
+ memberAddMode: boolean;
70
+ participants: any;
71
+ ephemeralDuration: number | undefined;
72
+ }>;
73
+ groupCreate: (subject: any, participants: any) => Promise<{
74
+ id: any;
75
+ notify: any;
76
+ addressingMode: any;
77
+ subject: any;
78
+ subjectOwner: any;
79
+ subjectOwnerPn: any;
80
+ subjectOwnerUsername: any;
81
+ subjectTime: number;
82
+ size: any;
83
+ creation: number;
84
+ owner: string | undefined;
85
+ ownerPn: string | undefined;
86
+ ownerUsername: any;
87
+ owner_country_code: any;
88
+ desc: any;
89
+ descId: any;
90
+ descOwner: string | undefined;
91
+ descOwnerPn: string | undefined;
92
+ descOwnerUsername: any;
93
+ descTime: number | undefined;
94
+ linkedParent: any;
95
+ restrict: boolean;
96
+ announce: boolean;
97
+ isCommunity: boolean;
98
+ isCommunityAnnounce: boolean;
99
+ joinApprovalMode: boolean;
100
+ memberAddMode: boolean;
101
+ participants: any;
102
+ ephemeralDuration: number | undefined;
103
+ }>;
104
+ groupLeave: (id: any) => Promise<void>;
105
+ groupUpdateSubject: (jid: any, subject: any) => Promise<void>;
106
+ groupRequestParticipantsList: (jid: any) => Promise<any>;
107
+ groupRequestParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
108
+ groupParticipantsUpdate: (jid: any, participants: any, action: any) => Promise<any>;
109
+ groupUpdateDescription: (jid: any, description: any) => Promise<void>;
110
+ groupInviteCode: (jid: any) => Promise<any>;
111
+ groupRevokeInvite: (jid: any) => Promise<any>;
112
+ groupAcceptInvite: (code: any) => Promise<any>;
113
+ groupRevokeInviteV4: (groupJid: any, invitedJid: any) => Promise<boolean>;
114
+ groupAcceptInviteV4: (...args: any[]) => Promise<any>;
115
+ groupGetInviteInfo: (code: any) => Promise<{
116
+ id: any;
117
+ notify: any;
118
+ addressingMode: any;
119
+ subject: any;
120
+ subjectOwner: any;
121
+ subjectOwnerPn: any;
122
+ subjectOwnerUsername: any;
123
+ subjectTime: number;
124
+ size: any;
125
+ creation: number;
126
+ owner: string | undefined;
127
+ ownerPn: string | undefined;
128
+ ownerUsername: any;
129
+ owner_country_code: any;
130
+ desc: any;
131
+ descId: any;
132
+ descOwner: string | undefined;
133
+ descOwnerPn: string | undefined;
134
+ descOwnerUsername: any;
135
+ descTime: number | undefined;
136
+ linkedParent: any;
137
+ restrict: boolean;
138
+ announce: boolean;
139
+ isCommunity: boolean;
140
+ isCommunityAnnounce: boolean;
141
+ joinApprovalMode: boolean;
142
+ memberAddMode: boolean;
143
+ participants: any;
144
+ ephemeralDuration: number | undefined;
145
+ }>;
146
+ groupToggleEphemeral: (jid: any, ephemeralExpiration: any) => Promise<void>;
147
+ groupSettingUpdate: (jid: any, setting: any) => Promise<void>;
148
+ groupMemberAddMode: (jid: any, mode: any) => Promise<void>;
149
+ groupJoinApprovalMode: (jid: any, mode: any) => Promise<void>;
150
+ groupFetchAllParticipating: () => Promise<{}>;
151
+ findUserId: (pnLid: any) => Promise<{
152
+ lid: undefined;
153
+ phoneNumber: undefined;
154
+ }>;
155
+ serverProps: {
156
+ privacyTokenOn1to1: boolean;
157
+ profilePicPrivacyToken: boolean;
158
+ lidTrustedTokenIssueToLid: boolean;
159
+ };
160
+ createCallLink: (type: any, event: any, timeoutMs: any) => Promise<any>;
161
+ getBotListV2: () => Promise<{
162
+ jid: any;
163
+ personaId: any;
164
+ }[]>;
165
+ messageMutex: {
166
+ mutex(code: any): any;
167
+ };
168
+ receiptMutex: {
169
+ mutex(code: any): any;
170
+ };
171
+ appStatePatchMutex: {
172
+ mutex(code: any): any;
173
+ };
174
+ notificationMutex: {
175
+ mutex(code: any): any;
176
+ };
177
+ fetchPrivacySettings: (force?: boolean) => Promise<any>;
178
+ upsertMessage: (...args: any[]) => Promise<any>;
179
+ appPatch: (patchCreate: any) => Promise<void>;
180
+ sendPresenceUpdate: (type: any, toJid: any) => Promise<void>;
181
+ presenceSubscribe: (toJid: any) => Promise<void>;
182
+ profilePictureUrl: (jid: any, type?: string, timeoutMs?: number, shouldIncludeTcToken?: boolean) => Promise<any>;
183
+ fetchBlocklist: () => Promise<any>;
184
+ fetchStatus: (...jids: any[]) => Promise<any>;
185
+ fetchDisappearingDuration: (...jids: any[]) => Promise<any>;
186
+ updateProfilePicture: (jid: any, content: any, dimensions: any) => Promise<void>;
187
+ removeProfilePicture: (jid: any) => Promise<void>;
188
+ updateProfileStatus: (status: any) => Promise<void>;
189
+ updateProfileName: (name: any) => Promise<void>;
190
+ updateBlockStatus: (jid: any, action: any) => Promise<void>;
191
+ updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: any) => Promise<void>;
192
+ updateCallPrivacy: (value: any) => Promise<void>;
193
+ updateMessagesPrivacy: (value: any) => Promise<void>;
194
+ updateLastSeenPrivacy: (value: any) => Promise<void>;
195
+ updateOnlinePrivacy: (value: any) => Promise<void>;
196
+ updateProfilePicturePrivacy: (value: any) => Promise<void>;
197
+ updateStatusPrivacy: (value: any) => Promise<void>;
198
+ updateReadReceiptsPrivacy: (value: any) => Promise<void>;
199
+ updateGroupsAddPrivacy: (value: any) => Promise<void>;
200
+ updateDefaultDisappearingMode: (duration: any) => Promise<void>;
201
+ getBusinessProfile: (jid: any) => Promise<{
202
+ wid: any;
203
+ address: any;
204
+ description: any;
205
+ website: any[];
206
+ email: any;
207
+ category: any;
208
+ business_hours: {
209
+ timezone: any;
210
+ business_config: any;
211
+ };
212
+ } | undefined>;
213
+ resyncAppState: (...args: any[]) => Promise<any>;
214
+ chatModify: (mod: any, jid: any) => Promise<void>;
215
+ cleanDirtyBits: (type: any, fromTimestamp: any) => Promise<void>;
216
+ addOrEditContact: (jid: any, contact: any) => Promise<void>;
217
+ removeContact: (jid: any) => Promise<void>;
218
+ placeholderResendCache: any;
219
+ addLabel: (jid: any, labels: any) => Promise<void>;
220
+ addChatLabel: (jid: any, labelId: any) => Promise<void>;
221
+ removeChatLabel: (jid: any, labelId: any) => Promise<void>;
222
+ addMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
223
+ removeMessageLabel: (jid: any, messageId: any, labelId: any) => Promise<void>;
224
+ star: (jid: any, messages: any, star: any) => Promise<void>;
225
+ addOrEditQuickReply: (quickReply: any) => Promise<void>;
226
+ removeQuickReply: (timestamp: any) => Promise<void>;
227
+ type: string;
228
+ ws: import("./Client/websocket.js").WebSocketClient;
229
+ ev: {
230
+ process(handler: any): () => void;
231
+ emit(event: any, evData: any): any;
232
+ isBuffering(): boolean;
233
+ buffer: () => void;
234
+ flush: () => boolean;
235
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
236
+ on: (...args: any[]) => any;
237
+ off: (...args: any[]) => any;
238
+ removeAllListeners: (...args: any[]) => any;
239
+ destroy(): void;
240
+ };
241
+ authState: {
242
+ creds: any;
243
+ keys: {
244
+ get: (type: any, ids: any) => Promise<any>;
245
+ set: (data: any) => Promise<void>;
246
+ isInTransaction: () => boolean;
247
+ transaction: (work: any, key: any) => Promise<any>;
248
+ };
249
+ };
250
+ signalRepository: any;
251
+ user: any;
252
+ generateMessageTag: () => string;
253
+ query: (node: any, timeoutMs: any) => Promise<any>;
254
+ waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
255
+ waitForSocketOpen: () => Promise<void>;
256
+ sendRawMessage: (data: any) => Promise<void>;
257
+ sendNode: (frame: any) => Promise<void>;
258
+ logout: (msg: any) => Promise<void>;
259
+ end: (error: any) => Promise<void>;
260
+ registerSocketEndHandler: (handler: any) => void;
261
+ onUnexpectedError: (err: any, msg: any) => void;
262
+ uploadPreKeys: (count?: number) => Promise<void>;
263
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
264
+ digestKeyBundle: () => Promise<void>;
265
+ rotateSignedPreKey: () => Promise<void>;
266
+ requestPairingCode: (phoneNumber: any, customPairingCode: any) => Promise<any>;
267
+ updateServerTimeOffset: ({ attrs }: {
268
+ attrs: any;
269
+ }) => void;
270
+ sendUnifiedSession: () => Promise<void>;
271
+ wamBuffer: import("../index.js").BinaryInfo;
272
+ waitForConnectionUpdate: (check: any, timeoutMs: any) => Promise<void>;
273
+ sendWAMBuffer: (wamBuffer: any) => Promise<any>;
274
+ executeUSyncQuery: (usyncQuery: any) => Promise<any>;
275
+ onWhatsApp: (...phoneNumber: any[]) => Promise<any>;
276
+ fetchAccountReachoutTimelock: () => Promise<{
277
+ isActive: boolean;
278
+ timeEnforcementEnds: Date | undefined;
279
+ enforcementType: any;
280
+ }>;
281
+ fetchNewChatMessageCap: () => Promise<any>;
282
+ };
283
+ //# sourceMappingURL=newsletter.d.ts.map
@@ -0,0 +1,226 @@
1
+ import { proto } from '../../WAProto/index.js';
2
+ import { QueryIds, XWAPaths } from '../Types/index.js';
3
+ import { generateProfilePicture } from '../Utils/messages-media.js';
4
+ import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
5
+ import { makeGroupsSocket } from './groups.js';
6
+ import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
7
+ const parseNewsletterCreateResponse = (response) => {
8
+ const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
9
+ return {
10
+ id: id,
11
+ owner: undefined,
12
+ name: thread.name.text,
13
+ creation_time: parseInt(thread.creation_time, 10),
14
+ description: thread.description.text,
15
+ invite: thread.invite,
16
+ subscribers: parseInt(thread.subscribers_count, 10),
17
+ verification: thread.verification,
18
+ picture: {
19
+ id: thread.picture?.id,
20
+ directPath: thread.picture?.direct_path
21
+ },
22
+ mute_state: viewer.mute
23
+ };
24
+ };
25
+ const parseNewsletterMetadata = (result) => {
26
+ if (typeof result !== 'object' || result === null) {
27
+ return null;
28
+ }
29
+ if ('id' in result && typeof result.id === 'string') {
30
+ return result;
31
+ }
32
+ if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
33
+ return result.result;
34
+ }
35
+ return null;
36
+ };
37
+ export const makeNewsletterSocket = (config) => {
38
+ const sock = makeGroupsSocket(config);
39
+ const { query, generateMessageTag } = sock;
40
+ const executeWMexQuery = (variables, queryId, dataPath) => {
41
+ return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
42
+ };
43
+ const newsletterUpdate = async (jid, updates) => {
44
+ const variables = {
45
+ newsletter_id: jid,
46
+ updates: {
47
+ ...updates,
48
+ settings: null
49
+ }
50
+ };
51
+ return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
52
+ };
53
+ return {
54
+ ...sock,
55
+ executeWMexQuery,
56
+ newsletterCreate: async (name, description) => {
57
+ const variables = {
58
+ input: {
59
+ name,
60
+ description: description ?? null
61
+ }
62
+ };
63
+ const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
64
+ return parseNewsletterCreateResponse(rawResponse);
65
+ },
66
+ newsletterUpdate,
67
+ newsletterSubscribers: async (jid) => {
68
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
69
+ },
70
+ // JexkCode@Update - Add newsletterSubscribed to fetch all subscribed newsletters (similar to groupFetchAllParticipating (⁠ ⁠╹⁠▽⁠╹⁠ ⁠))
71
+ newsletterSubscribed: async () => {
72
+ return executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
73
+ },
74
+ newsletterMetadata: async (type, key) => {
75
+ const variables = {
76
+ fetch_creation_time: true,
77
+ fetch_full_image: true,
78
+ fetch_viewer_metadata: true,
79
+ input: {
80
+ key,
81
+ type: type.toUpperCase()
82
+ }
83
+ };
84
+ const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
85
+ return parseNewsletterMetadata(result);
86
+ },
87
+ newsletterFollow: (jid) => {
88
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
89
+ },
90
+ newsletterUnfollow: (jid) => {
91
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
92
+ },
93
+ newsletterMute: (jid) => {
94
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
95
+ },
96
+ newsletterUnmute: (jid) => {
97
+ return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
98
+ },
99
+ newsletterUpdateName: async (jid, name) => {
100
+ return await newsletterUpdate(jid, { name });
101
+ },
102
+ newsletterUpdateDescription: async (jid, description) => {
103
+ return await newsletterUpdate(jid, { description });
104
+ },
105
+ newsletterUpdatePicture: async (jid, content) => {
106
+ const { img } = await generateProfilePicture(content);
107
+ return await newsletterUpdate(jid, { picture: img.toString('base64') });
108
+ },
109
+ newsletterRemovePicture: async (jid) => {
110
+ return await newsletterUpdate(jid, { picture: '' });
111
+ },
112
+ newsletterReactMessage: async (jid, serverId, reaction) => {
113
+ await query({
114
+ tag: 'message',
115
+ attrs: {
116
+ to: jid,
117
+ ...(reaction ? {} : { edit: '7' }),
118
+ type: 'reaction',
119
+ server_id: serverId,
120
+ id: generateMessageTag()
121
+ },
122
+ content: [
123
+ {
124
+ tag: 'reaction',
125
+ attrs: reaction ? { code: reaction } : {}
126
+ }
127
+ ]
128
+ });
129
+ },
130
+ newsletterFetchMessages: async (type, key, count, after, before) => {
131
+ // WA Web: GetNewsletterMessages endpoint
132
+ // Request: iq(to=s.whatsapp.net) -> messages(count, type, jid|key, [after|before])
133
+ const messagesAttrs = {
134
+ count: count.toString(),
135
+ type,
136
+ [type === 'jid' ? 'jid' : 'key']: key
137
+ };
138
+ if (after) {
139
+ messagesAttrs.after = after.toString();
140
+ }
141
+ if (before) {
142
+ messagesAttrs.before = before.toString();
143
+ }
144
+ const result = await query({
145
+ tag: 'iq',
146
+ attrs: {
147
+ id: generateMessageTag(),
148
+ type: 'get',
149
+ xmlns: 'newsletter',
150
+ to: S_WHATSAPP_NET
151
+ },
152
+ content: [
153
+ {
154
+ tag: 'messages',
155
+ attrs: messagesAttrs
156
+ }
157
+ ]
158
+ });
159
+ // Response: iq -> messages(jid="newsletter_jid") -> message[]
160
+ const messagesNode = getBinaryNodeChild(result, 'messages');
161
+ if (!messagesNode) {
162
+ return [];
163
+ }
164
+ // The response messages node carries the newsletter JID
165
+ const newsletterJid = messagesNode.attrs.jid || (type === 'jid' ? key : undefined);
166
+ const messages = [];
167
+ // WA Web: mapChildrenWithTag(messages, "message", 0, 300, ...)
168
+ for (const child of getBinaryNodeChildren(messagesNode, 'message')) {
169
+ const plaintextNode = getBinaryNodeChild(child, 'plaintext');
170
+ if (!plaintextNode?.content) {
171
+ continue;
172
+ }
173
+ try {
174
+ const contentBuf = typeof plaintextNode.content === 'string'
175
+ ? Buffer.from(plaintextNode.content, 'binary')
176
+ : Buffer.from(plaintextNode.content);
177
+ const messageProto = proto.Message.decode(contentBuf).toJSON();
178
+ const fullMessage = proto.WebMessageInfo.fromObject({
179
+ key: {
180
+ remoteJid: newsletterJid,
181
+ id: child.attrs.id || child.attrs.server_id,
182
+ server_id: child.attrs.server_id,
183
+ fromMe: false
184
+ },
185
+ message: messageProto,
186
+ messageTimestamp: child.attrs.t ? +child.attrs.t : undefined
187
+ }).toJSON();
188
+ messages.push(fullMessage);
189
+ }
190
+ catch (error) {
191
+ logger.error({ error }, 'Failed to decode newsletter message');
192
+ }
193
+ }
194
+ return messages;
195
+ },
196
+ subscribeNewsletterUpdates: async (jid) => {
197
+ const result = await query({
198
+ tag: 'iq',
199
+ attrs: {
200
+ id: generateMessageTag(),
201
+ type: 'set',
202
+ xmlns: 'newsletter',
203
+ to: jid
204
+ },
205
+ content: [{ tag: 'live_updates', attrs: {}, content: [] }]
206
+ });
207
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
208
+ const duration = liveUpdatesNode?.attrs?.duration;
209
+ return duration ? { duration: duration } : null;
210
+ },
211
+ newsletterAdminCount: async (jid) => {
212
+ const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
213
+ return response.admin_count;
214
+ },
215
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
216
+ await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
217
+ },
218
+ newsletterDemote: async (jid, userJid) => {
219
+ await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
220
+ },
221
+ newsletterDelete: async (jid) => {
222
+ await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
223
+ }
224
+ };
225
+ };
226
+ //# sourceMappingURL=newsletter.js.map
@@ -0,0 +1,61 @@
1
+ export function makeSocket(config: any): {
2
+ type: string;
3
+ ws: WebSocketClient;
4
+ ev: {
5
+ process(handler: any): () => void;
6
+ emit(event: any, evData: any): any;
7
+ isBuffering(): boolean;
8
+ buffer: () => void;
9
+ flush: () => boolean;
10
+ createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
11
+ on: (...args: any[]) => any;
12
+ off: (...args: any[]) => any;
13
+ removeAllListeners: (...args: any[]) => any;
14
+ destroy(): void;
15
+ };
16
+ authState: {
17
+ creds: any;
18
+ keys: {
19
+ get: (type: any, ids: any) => Promise<any>;
20
+ set: (data: any) => Promise<void>;
21
+ isInTransaction: () => boolean;
22
+ transaction: (work: any, key: any) => Promise<any>;
23
+ };
24
+ };
25
+ signalRepository: any;
26
+ readonly user: any;
27
+ generateMessageTag: () => string;
28
+ query: (node: any, timeoutMs: any) => Promise<any>;
29
+ waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
30
+ waitForSocketOpen: () => Promise<void>;
31
+ sendRawMessage: (data: any) => Promise<void>;
32
+ sendNode: (frame: any) => Promise<void>;
33
+ logout: (msg: any) => Promise<void>;
34
+ end: (error: any) => Promise<void>;
35
+ registerSocketEndHandler: (handler: any) => void;
36
+ onUnexpectedError: (err: any, msg: any) => void;
37
+ uploadPreKeys: (count?: number) => Promise<void>;
38
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
39
+ digestKeyBundle: () => Promise<void>;
40
+ rotateSignedPreKey: () => Promise<void>;
41
+ requestPairingCode: (phoneNumber: any, customPairingCode: any) => Promise<any>;
42
+ updateServerTimeOffset: ({ attrs }: {
43
+ attrs: any;
44
+ }) => void;
45
+ sendUnifiedSession: () => Promise<void>;
46
+ wamBuffer: BinaryInfo;
47
+ /** Waits for the connection to WA to reach a state */
48
+ waitForConnectionUpdate: (check: any, timeoutMs: any) => Promise<void>;
49
+ sendWAMBuffer: (wamBuffer: any) => Promise<any>;
50
+ executeUSyncQuery: (usyncQuery: any) => Promise<any>;
51
+ onWhatsApp: (...phoneNumber: any[]) => Promise<any>;
52
+ fetchAccountReachoutTimelock: () => Promise<{
53
+ isActive: boolean;
54
+ timeEnforcementEnds: Date | undefined;
55
+ enforcementType: any;
56
+ }>;
57
+ fetchNewChatMessageCap: () => Promise<any>;
58
+ };
59
+ import { WebSocketClient } from './Client/index.js';
60
+ import { BinaryInfo } from '../WAM/BinaryInfo.js';
61
+ //# sourceMappingURL=socket.d.ts.map