sanka-baileyss 2.3.6 → 2.3.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.
@@ -1,286 +1,242 @@
1
1
  "use strict"
2
-
3
2
  Object.defineProperty(exports, "__esModule", { value: true })
4
-
5
3
  const Types_1 = require("../Types")
6
4
  const Utils_1 = require("../Utils")
7
5
  const WABinary_1 = require("../WABinary")
8
6
  const groups_1 = require("./groups")
9
-
10
7
  const makeNewsletterSocket = (config) => {
11
- const suki = groups_1.makeGroupsSocket(config)
12
- const { authState, signalRepository, query, generateMessageTag } = suki
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
- ...suki,
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
- }
8
+ const sock = groups_1.makeGroupsSocket(config)
9
+ const { authState, signalRepository, query, generateMessageTag } = sock
10
+ const encoder = new TextEncoder()
11
+ const newsletterQuery = async (jid, type, content) => (query({
12
+ tag: 'iq',
13
+ attrs: {
14
+ id: generateMessageTag(),
15
+ type,
16
+ xmlns: 'newsletter',
17
+ to: jid,
18
+ },
19
+ content
20
+ }))
21
+ const newsletterWMexQuery = async (jid, queryId, content) => (query({
22
+ tag: 'iq',
23
+ attrs: {
24
+ id: generateMessageTag(),
25
+ type: 'get',
26
+ xmlns: 'w:mex',
27
+ to: WABinary_1.S_WHATSAPP_NET,
28
+ },
29
+ content: [
30
+ {
31
+ tag: 'query',
32
+ attrs: { 'query_id': queryId },
33
+ content: encoder.encode(JSON.stringify({
34
+ variables: {
35
+ 'newsletter_id': jid,
36
+ ...content
37
+ }
38
+ }))
39
+ }
40
+ ]
41
+ }))
42
+ const parseFetchedUpdates = async (node, type) => {
43
+ let child
44
+ if (type === 'messages') {
45
+ child = WABinary_1.getBinaryNodeChild(node, 'messages')
46
+ }
47
+ else {
48
+ const parent = WABinary_1.getBinaryNodeChild(node, 'message_updates')
49
+ child = WABinary_1.getBinaryNodeChild(parent, 'messages')
50
+ }
51
+ return await Promise.all(WABinary_1.getAllBinaryNodeChildren(child).map(async (messageNode) => {
52
+ messageNode.attrs.from = child?.attrs.jid
53
+ const views = parseInt(WABinary_1.getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0')
54
+ const reactionNode = WABinary_1.getBinaryNodeChild(messageNode, 'reactions')
55
+ const reactions = WABinary_1.getBinaryNodeChildren(reactionNode, 'reaction')
56
+ .map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }))
57
+ const data = {
58
+ 'server_id': messageNode.attrs.server_id,
59
+ views,
60
+ reactions
61
+ }
62
+ if (type === 'messages') {
63
+ const { fullMessage: message, decrypt } = await Utils_1.decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger)
64
+ await decrypt()
65
+ data.message = message
66
+ }
67
+ return data
68
+ }))
69
+ }
70
+ return {
71
+ ...sock,
72
+ newsletterQuery,
73
+ newsletterWMexQuery,
74
+ subscribeNewsletterUpdates: async (jid) => {
75
+ const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }])
76
+ return WABinary_1.getBinaryNodeChild(result, 'live_updates')?.attrs
77
+ },
78
+ newsletterReactionMode: async (jid, mode) => {
79
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
80
+ updates: { settings: { 'reaction_codes': { value: mode } } }
81
+ })
82
+ },
83
+ newsletterUpdateDescription: async (jid, description) => {
84
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
85
+ updates: { description: description || '', settings: null }
86
+ })
87
+ },
88
+ newsletterUpdateName: async (jid, name) => {
89
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
90
+ updates: { name, settings: null }
91
+ })
92
+ },
93
+ newsletterUpdatePicture: async (jid, content) => {
94
+ const { img } = await Utils_1.generateProfilePicture(content)
95
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
96
+ updates: { picture: img.toString('base64'), settings: null }
97
+ })
98
+ },
99
+ newsletterRemovePicture: async (jid) => {
100
+ await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
101
+ updates: { picture: '', settings: null }
102
+ })
103
+ },
104
+ newsletterUnfollow: async (jid) => {
105
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW)
106
+ },
107
+ newsletterFollow: async (jid) => {
108
+ await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW)
109
+ },
110
+ newsletterUnmute: async (jid) => {
111
+ await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE)
112
+ },
113
+ newsletterMute: async (jid) => {
114
+ await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE)
115
+ },
116
+ newsletterAction: async (jid, type) => {
117
+ await newsletterWMexQuery(jid, Types_1.QueryIds[type.toUpperCase()])
118
+ },
119
+ newsletterCreate: async (name, description, picture) => {
120
+ //TODO: Implement TOS system wide for Meta AI, communities, and here etc.
121
+ /**tos query */
122
+ await query({
123
+ tag: 'iq',
124
+ attrs: {
125
+ to: WABinary_1.S_WHATSAPP_NET,
126
+ xmlns: 'tos',
127
+ id: generateMessageTag(),
128
+ type: 'set'
129
+ },
130
+ content: [
131
+ {
132
+ tag: 'notice',
133
+ attrs: {
134
+ id: '20601218',
135
+ stage: '5'
136
+ },
137
+ content: []
138
+ }
139
+ ]
140
+ })
141
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
142
+ input: {
143
+ name,
144
+ description: description || null,
145
+ picture: picture ? (await Utils_1.generateProfilePicture(picture)).img.toString('base64') : null,
146
+ settings: {
147
+ reaction_codes: {
148
+ value: 'ALL'
149
+ }
150
+ }
151
+ }
152
+ })
153
+ return extractNewsletterMetadata(result, true)
154
+ },
155
+ newsletterMetadata: async (type, key, role) => {
156
+ const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
157
+ input: {
158
+ key,
159
+ type: type.toUpperCase(),
160
+ view_role: role || 'GUEST'
161
+ },
162
+ fetch_viewer_metadata: true,
163
+ fetch_full_image: true,
164
+ fetch_creation_time: true
165
+ })
166
+ return extractNewsletterMetadata(result)
167
+ },
168
+ newsletterAdminCount: async (jid) => {
169
+ const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT)
170
+ const buff = WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString()
171
+ return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count
172
+ },
173
+ newsletterChangeOwner: async (jid, userLid) => {
174
+ await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
175
+ user_id: userLid
176
+ })
177
+ },
178
+ newsletterDemote: async (jid, userLid) => {
179
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
180
+ user_id: userLid
181
+ })
182
+ },
183
+ newsletterDelete: async (jid) => {
184
+ await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE)
185
+ },
186
+ /**if code wasn't passed, the reaction will be removed (if is reacted) */
187
+ newsletterReactMessage: async (jid, serverId, code) => {
188
+ await query({
189
+ tag: 'message',
190
+ attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id: serverId, id: Utils_1.generateMessageID() },
191
+ content: [{
192
+ tag: 'reaction',
193
+ attrs: code ? { code } : {}
194
+ }]
195
+ })
196
+ },
197
+ newsletterFetchMessages: async (type, key, count, after) => {
198
+ const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
199
+ {
200
+ tag: 'messages',
201
+ attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: after?.toString() || '100' }
202
+ }
203
+ ])
204
+ return await parseFetchedUpdates(result, 'messages')
205
+ },
206
+ newsletterFetchUpdates: async (jid, count, after, since) => {
207
+ const result = await newsletterQuery(jid, 'get', [
208
+ {
209
+ tag: 'message_updates',
210
+ attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
211
+ }
212
+ ])
213
+ return await parseFetchedUpdates(result, 'updates')
214
+ }
215
+ }
257
216
  }
