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.
- package/lib/Socket/messages-send.js +964 -1276
- package/lib/Socket/newsletter.js +230 -274
- package/package.json +1 -1
package/lib/Socket/newsletter.js
CHANGED
|
@@ -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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
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
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
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
|
-
|
|
285
|
-
|
|
240
|
+
makeNewsletterSocket,
|
|
241
|
+
extractNewsletterMetadata
|
|
286
242
|
}
|