258
-
259
217
  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
218
+ const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
219
+ const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
220
+ const metadata = {
221
+ id: metadataPath.id,
222
+ state: metadataPath.state.type,
223
+ creation_time: +metadataPath.thread_metadata.creation_time,
224
+ name: metadataPath.thread_metadata.name.text,
225
+ nameTime: +metadataPath.thread_metadata.name.update_time,
226
+ description: metadataPath.thread_metadata.description.text,
227
+ descriptionTime: +metadataPath.thread_metadata.description.update_time,
228
+ invite: metadataPath.thread_metadata.invite,
229
+ handle: metadataPath.thread_metadata.handle,
230
+ picture: Utils_1.getUrlFromDirectPath(metadataPath.thread_metadata.picture?.direct_path || ''),
231
+ preview: Utils_1.getUrlFromDirectPath(metadataPath.thread_metadata.preview?.direct_path || ''),
232
+ reaction_codes: metadataPath.thread_metadata?.settings?.reaction_codes?.value,
233
+ subscribers: +metadataPath.thread_metadata.subscribers_count,
234
+ verification: metadataPath.thread_metadata.verification,
235
+ viewer_metadata: metadataPath.viewer_metadata
236
+ }
237
+ return metadata
281
238
  }
282
-
283
239
  module.exports = {
284
- makeNewsletterSocket,
285
- extractNewsletterMetadata
240
+ makeNewsletterSocket,
241
+ extractNewsletterMetadata
286
242
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sanka-baileyss",
3
- "version": "2.3.6",
3
+ "version": "2.3.7",
4
4
  "description": "WhatsApp API Modification By Sanka_Vollerei",
5
5
  "keywords": [
6
6
  "Baileys",