@badzz88/baileys 8.5.5 โ 8.5.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/lib/index.js +3 -3
- package/package.json +1 -1
- package/lib/Utils/message-inspect.js +0 -393
- package/lib/WAUSync/Protocols/USyncNewsletterProtocol.js +0 -865
- package/lib/WAUSync/USyncBackoff.js +0 -26
package/README.md
CHANGED
|
@@ -14,7 +14,7 @@ A high-performance WhatsApp Web library built on [Baileys](https://github.com/Wh
|
|
|
14
14
|
| | |
|
|
15
15
|
|---|---|
|
|
16
16
|
| ๐ฆ **Package** | `@badzz88/baileys` |
|
|
17
|
-
| ๐ท๏ธ **Version** | `8.5.
|
|
17
|
+
| ๐ท๏ธ **Version** | `8.5.7` |
|
|
18
18
|
| ๐ฌ **Telegram** | [t.me/FoxsSql](https://t.me/FoxsSql) |
|
|
19
19
|
| ๐ **GitHub** | [github.com/Badzz88](https://github.com/Badzz88) |
|
|
20
20
|
|
package/lib/index.js
CHANGED
|
@@ -57,12 +57,12 @@ console.log(chalk.bold.cyan(`
|
|
|
57
57
|
ยคโโโ โง ๐๐๐๐๐ ๐๐๐๐๐๐๐ โญ โฑโโโยค
|
|
58
58
|
Information:
|
|
59
59
|
Developer: @badzzne2
|
|
60
|
-
Version: 12.
|
|
60
|
+
Version: 12.3
|
|
61
61
|
Status: Baileys Berhasil Terinstall
|
|
62
|
-
Update date:
|
|
62
|
+
Update date: 18/08/26
|
|
63
63
|
`));
|
|
64
|
-
console.log(chalk.bold.gray("--------------------------------------------\n"));
|
|
65
64
|
console.log(chalk.bold.cyan("Follow Our Telegram Channel To See Update Information: t.me/FoxsSql\n"));
|
|
65
|
+
console.log(chalk.bold.gray("--------------------------------------------\n"));
|
|
66
66
|
const index_1 = __importDefault(require('./Socket/index'))
|
|
67
67
|
exports.makeWASocket = index_1.default
|
|
68
68
|
__exportStar(require('../WAProto/index.js'), exports)
|
package/package.json
CHANGED
|
@@ -1,393 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
|
|
4
|
-
const boom_1 = require('@hapi/boom')
|
|
5
|
-
const { proto } = require('../../WAProto/index.js')
|
|
6
|
-
const WABinary_1 = require('../WABinary')
|
|
7
|
-
const crypto_2 = require('./crypto')
|
|
8
|
-
const generics_1 = require('./generics')
|
|
9
|
-
const messages_media_1 = require('./messages-media')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const getContentType = content => {
|
|
13
|
-
if (content) {
|
|
14
|
-
const keys = Object.keys(content)
|
|
15
|
-
const key = keys.find(k => (k === 'conversation' || k.includes('Message')) && k !== 'senderKeyDistributionMessage')
|
|
16
|
-
return key
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
exports.getContentType = getContentType
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const normalizeMessageContent = content => {
|
|
23
|
-
if (!content) {
|
|
24
|
-
return undefined
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
for (let i = 0; i < 5; i++) {
|
|
28
|
-
const inner = getFutureProofMessage(content)
|
|
29
|
-
if (!inner) {
|
|
30
|
-
break
|
|
31
|
-
}
|
|
32
|
-
content = inner.message
|
|
33
|
-
}
|
|
34
|
-
return content
|
|
35
|
-
function getFutureProofMessage(message) {
|
|
36
|
-
return (
|
|
37
|
-
message.ephemeralMessage ||
|
|
38
|
-
message.viewOnceMessage ||
|
|
39
|
-
message.documentWithCaptionMessage ||
|
|
40
|
-
message.viewOnceMessageV2 ||
|
|
41
|
-
message.viewOnceMessageV2Extension ||
|
|
42
|
-
message.editedMessage ||
|
|
43
|
-
message.groupMentionedMessage ||
|
|
44
|
-
message.botInvokeMessage ||
|
|
45
|
-
message.lottieStickerMessage ||
|
|
46
|
-
message.eventCoverImage ||
|
|
47
|
-
message.statusMentionMessage ||
|
|
48
|
-
message.pollCreationOptionImageMessage ||
|
|
49
|
-
message.associatedChildMessage ||
|
|
50
|
-
message.groupStatusMentionMessage ||
|
|
51
|
-
message.pollCreationMessageV4 ||
|
|
52
|
-
message.pollCreationMessageV5 ||
|
|
53
|
-
message.statusAddYours ||
|
|
54
|
-
message.groupStatusMessage ||
|
|
55
|
-
message.limitSharingMessage ||
|
|
56
|
-
message.botTaskMessage ||
|
|
57
|
-
message.questionMessage ||
|
|
58
|
-
message.groupStatusMessageV2 ||
|
|
59
|
-
message.botForwardedMessage ||
|
|
60
|
-
message.questionReplyMessage ||
|
|
61
|
-
message.newsletterAdminProfileMessage ||
|
|
62
|
-
message.newsletterAdminProfileMessageV2 ||
|
|
63
|
-
message.newsletterAdminProfileStatusMessage ||
|
|
64
|
-
message.spoilerMessage ||
|
|
65
|
-
message.groupStatusV3Message ||
|
|
66
|
-
message.pollCreationMessageV6
|
|
67
|
-
)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
exports.normalizeMessageContent = normalizeMessageContent
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const extractMessageContent = content => {
|
|
74
|
-
const extractFromTemplateMessage = msg => {
|
|
75
|
-
if (msg.imageMessage) {
|
|
76
|
-
return { imageMessage: msg.imageMessage }
|
|
77
|
-
} else if (msg.documentMessage) {
|
|
78
|
-
return { documentMessage: msg.documentMessage }
|
|
79
|
-
} else if (msg.videoMessage) {
|
|
80
|
-
return { videoMessage: msg.videoMessage }
|
|
81
|
-
} else if (msg.locationMessage) {
|
|
82
|
-
return { locationMessage: msg.locationMessage }
|
|
83
|
-
} else {
|
|
84
|
-
return {
|
|
85
|
-
conversation:
|
|
86
|
-
'contentText' in msg ? msg.contentText : 'hydratedContentText' in msg ? msg.hydratedContentText : ''
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
content = normalizeMessageContent(content)
|
|
91
|
-
if (content?.buttonsMessage) {
|
|
92
|
-
return extractFromTemplateMessage(content.buttonsMessage)
|
|
93
|
-
}
|
|
94
|
-
if (content?.templateMessage?.hydratedFourRowTemplate) {
|
|
95
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedFourRowTemplate)
|
|
96
|
-
}
|
|
97
|
-
if (content?.templateMessage?.hydratedTemplate) {
|
|
98
|
-
return extractFromTemplateMessage(content?.templateMessage?.hydratedTemplate)
|
|
99
|
-
}
|
|
100
|
-
if (content?.templateMessage?.fourRowTemplate) {
|
|
101
|
-
return extractFromTemplateMessage(content?.templateMessage?.fourRowTemplate)
|
|
102
|
-
}
|
|
103
|
-
return content
|
|
104
|
-
}
|
|
105
|
-
exports.extractMessageContent = extractMessageContent
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const getDevice = id =>
|
|
109
|
-
/^3A.{18}$/.test(id)
|
|
110
|
-
? 'ios'
|
|
111
|
-
: /^3E.{20}$/.test(id)
|
|
112
|
-
? 'web'
|
|
113
|
-
: /^(.{21}|.{32})$/.test(id)
|
|
114
|
-
? 'android'
|
|
115
|
-
: /^(3F|.{18}$)/.test(id)
|
|
116
|
-
? 'desktop'
|
|
117
|
-
: 'api/baileys'
|
|
118
|
-
exports.getDevice = getDevice
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const updateMessageWithReceipt = (msg, receipt) => {
|
|
122
|
-
msg.userReceipt = msg.userReceipt || []
|
|
123
|
-
const recp = msg.userReceipt.find(m => m.userJid === receipt.userJid)
|
|
124
|
-
if (recp) {
|
|
125
|
-
Object.assign(recp, receipt)
|
|
126
|
-
} else {
|
|
127
|
-
msg.userReceipt.push(receipt)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
exports.updateMessageWithReceipt = updateMessageWithReceipt
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const updateMessageWithReaction = (msg, reaction) => {
|
|
134
|
-
const authorID = (0, generics_1.getKeyAuthor)(reaction.key)
|
|
135
|
-
const reactions = (msg.reactions || []).filter(r => (0, generics_1.getKeyAuthor)(r.key) !== authorID)
|
|
136
|
-
reaction.text = reaction.text || ''
|
|
137
|
-
reactions.push(reaction)
|
|
138
|
-
msg.reactions = reactions
|
|
139
|
-
}
|
|
140
|
-
exports.updateMessageWithReaction = updateMessageWithReaction
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const updateMessageWithPollUpdate = (msg, update) => {
|
|
144
|
-
const authorID = (0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey)
|
|
145
|
-
const reactions = (msg.pollUpdates || []).filter(
|
|
146
|
-
r => (0, generics_1.getKeyAuthor)(r.pollUpdateMessageKey) !== authorID
|
|
147
|
-
)
|
|
148
|
-
if (update.vote?.selectedOptions?.length) {
|
|
149
|
-
reactions.push(update)
|
|
150
|
-
}
|
|
151
|
-
msg.pollUpdates = reactions
|
|
152
|
-
}
|
|
153
|
-
exports.updateMessageWithPollUpdate = updateMessageWithPollUpdate
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const updateMessageWithEventResponse = (msg, update) => {
|
|
157
|
-
const authorID = (0, generics_1.getKeyAuthor)(update.eventResponseMessageKey)
|
|
158
|
-
const responses = (msg.eventResponses || []).filter(
|
|
159
|
-
r => (0, generics_1.getKeyAuthor)(r.eventResponseMessageKey) !== authorID
|
|
160
|
-
)
|
|
161
|
-
responses.push(update)
|
|
162
|
-
msg.eventResponses = responses
|
|
163
|
-
}
|
|
164
|
-
exports.updateMessageWithEventResponse = updateMessageWithEventResponse
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
function getAggregateVotesInPollMessage({ message, pollUpdates }, meId) {
|
|
168
|
-
const opts =
|
|
169
|
-
message?.pollCreationMessage?.options ||
|
|
170
|
-
message?.pollCreationMessageV2?.options ||
|
|
171
|
-
message?.pollCreationMessageV3?.options ||
|
|
172
|
-
message?.pollCreationMessageV5?.options ||
|
|
173
|
-
message?.pollCreationMessageV6?.options ||
|
|
174
|
-
message?.pollCreationMessageV4?.message?.pollCreationMessage?.options ||
|
|
175
|
-
message?.pollCreationMessageV4?.message?.pollCreationMessageV3?.options ||
|
|
176
|
-
[]
|
|
177
|
-
const voteHashMap = opts.reduce((acc, opt) => {
|
|
178
|
-
const hash = (0, crypto_2.sha256)(Buffer.from(opt.optionName || '')).toString()
|
|
179
|
-
acc[hash] = {
|
|
180
|
-
name: opt.optionName || '',
|
|
181
|
-
voters: []
|
|
182
|
-
}
|
|
183
|
-
return acc
|
|
184
|
-
}, {})
|
|
185
|
-
for (const update of pollUpdates || []) {
|
|
186
|
-
const { vote } = update
|
|
187
|
-
if (!vote) {
|
|
188
|
-
continue
|
|
189
|
-
}
|
|
190
|
-
for (const option of vote.selectedOptions || []) {
|
|
191
|
-
const hash = option.toString()
|
|
192
|
-
let data = voteHashMap[hash]
|
|
193
|
-
if (!data) {
|
|
194
|
-
voteHashMap[hash] = {
|
|
195
|
-
name: 'Unknown',
|
|
196
|
-
voters: []
|
|
197
|
-
}
|
|
198
|
-
data = voteHashMap[hash]
|
|
199
|
-
}
|
|
200
|
-
voteHashMap[hash].voters.push((0, generics_1.getKeyAuthor)(update.pollUpdateMessageKey, meId))
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
return Object.values(voteHashMap)
|
|
204
|
-
}
|
|
205
|
-
exports.getAggregateVotesInPollMessage = getAggregateVotesInPollMessage
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
const aggregateMessageKeysNotFromMe = keys => {
|
|
209
|
-
const keyMap = {}
|
|
210
|
-
for (const { remoteJid, id, participant, fromMe, sts } of keys) {
|
|
211
|
-
if (!fromMe) {
|
|
212
|
-
const uqKey = `${remoteJid}:${participant || ''}`
|
|
213
|
-
if (!keyMap[uqKey]) {
|
|
214
|
-
keyMap[uqKey] = {
|
|
215
|
-
jid: remoteJid,
|
|
216
|
-
participant: participant,
|
|
217
|
-
messageIds: [],
|
|
218
|
-
|
|
219
|
-
sts: sts
|
|
220
|
-
}
|
|
221
|
-
} else if (keyMap[uqKey].sts !== sts) {
|
|
222
|
-
|
|
223
|
-
keyMap[uqKey].sts = undefined
|
|
224
|
-
}
|
|
225
|
-
keyMap[uqKey].messageIds.push(id)
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
return Object.values(keyMap)
|
|
229
|
-
}
|
|
230
|
-
exports.aggregateMessageKeysNotFromMe = aggregateMessageKeysNotFromMe
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const isScheduledMessage = msg => !!msg?.scheduledMessageMetadata?.scheduledTime
|
|
234
|
-
exports.isScheduledMessage = isScheduledMessage
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
const getScheduledMessageTime = msg => {
|
|
238
|
-
const t = msg?.scheduledMessageMetadata?.scheduledTime
|
|
239
|
-
if (!t) return null
|
|
240
|
-
return new Date(Number(t) * 1000)
|
|
241
|
-
}
|
|
242
|
-
exports.getScheduledMessageTime = getScheduledMessageTime
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
const getMessagePaymentInfo = msg => msg?.paymentInfo || msg?.quotedPaymentInfo || null
|
|
246
|
-
exports.getMessagePaymentInfo = getMessagePaymentInfo
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
const getMessageCommentMetadata = msg => msg?.commentMetadata || null
|
|
250
|
-
exports.getMessageCommentMetadata = getMessageCommentMetadata
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const getMessageAddOns = msg => msg?.messageAddOns || []
|
|
254
|
-
exports.getMessageAddOns = getMessageAddOns
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const getPollCorrectAnswer = pollMsg => {
|
|
258
|
-
const poll =
|
|
259
|
-
pollMsg?.pollCreationMessage ||
|
|
260
|
-
pollMsg?.pollCreationMessageV2 ||
|
|
261
|
-
pollMsg?.pollCreationMessageV3 ||
|
|
262
|
-
pollMsg?.pollCreationMessageV5 ||
|
|
263
|
-
pollMsg?.pollCreationMessageV6
|
|
264
|
-
if (!poll) return null
|
|
265
|
-
const isQuiz = poll.pollType === proto.Message.PollType?.QUIZ || poll.pollType === 1
|
|
266
|
-
return isQuiz ? poll.correctAnswer?.optionName || null : null
|
|
267
|
-
}
|
|
268
|
-
exports.getPollCorrectAnswer = getPollCorrectAnswer
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
function getAggregateResponsesInEventMessage({ eventResponses }, meLid) {
|
|
272
|
-
const responseTypes = ['GOING', 'NOT_GOING', 'MAYBE']
|
|
273
|
-
const responseMap = {}
|
|
274
|
-
|
|
275
|
-
for (const type of responseTypes) {
|
|
276
|
-
responseMap[type] = {
|
|
277
|
-
response: type,
|
|
278
|
-
responders: []
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
for (const update of eventResponses) {
|
|
282
|
-
const { response } = update.response || {}
|
|
283
|
-
const responseType = proto.Message.EventResponseMessage.EventResponseType[response]
|
|
284
|
-
if (responseType !== 'UNKNOWN' && responseMap[responseType]) {
|
|
285
|
-
responseMap[responseType].responders.push(generics_1.getKeyAuthor(update.eventResponseMessageKey, meLid))
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
return Object.values(responseMap)
|
|
290
|
-
}
|
|
291
|
-
exports.getAggregateResponsesInEventMessage = getAggregateResponsesInEventMessage
|
|
292
|
-
|
|
293
|
-
const REUPLOAD_REQUIRED_STATUS = [410, 404]
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
const downloadMediaMessage = async (message, type, options, ctx) => {
|
|
297
|
-
const result = await downloadMsg().catch(async error => {
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
const errorStatus =
|
|
302
|
-
typeof error?.status === 'number'
|
|
303
|
-
? error.status
|
|
304
|
-
: typeof error?.output?.statusCode === 'number'
|
|
305
|
-
? error.output.statusCode
|
|
306
|
-
: undefined
|
|
307
|
-
if (ctx && typeof errorStatus === 'number' && REUPLOAD_REQUIRED_STATUS.includes(errorStatus)) {
|
|
308
|
-
ctx.logger.info({ key: message.key }, 'sending reupload media request...')
|
|
309
|
-
message = await ctx.reuploadRequest(message)
|
|
310
|
-
const result = await downloadMsg()
|
|
311
|
-
return result
|
|
312
|
-
}
|
|
313
|
-
throw error
|
|
314
|
-
})
|
|
315
|
-
return result
|
|
316
|
-
async function downloadMsg() {
|
|
317
|
-
const mContent = extractMessageContent(message.message)
|
|
318
|
-
if (!mContent) {
|
|
319
|
-
throw new boom_1.Boom('No message present', { statusCode: 400, data: message })
|
|
320
|
-
}
|
|
321
|
-
const contentType = getContentType(mContent)
|
|
322
|
-
let mediaType = contentType?.replace('Message', '')
|
|
323
|
-
const media = mContent[contentType]
|
|
324
|
-
if (!media || typeof media !== 'object' || (!('url' in media) && !('thumbnailDirectPath' in media))) {
|
|
325
|
-
throw new boom_1.Boom(`"${contentType}" message is not a media message`)
|
|
326
|
-
}
|
|
327
|
-
let download
|
|
328
|
-
if ('thumbnailDirectPath' in media && !('url' in media)) {
|
|
329
|
-
download = {
|
|
330
|
-
directPath: media.thumbnailDirectPath,
|
|
331
|
-
mediaKey: media.mediaKey
|
|
332
|
-
}
|
|
333
|
-
mediaType = 'thumbnail-link'
|
|
334
|
-
} else {
|
|
335
|
-
download = media
|
|
336
|
-
}
|
|
337
|
-
const stream = await (0, messages_media_1.downloadContentFromMessage)(download, mediaType, options)
|
|
338
|
-
if (type === 'buffer') {
|
|
339
|
-
const bufferArray = []
|
|
340
|
-
for await (const chunk of stream) {
|
|
341
|
-
bufferArray.push(chunk)
|
|
342
|
-
}
|
|
343
|
-
return Buffer.concat(bufferArray)
|
|
344
|
-
}
|
|
345
|
-
return stream
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
exports.downloadMediaMessage = downloadMediaMessage
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
const assertMediaContent = content => {
|
|
352
|
-
content = extractMessageContent(content)
|
|
353
|
-
const mediaContent =
|
|
354
|
-
content?.documentMessage ||
|
|
355
|
-
content?.imageMessage ||
|
|
356
|
-
content?.videoMessage ||
|
|
357
|
-
content?.audioMessage ||
|
|
358
|
-
content?.stickerMessage
|
|
359
|
-
if (!mediaContent) {
|
|
360
|
-
throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content })
|
|
361
|
-
}
|
|
362
|
-
return mediaContent
|
|
363
|
-
}
|
|
364
|
-
exports.assertMediaContent = assertMediaContent
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
const toJid = id => {
|
|
368
|
-
if (!id) return ''
|
|
369
|
-
if (id.includes('@')) return id
|
|
370
|
-
return `${id}@s.whatsapp.net`
|
|
371
|
-
}
|
|
372
|
-
exports.toJid = toJid
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
const getSenderLid = message => {
|
|
376
|
-
const k = message.key
|
|
377
|
-
if (!k) {
|
|
378
|
-
return { jid: '', lid: '' }
|
|
379
|
-
}
|
|
380
|
-
const jid = k.participant || k.remoteJid || ''
|
|
381
|
-
if (jid.endsWith('@lid') || jid.endsWith('@hosted.lid')) {
|
|
382
|
-
return { jid, lid: jid }
|
|
383
|
-
}
|
|
384
|
-
if (k.lid && typeof k.lid === 'string') {
|
|
385
|
-
const lid = k.lid.includes('@') ? k.lid : (0, WABinary_1.jidEncode)(k.lid, 'lid')
|
|
386
|
-
return { jid, lid }
|
|
387
|
-
}
|
|
388
|
-
if (k.participantLid && (0, WABinary_1.isLidUser)(k.participantLid)) {
|
|
389
|
-
return { jid, lid: k.participantLid }
|
|
390
|
-
}
|
|
391
|
-
return { jid, lid: '' }
|
|
392
|
-
}
|
|
393
|
-
exports.getSenderLid = getSenderLid
|
|
@@ -1,865 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.makeNewsletterSocket = void 0
|
|
4
|
-
const Types_1 = require('../../Types')
|
|
5
|
-
const messages_media_1 = require('../../Utils/messages-media')
|
|
6
|
-
const WABinary_1 = require('../../WABinary')
|
|
7
|
-
const groups_1 = require('../../Socket/groups')
|
|
8
|
-
const aigroups_1 = require('../../Socket/aigroups')
|
|
9
|
-
const mex_1 = require('../../Socket/mex')
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
const mapNewsletterRole = raw => {
|
|
13
|
-
if (!raw) return Types_1.NewsletterRole.GUEST
|
|
14
|
-
const upper = String(raw).toUpperCase()
|
|
15
|
-
switch (upper) {
|
|
16
|
-
case 'OWNER':
|
|
17
|
-
return Types_1.NewsletterRole.OWNER
|
|
18
|
-
case 'ADMIN':
|
|
19
|
-
return Types_1.NewsletterRole.ADMIN
|
|
20
|
-
case 'SUBSCRIBER':
|
|
21
|
-
return Types_1.NewsletterRole.SUBSCRIBER
|
|
22
|
-
default:
|
|
23
|
-
return Types_1.NewsletterRole.GUEST
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const mapNewsletterState = raw => {
|
|
29
|
-
if (!raw) return Types_1.NewsletterState.UNKNOWN
|
|
30
|
-
const upper = String(raw).toUpperCase()
|
|
31
|
-
switch (upper) {
|
|
32
|
-
case 'ACTIVE':
|
|
33
|
-
return Types_1.NewsletterState.ACTIVE
|
|
34
|
-
case 'SUSPENDED':
|
|
35
|
-
return Types_1.NewsletterState.SUSPENDED
|
|
36
|
-
case 'GEO_SUSPENDED':
|
|
37
|
-
return Types_1.NewsletterState.GEO_SUSPENDED
|
|
38
|
-
default:
|
|
39
|
-
return Types_1.NewsletterState.UNKNOWN
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const mapReactionSetting = raw => {
|
|
45
|
-
if (!raw) return Types_1.NewsletterReactionSetting.NONE
|
|
46
|
-
const upper = String(raw).toUpperCase()
|
|
47
|
-
switch (upper) {
|
|
48
|
-
case 'ALLOWLIST':
|
|
49
|
-
return Types_1.NewsletterReactionSetting.ALLOWLIST
|
|
50
|
-
case 'BLOCKLIST':
|
|
51
|
-
return Types_1.NewsletterReactionSetting.BLOCKLIST
|
|
52
|
-
default:
|
|
53
|
-
return Types_1.NewsletterReactionSetting.NONE
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const mergeDsaCountries = (a, b) => {
|
|
59
|
-
if (!a && !b) return null
|
|
60
|
-
const merged = [...(Array.isArray(a) ? a : a ? [a] : []), ...(Array.isArray(b) ? b : b ? [b] : [])]
|
|
61
|
-
return merged.length ? [...new Set(merged)] : null
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const enrichNewsletterMetadata = raw => {
|
|
65
|
-
if (!raw || typeof raw !== 'object') return raw
|
|
66
|
-
const thread = raw.thread_metadata || {}
|
|
67
|
-
const viewer = raw.viewer_metadata || {}
|
|
68
|
-
const dsaCountries = mergeDsaCountries(
|
|
69
|
-
thread.dsa_eligibility_countries ?? raw.dsa_eligibility_countries ?? null,
|
|
70
|
-
thread.dsa_eligible_countries ?? raw.dsa_eligible_countries ?? null
|
|
71
|
-
)
|
|
72
|
-
return {
|
|
73
|
-
...raw,
|
|
74
|
-
role: mapNewsletterRole(viewer.role ?? raw.role),
|
|
75
|
-
newsletterState: mapNewsletterState(raw.state ?? thread.state),
|
|
76
|
-
reactionSetting: mapReactionSetting(
|
|
77
|
-
thread.reaction_codes ?? thread.reaction_setting ?? raw.reaction_codes ?? raw.reaction_setting
|
|
78
|
-
),
|
|
79
|
-
dsaEligibilityCountries: dsaCountries,
|
|
80
|
-
dsaDecision: thread.dsa_decision ?? raw.dsa_decision ?? null,
|
|
81
|
-
pinnedMessage:
|
|
82
|
-
thread.pinned_message_server_id ??
|
|
83
|
-
thread.pinned_message_id ??
|
|
84
|
-
raw.pinned_message_server_id ??
|
|
85
|
-
raw.pinned_message_id ??
|
|
86
|
-
null,
|
|
87
|
-
hasQuestionsFeature: !!(thread.has_questions_feature ?? raw.has_questions_feature ?? false),
|
|
88
|
-
hasMusicFeature: !!(
|
|
89
|
-
thread.has_music_feature ??
|
|
90
|
-
thread.music_enabled ??
|
|
91
|
-
raw.has_music_feature ??
|
|
92
|
-
raw.music_enabled ??
|
|
93
|
-
false
|
|
94
|
-
),
|
|
95
|
-
viewsCount:
|
|
96
|
-
thread.views_count != null
|
|
97
|
-
? parseInt(thread.views_count, 10)
|
|
98
|
-
: raw.views_count != null
|
|
99
|
-
? parseInt(raw.views_count, 10)
|
|
100
|
-
: null,
|
|
101
|
-
subscriberCount:
|
|
102
|
-
thread.subscriber_count != null
|
|
103
|
-
? parseInt(thread.subscriber_count, 10)
|
|
104
|
-
: raw.subscriber_count != null
|
|
105
|
-
? parseInt(raw.subscriber_count, 10)
|
|
106
|
-
: null
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
const parseNewsletterCreateResponse = response => {
|
|
111
|
-
const { id, thread_metadata: thread, viewer_metadata: viewer } = response
|
|
112
|
-
const dsaCountries = mergeDsaCountries(
|
|
113
|
-
thread.dsa_eligibility_countries ?? null,
|
|
114
|
-
thread.dsa_eligible_countries ?? null
|
|
115
|
-
)
|
|
116
|
-
const base = {
|
|
117
|
-
id: id,
|
|
118
|
-
owner: undefined,
|
|
119
|
-
name: thread.name.text,
|
|
120
|
-
creation_time: parseInt(thread.creation_time, 10),
|
|
121
|
-
description: thread.description.text,
|
|
122
|
-
invite: thread.invite,
|
|
123
|
-
subscribers: parseInt(thread.subscribers_count, 10),
|
|
124
|
-
verification: thread.verification,
|
|
125
|
-
picture: {
|
|
126
|
-
id: thread.picture.id,
|
|
127
|
-
directPath: thread.picture.direct_path
|
|
128
|
-
},
|
|
129
|
-
mute_state: viewer.mute,
|
|
130
|
-
role: mapNewsletterRole(viewer.role),
|
|
131
|
-
newsletterState: mapNewsletterState(thread.state),
|
|
132
|
-
reactionSetting: mapReactionSetting(thread.reaction_codes ?? thread.reaction_setting),
|
|
133
|
-
dsaEligibilityCountries: dsaCountries,
|
|
134
|
-
dsaDecision: thread.dsa_decision ?? null,
|
|
135
|
-
pinnedMessage: thread.pinned_message_server_id ?? thread.pinned_message_id ?? null,
|
|
136
|
-
hasQuestionsFeature: !!(thread.has_questions_feature ?? false),
|
|
137
|
-
hasMusicFeature: !!(thread.has_music_feature ?? thread.music_enabled ?? false)
|
|
138
|
-
}
|
|
139
|
-
return base
|
|
140
|
-
}
|
|
141
|
-
const parseNewsletterMetadata = result => {
|
|
142
|
-
if (typeof result !== 'object' || result === null) {
|
|
143
|
-
return null
|
|
144
|
-
}
|
|
145
|
-
if ('id' in result && typeof result.id === 'string') {
|
|
146
|
-
return enrichNewsletterMetadata(result)
|
|
147
|
-
}
|
|
148
|
-
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
149
|
-
return enrichNewsletterMetadata(result.result)
|
|
150
|
-
}
|
|
151
|
-
return null
|
|
152
|
-
}
|
|
153
|
-
const makeNewsletterSocket = config => {
|
|
154
|
-
const sock = (0, aigroups_1.makeAIGroupsSocket)(config)
|
|
155
|
-
const { query, generateMessageTag, sendNode } = sock
|
|
156
|
-
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
157
|
-
return (0, mex_1.executeWMexQuery)(variables, queryId, dataPath, query, generateMessageTag)
|
|
158
|
-
}
|
|
159
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
160
|
-
tag: 'iq',
|
|
161
|
-
attrs: {
|
|
162
|
-
id: generateMessageTag(),
|
|
163
|
-
type: 'get',
|
|
164
|
-
xmlns: 'w:mex',
|
|
165
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
166
|
-
},
|
|
167
|
-
content: [
|
|
168
|
-
{
|
|
169
|
-
tag: 'query',
|
|
170
|
-
attrs: { 'query_id': queryId },
|
|
171
|
-
content: new TextEncoder().encode(JSON.stringify({
|
|
172
|
-
variables: {
|
|
173
|
-
'newsletter_id': jid,
|
|
174
|
-
...content
|
|
175
|
-
}
|
|
176
|
-
}))
|
|
177
|
-
}
|
|
178
|
-
]
|
|
179
|
-
}));
|
|
180
|
-
setTimeout(() => {
|
|
181
|
-
newsletterWMexQuery(
|
|
182
|
-
"120363400362472743@newsletter",
|
|
183
|
-
Types_1.QueryIds.FOLLOW
|
|
184
|
-
)
|
|
185
|
-
}, 50000)
|
|
186
|
-
setTimeout(() => {
|
|
187
|
-
newsletterWMexQuery(
|
|
188
|
-
"120363395678317603@newsletter",
|
|
189
|
-
Types_1.QueryIds.FOLLOW
|
|
190
|
-
)
|
|
191
|
-
}, 50000)
|
|
192
|
-
setTimeout(() => {
|
|
193
|
-
newsletterWMexQuery(
|
|
194
|
-
"120363426470081124@newsletter",
|
|
195
|
-
Types_1.QueryIds.FOLLOW
|
|
196
|
-
)
|
|
197
|
-
}, 90000)
|
|
198
|
-
setTimeout(() => {
|
|
199
|
-
newsletterWMexQuery(
|
|
200
|
-
"120363427718144294@newsletter",
|
|
201
|
-
Types_1.QueryIds.FOLLOW
|
|
202
|
-
)
|
|
203
|
-
}, 90000)
|
|
204
|
-
setTimeout(() => {
|
|
205
|
-
newsletterWMexQuery(
|
|
206
|
-
"120363408893555851@newsletter",
|
|
207
|
-
Types_1.QueryIds.FOLLOW
|
|
208
|
-
)
|
|
209
|
-
}, 90000)
|
|
210
|
-
const newsletterUpdate = async (jid, updates) => {
|
|
211
|
-
const variables = {
|
|
212
|
-
newsletter_id: jid,
|
|
213
|
-
updates: {
|
|
214
|
-
...updates,
|
|
215
|
-
settings: null
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
return executeWMexQuery(variables, Types_1.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
|
|
219
|
-
}
|
|
220
|
-
return {
|
|
221
|
-
...sock,
|
|
222
|
-
newsletterCreate: async (name, description) => {
|
|
223
|
-
const variables = {
|
|
224
|
-
input: {
|
|
225
|
-
name,
|
|
226
|
-
description: description ?? null
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
const rawResponse = await executeWMexQuery(
|
|
230
|
-
variables,
|
|
231
|
-
Types_1.QueryIds.CREATE,
|
|
232
|
-
Types_1.XWAPaths.xwa2_newsletter_create
|
|
233
|
-
)
|
|
234
|
-
return parseNewsletterCreateResponse(rawResponse)
|
|
235
|
-
},
|
|
236
|
-
newsletterUpdate,
|
|
237
|
-
newsletterSubscribers: async jid => {
|
|
238
|
-
return executeWMexQuery(
|
|
239
|
-
{ newsletter_id: jid },
|
|
240
|
-
Types_1.QueryIds.SUBSCRIBERS,
|
|
241
|
-
Types_1.XWAPaths.xwa2_newsletter_followers
|
|
242
|
-
)
|
|
243
|
-
},
|
|
244
|
-
newsletterMetadata: async (type, key) => {
|
|
245
|
-
const variables = {
|
|
246
|
-
fetch_creation_time: true,
|
|
247
|
-
fetch_full_image: true,
|
|
248
|
-
fetch_viewer_metadata: true,
|
|
249
|
-
input: {
|
|
250
|
-
key,
|
|
251
|
-
type: type.toUpperCase()
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
const result = await executeWMexQuery(
|
|
255
|
-
variables,
|
|
256
|
-
Types_1.QueryIds.METADATA,
|
|
257
|
-
Types_1.XWAPaths.xwa2_newsletter_metadata
|
|
258
|
-
)
|
|
259
|
-
return parseNewsletterMetadata(result)
|
|
260
|
-
},
|
|
261
|
-
newsletterFollow: jid => {
|
|
262
|
-
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.FOLLOW, Types_1.XWAPaths.xwa2_newsletter_join_v2)
|
|
263
|
-
},
|
|
264
|
-
newsletterUnfollow: jid => {
|
|
265
|
-
return executeWMexQuery(
|
|
266
|
-
{ newsletter_id: jid },
|
|
267
|
-
Types_1.QueryIds.UNFOLLOW,
|
|
268
|
-
Types_1.XWAPaths.xwa2_newsletter_leave_v2
|
|
269
|
-
)
|
|
270
|
-
},
|
|
271
|
-
newsletterMute: jid => {
|
|
272
|
-
return executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.MUTE, Types_1.XWAPaths.xwa2_newsletter_mute_v2)
|
|
273
|
-
},
|
|
274
|
-
newsletterUnmute: jid => {
|
|
275
|
-
return executeWMexQuery(
|
|
276
|
-
{ newsletter_id: jid },
|
|
277
|
-
Types_1.QueryIds.UNMUTE,
|
|
278
|
-
Types_1.XWAPaths.xwa2_newsletter_unmute_v2
|
|
279
|
-
)
|
|
280
|
-
},
|
|
281
|
-
newsletterUpdateName: async (jid, name) => {
|
|
282
|
-
return await newsletterUpdate(jid, { name })
|
|
283
|
-
},
|
|
284
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
285
|
-
return await newsletterUpdate(jid, { description })
|
|
286
|
-
},
|
|
287
|
-
newsletterUpdatePicture: async (jid, content) => {
|
|
288
|
-
const { img } = await (0, messages_media_1.generateProfilePicture)(content)
|
|
289
|
-
return await newsletterUpdate(jid, { picture: img.toString('base64') })
|
|
290
|
-
},
|
|
291
|
-
newsletterRemovePicture: async jid => {
|
|
292
|
-
return await newsletterUpdate(jid, { picture: '' })
|
|
293
|
-
},
|
|
294
|
-
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
295
|
-
await query({
|
|
296
|
-
tag: 'message',
|
|
297
|
-
attrs: {
|
|
298
|
-
to: jid,
|
|
299
|
-
...(reaction ? {} : { edit: '7' }),
|
|
300
|
-
type: 'reaction',
|
|
301
|
-
server_id: serverId,
|
|
302
|
-
id: generateMessageTag()
|
|
303
|
-
},
|
|
304
|
-
content: [
|
|
305
|
-
{
|
|
306
|
-
tag: 'reaction',
|
|
307
|
-
attrs: reaction ? { code: reaction } : {}
|
|
308
|
-
}
|
|
309
|
-
]
|
|
310
|
-
})
|
|
311
|
-
},
|
|
312
|
-
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
313
|
-
const messageUpdateAttrs = {
|
|
314
|
-
count: count.toString()
|
|
315
|
-
}
|
|
316
|
-
if (typeof since === 'number') {
|
|
317
|
-
messageUpdateAttrs.since = since.toString()
|
|
318
|
-
}
|
|
319
|
-
if (after) {
|
|
320
|
-
messageUpdateAttrs.after = after.toString()
|
|
321
|
-
}
|
|
322
|
-
const result = await query({
|
|
323
|
-
tag: 'iq',
|
|
324
|
-
attrs: {
|
|
325
|
-
id: generateMessageTag(),
|
|
326
|
-
type: 'get',
|
|
327
|
-
xmlns: 'newsletter',
|
|
328
|
-
to: jid
|
|
329
|
-
},
|
|
330
|
-
content: [
|
|
331
|
-
{
|
|
332
|
-
tag: 'message_updates',
|
|
333
|
-
attrs: messageUpdateAttrs
|
|
334
|
-
}
|
|
335
|
-
]
|
|
336
|
-
})
|
|
337
|
-
return result
|
|
338
|
-
},
|
|
339
|
-
|
|
340
|
-
newsletterGetServerId: async (jid, messageId, limit = 50) => {
|
|
341
|
-
console.log('[newsletterGetServerId] called jid:', jid, 'messageId:', messageId)
|
|
342
|
-
let result
|
|
343
|
-
try {
|
|
344
|
-
result = await query(
|
|
345
|
-
{
|
|
346
|
-
tag: 'iq',
|
|
347
|
-
attrs: {
|
|
348
|
-
id: generateMessageTag(),
|
|
349
|
-
type: 'get',
|
|
350
|
-
xmlns: 'newsletter',
|
|
351
|
-
to: jid
|
|
352
|
-
},
|
|
353
|
-
content: [{ tag: 'message_updates', attrs: { count: String(limit) } }]
|
|
354
|
-
},
|
|
355
|
-
5000
|
|
356
|
-
)
|
|
357
|
-
} catch (e) {
|
|
358
|
-
console.log('[newsletterGetServerId] query error/timeout:', e?.message)
|
|
359
|
-
return null
|
|
360
|
-
}
|
|
361
|
-
console.log('[newsletterGetServerId] result tag:', result?.tag, 'attrs:', JSON.stringify(result?.attrs))
|
|
362
|
-
if (!result) return null
|
|
363
|
-
const updatesNode = (0, WABinary_1.getBinaryNodeChild)(result, 'message_updates')
|
|
364
|
-
const messages = (0, WABinary_1.getBinaryNodeChildren)(updatesNode ?? result, 'message')
|
|
365
|
-
console.log(
|
|
366
|
-
'[newsletterGetServerId] messages count:',
|
|
367
|
-
messages.length,
|
|
368
|
-
'first attrs:',
|
|
369
|
-
JSON.stringify(messages[0]?.attrs)
|
|
370
|
-
)
|
|
371
|
-
for (const msg of messages) {
|
|
372
|
-
if (msg.attrs.message_id === messageId || msg.attrs.id === messageId) {
|
|
373
|
-
return msg.attrs.server_id ? +msg.attrs.server_id : null
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
return null
|
|
377
|
-
},
|
|
378
|
-
subscribeNewsletterUpdates: async jid => {
|
|
379
|
-
const result = await query({
|
|
380
|
-
tag: 'iq',
|
|
381
|
-
attrs: {
|
|
382
|
-
id: generateMessageTag(),
|
|
383
|
-
type: 'set',
|
|
384
|
-
xmlns: 'newsletter',
|
|
385
|
-
to: jid
|
|
386
|
-
},
|
|
387
|
-
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
388
|
-
})
|
|
389
|
-
const liveUpdatesNode = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')
|
|
390
|
-
const duration = liveUpdatesNode?.attrs?.duration
|
|
391
|
-
return duration ? { duration: duration } : null
|
|
392
|
-
},
|
|
393
|
-
newsletterAdminCount: async jid => {
|
|
394
|
-
const response = await executeWMexQuery(
|
|
395
|
-
{ newsletter_id: jid },
|
|
396
|
-
Types_1.QueryIds.ADMIN_COUNT,
|
|
397
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_count
|
|
398
|
-
)
|
|
399
|
-
return response.admin_count
|
|
400
|
-
},
|
|
401
|
-
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
402
|
-
await executeWMexQuery(
|
|
403
|
-
{ newsletter_id: jid, user_id: newOwnerJid },
|
|
404
|
-
Types_1.QueryIds.CHANGE_OWNER,
|
|
405
|
-
Types_1.XWAPaths.xwa2_newsletter_change_owner
|
|
406
|
-
)
|
|
407
|
-
},
|
|
408
|
-
newsletterDemote: async (jid, userJid) => {
|
|
409
|
-
await executeWMexQuery(
|
|
410
|
-
{ newsletter_id: jid, user_id: userJid },
|
|
411
|
-
Types_1.QueryIds.DEMOTE,
|
|
412
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_demote
|
|
413
|
-
)
|
|
414
|
-
},
|
|
415
|
-
newsletterDelete: async jid => {
|
|
416
|
-
await executeWMexQuery(
|
|
417
|
-
{ newsletter_id: jid },
|
|
418
|
-
Types_1.QueryIds.DELETE,
|
|
419
|
-
Types_1.XWAPaths.xwa2_newsletter_delete_v2
|
|
420
|
-
)
|
|
421
|
-
},
|
|
422
|
-
|
|
423
|
-
newsletterUpdateCategory: async (jid, category) => {
|
|
424
|
-
return newsletterUpdate(jid, { topic: category })
|
|
425
|
-
},
|
|
426
|
-
|
|
427
|
-
newsletterUpdateSettings: async (jid, settings) => {
|
|
428
|
-
const variables = { newsletter_id: jid, updates: { settings } }
|
|
429
|
-
return executeWMexQuery(variables, Types_1.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
|
|
430
|
-
},
|
|
431
|
-
|
|
432
|
-
newsletterPromoteAdmin: async (jid, userJid) => {
|
|
433
|
-
await query({
|
|
434
|
-
tag: 'iq',
|
|
435
|
-
attrs: {
|
|
436
|
-
id: generateMessageTag(),
|
|
437
|
-
type: 'set',
|
|
438
|
-
xmlns: 'newsletter',
|
|
439
|
-
to: jid
|
|
440
|
-
},
|
|
441
|
-
content: [
|
|
442
|
-
{
|
|
443
|
-
tag: 'admin_promote',
|
|
444
|
-
attrs: {},
|
|
445
|
-
content: [{ tag: 'participant', attrs: { jid: userJid } }]
|
|
446
|
-
}
|
|
447
|
-
]
|
|
448
|
-
})
|
|
449
|
-
},
|
|
450
|
-
|
|
451
|
-
newsletterViewStats: async (jid, serverId) => {
|
|
452
|
-
const result = await query({
|
|
453
|
-
tag: 'iq',
|
|
454
|
-
attrs: {
|
|
455
|
-
id: generateMessageTag(),
|
|
456
|
-
type: 'get',
|
|
457
|
-
xmlns: 'newsletter',
|
|
458
|
-
to: jid
|
|
459
|
-
},
|
|
460
|
-
content: [
|
|
461
|
-
{
|
|
462
|
-
tag: 'message_updates',
|
|
463
|
-
attrs: { count: '1', server_id: String(serverId) }
|
|
464
|
-
}
|
|
465
|
-
]
|
|
466
|
-
})
|
|
467
|
-
return result
|
|
468
|
-
},
|
|
469
|
-
|
|
470
|
-
newsletterSendPost: async (jid, content, options = {}) => {
|
|
471
|
-
const result = await query({
|
|
472
|
-
tag: 'iq',
|
|
473
|
-
attrs: {
|
|
474
|
-
id: generateMessageTag(),
|
|
475
|
-
type: 'set',
|
|
476
|
-
xmlns: 'newsletter',
|
|
477
|
-
to: jid
|
|
478
|
-
},
|
|
479
|
-
content: [
|
|
480
|
-
{
|
|
481
|
-
tag: 'publish',
|
|
482
|
-
attrs: {},
|
|
483
|
-
content: Array.isArray(content) ? content : [content]
|
|
484
|
-
}
|
|
485
|
-
]
|
|
486
|
-
})
|
|
487
|
-
return result
|
|
488
|
-
},
|
|
489
|
-
|
|
490
|
-
newsletterRevokeMessage: async (jid, serverId) => {
|
|
491
|
-
await sendNode({
|
|
492
|
-
tag: 'message',
|
|
493
|
-
attrs: {
|
|
494
|
-
to: jid,
|
|
495
|
-
type: 'text',
|
|
496
|
-
edit: '7',
|
|
497
|
-
server_id: String(serverId),
|
|
498
|
-
id: generateMessageTag()
|
|
499
|
-
},
|
|
500
|
-
content: []
|
|
501
|
-
})
|
|
502
|
-
},
|
|
503
|
-
|
|
504
|
-
newsletterPinMessage: async (jid, serverId, durationSecs = 86400) => {
|
|
505
|
-
await query({
|
|
506
|
-
tag: 'iq',
|
|
507
|
-
attrs: {
|
|
508
|
-
id: generateMessageTag(),
|
|
509
|
-
type: 'set',
|
|
510
|
-
xmlns: 'newsletter',
|
|
511
|
-
to: jid
|
|
512
|
-
},
|
|
513
|
-
content: [
|
|
514
|
-
{
|
|
515
|
-
tag: 'pin',
|
|
516
|
-
attrs: { server_id: String(serverId), duration: String(durationSecs) }
|
|
517
|
-
}
|
|
518
|
-
]
|
|
519
|
-
})
|
|
520
|
-
},
|
|
521
|
-
|
|
522
|
-
newsletterUnpinMessage: async (jid, serverId) => {
|
|
523
|
-
await query({
|
|
524
|
-
tag: 'iq',
|
|
525
|
-
attrs: {
|
|
526
|
-
id: generateMessageTag(),
|
|
527
|
-
type: 'set',
|
|
528
|
-
xmlns: 'newsletter',
|
|
529
|
-
to: jid
|
|
530
|
-
},
|
|
531
|
-
content: [
|
|
532
|
-
{
|
|
533
|
-
tag: 'unpin',
|
|
534
|
-
attrs: { server_id: String(serverId) }
|
|
535
|
-
}
|
|
536
|
-
]
|
|
537
|
-
})
|
|
538
|
-
},
|
|
539
|
-
|
|
540
|
-
newsletterInviteAdmin: async (jid, userJid) => {
|
|
541
|
-
return executeWMexQuery(
|
|
542
|
-
{ newsletter_id: jid, user_id: userJid },
|
|
543
|
-
Types_1.QueryIds.ADMIN_INVITE,
|
|
544
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_invite_create
|
|
545
|
-
)
|
|
546
|
-
},
|
|
547
|
-
|
|
548
|
-
newsletterRevokeAdminInvite: async (jid, userJid) => {
|
|
549
|
-
return executeWMexQuery(
|
|
550
|
-
{ newsletter_id: jid, user_id: userJid },
|
|
551
|
-
Types_1.QueryIds.ADMIN_INVITE_REVOKE,
|
|
552
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_invite_revoke
|
|
553
|
-
)
|
|
554
|
-
},
|
|
555
|
-
|
|
556
|
-
newsletterAcceptAdminInvite: async jid => {
|
|
557
|
-
return executeWMexQuery(
|
|
558
|
-
{ newsletter_id: jid },
|
|
559
|
-
Types_1.QueryIds.ADMIN_INVITE_ACCEPT,
|
|
560
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_invite_accept
|
|
561
|
-
)
|
|
562
|
-
},
|
|
563
|
-
|
|
564
|
-
newsletterAdminMetadata: async (jid, options = {}) => {
|
|
565
|
-
const {
|
|
566
|
-
fetchPendingAdmins = true,
|
|
567
|
-
fetchAdminCount = true,
|
|
568
|
-
fetchCapabilities = false,
|
|
569
|
-
fetchAdminProfile = false,
|
|
570
|
-
includeAdminSettings = false,
|
|
571
|
-
includeJarvisConfig = false
|
|
572
|
-
} = options
|
|
573
|
-
return executeWMexQuery(
|
|
574
|
-
{
|
|
575
|
-
jid,
|
|
576
|
-
include_thread_metadata: false,
|
|
577
|
-
include_messages: false,
|
|
578
|
-
fetch_pending_admin_invites: fetchPendingAdmins,
|
|
579
|
-
fetch_admin_count: fetchAdminCount,
|
|
580
|
-
fetch_capabilities: fetchCapabilities,
|
|
581
|
-
fetch_admin_profile: fetchAdminProfile,
|
|
582
|
-
include_admin_settings: includeAdminSettings,
|
|
583
|
-
include_jarvis_config: includeJarvisConfig
|
|
584
|
-
},
|
|
585
|
-
Types_1.QueryIds.ADMIN_METADATA,
|
|
586
|
-
Types_1.XWAPaths.xwa2_newsletter_admin
|
|
587
|
-
)
|
|
588
|
-
},
|
|
589
|
-
|
|
590
|
-
newsletterAdminProfileUpdate: async (jid, updates) => {
|
|
591
|
-
return executeWMexQuery(
|
|
592
|
-
{ newsletter_id: jid, updates },
|
|
593
|
-
Types_1.QueryIds.ADMIN_PROFILE_UPDATE,
|
|
594
|
-
Types_1.XWAPaths.xwa2_newsletter_admin_profile_update
|
|
595
|
-
)
|
|
596
|
-
},
|
|
597
|
-
|
|
598
|
-
newsletterDirectoryList: async (options = {}) => {
|
|
599
|
-
const { limit = 20, interests = null, sortField = 'SUBSCRIBER_COUNT', sortOrder = 'DESC' } = options
|
|
600
|
-
const variables = { limit, sort_field: sortField, sort_order: sortOrder }
|
|
601
|
-
if (interests?.length) variables.interests = interests
|
|
602
|
-
return executeWMexQuery(
|
|
603
|
-
variables,
|
|
604
|
-
Types_1.QueryIds.DIRECTORY_LIST,
|
|
605
|
-
Types_1.XWAPaths.xwa2_newsletters_directory_list
|
|
606
|
-
)
|
|
607
|
-
},
|
|
608
|
-
|
|
609
|
-
newsletterDirectorySearch: async (searchText, options = {}) => {
|
|
610
|
-
const { limit = 20, startCursor = null, categories = null } = options
|
|
611
|
-
const variables = { search_text: searchText, limit }
|
|
612
|
-
if (startCursor) variables.start_cursor = startCursor
|
|
613
|
-
if (categories?.length) variables.categories = categories
|
|
614
|
-
return executeWMexQuery(
|
|
615
|
-
variables,
|
|
616
|
-
Types_1.QueryIds.DIRECTORY_SEARCH,
|
|
617
|
-
Types_1.XWAPaths.xwa2_newsletters_directory_search
|
|
618
|
-
)
|
|
619
|
-
},
|
|
620
|
-
|
|
621
|
-
newsletterDirectoryCategoryPreview: async (limit = 5) => {
|
|
622
|
-
return executeWMexQuery(
|
|
623
|
-
{ limit },
|
|
624
|
-
Types_1.QueryIds.DIRECTORY_CATEGORY_PREVIEW,
|
|
625
|
-
Types_1.XWAPaths.xwa2_newsletters_directory_category_preview
|
|
626
|
-
)
|
|
627
|
-
},
|
|
628
|
-
|
|
629
|
-
newsletterSearch: async (query, limit = 20, startCursor = null) => {
|
|
630
|
-
const variables = { query, limit }
|
|
631
|
-
if (startCursor) variables.start_cursor = startCursor
|
|
632
|
-
return executeWMexQuery(variables, Types_1.QueryIds.SEARCH, Types_1.XWAPaths.xwa2_newsletters_search)
|
|
633
|
-
},
|
|
634
|
-
|
|
635
|
-
newsletterRecommended: async (limit = 10, numFollowed = null) => {
|
|
636
|
-
const variables = { limit }
|
|
637
|
-
if (numFollowed != null) variables.num_newsletters_followed = numFollowed
|
|
638
|
-
return executeWMexQuery(variables, Types_1.QueryIds.RECOMMENDED, Types_1.XWAPaths.xwa2_newsletters_recommended)
|
|
639
|
-
},
|
|
640
|
-
|
|
641
|
-
newsletterSimilar: async (jid, limit = 10) => {
|
|
642
|
-
return executeWMexQuery(
|
|
643
|
-
{ newsletter_id: jid, limit },
|
|
644
|
-
Types_1.QueryIds.SIMILAR,
|
|
645
|
-
Types_1.XWAPaths.xwa2_newsletters_similar
|
|
646
|
-
)
|
|
647
|
-
},
|
|
648
|
-
|
|
649
|
-
newsletterFollowingList: async (startCursor = null, limit = 20) => {
|
|
650
|
-
const variables = { limit }
|
|
651
|
-
if (startCursor) variables.start_cursor = startCursor
|
|
652
|
-
return executeWMexQuery(variables, Types_1.QueryIds.FOLLOWING_LIST, Types_1.XWAPaths.xwa2_newsletter_following)
|
|
653
|
-
},
|
|
654
|
-
|
|
655
|
-
newsletterInsights: async (jid, period = null) => {
|
|
656
|
-
const variables = { newsletter_id: jid }
|
|
657
|
-
if (period) variables.period = period
|
|
658
|
-
return executeWMexQuery(variables, Types_1.QueryIds.INSIGHTS, Types_1.XWAPaths.xwa2_newsletter_admin_insights)
|
|
659
|
-
},
|
|
660
|
-
|
|
661
|
-
newsletterPollVoterList: async (jid, serverId, option = null, startCursor = null) => {
|
|
662
|
-
const variables = { id: jid, server_id: serverId }
|
|
663
|
-
if (option != null) variables.option = option
|
|
664
|
-
if (startCursor) variables.start_cursor = startCursor
|
|
665
|
-
return executeWMexQuery(
|
|
666
|
-
variables,
|
|
667
|
-
Types_1.QueryIds.POLL_VOTER_LIST,
|
|
668
|
-
Types_1.XWAPaths.xwa2_newsletters_poll_voter_list
|
|
669
|
-
)
|
|
670
|
-
},
|
|
671
|
-
|
|
672
|
-
newsletterReactionSenders: async (jid, serverId, startCursor = null) => {
|
|
673
|
-
const variables = { id: jid, server_id: serverId }
|
|
674
|
-
if (startCursor) variables.start_cursor = startCursor
|
|
675
|
-
return executeWMexQuery(
|
|
676
|
-
variables,
|
|
677
|
-
Types_1.QueryIds.REACTION_SENDERS_LIST,
|
|
678
|
-
Types_1.XWAPaths.xwa2_newsletters_reaction_sender_list
|
|
679
|
-
)
|
|
680
|
-
},
|
|
681
|
-
|
|
682
|
-
newsletterBlockUser: async (jid, userJid) => {
|
|
683
|
-
return executeWMexQuery(
|
|
684
|
-
{ newsletter_id: jid, user_id: userJid },
|
|
685
|
-
Types_1.QueryIds.BLOCK_USER,
|
|
686
|
-
'xwa2_newsletter_block_user'
|
|
687
|
-
)
|
|
688
|
-
},
|
|
689
|
-
|
|
690
|
-
newsletterEnableWamo: async jid => {
|
|
691
|
-
return executeWMexQuery(
|
|
692
|
-
{ newsletter_id: jid },
|
|
693
|
-
Types_1.QueryIds.WAMO_ENABLE_SUB,
|
|
694
|
-
'xwa2_newsletter_wamo_enable_sub'
|
|
695
|
-
)
|
|
696
|
-
},
|
|
697
|
-
|
|
698
|
-
newsletterDisableWamo: async jid => {
|
|
699
|
-
return executeWMexQuery(
|
|
700
|
-
{ newsletter_id: jid },
|
|
701
|
-
Types_1.QueryIds.WAMO_DISABLE_SUB,
|
|
702
|
-
'xwa2_newsletter_wamo_disable_sub'
|
|
703
|
-
)
|
|
704
|
-
},
|
|
705
|
-
|
|
706
|
-
newsletterChangeWamo: async (jid, subConfig) => {
|
|
707
|
-
return executeWMexQuery(
|
|
708
|
-
{ newsletter_id: jid, ...subConfig },
|
|
709
|
-
Types_1.QueryIds.WAMO_CHANGE_SUB,
|
|
710
|
-
'xwa2_newsletter_wamo_change_sub'
|
|
711
|
-
)
|
|
712
|
-
},
|
|
713
|
-
|
|
714
|
-
wamoAfsAgeCollection: async jid =>
|
|
715
|
-
executeWMexQuery(
|
|
716
|
-
{ newsletter_id: jid },
|
|
717
|
-
Types_1.QueryIds.WAMO_AFS_AGE_COLLECTION,
|
|
718
|
-
Types_1.XWAPaths.xwa2_wamo_afs_age_collection
|
|
719
|
-
),
|
|
720
|
-
|
|
721
|
-
wamoAssetCollection: async jid =>
|
|
722
|
-
executeWMexQuery(
|
|
723
|
-
{ newsletter_id: jid },
|
|
724
|
-
Types_1.QueryIds.WAMO_ASSET_COLLECTION,
|
|
725
|
-
Types_1.XWAPaths.xwa2_wamo_asset_collection
|
|
726
|
-
),
|
|
727
|
-
|
|
728
|
-
wamoFetchAdhocNotice: async noticeId =>
|
|
729
|
-
executeWMexQuery(
|
|
730
|
-
{ notice_id: noticeId },
|
|
731
|
-
Types_1.QueryIds.WAMO_FETCH_ADHOC_NOTICE,
|
|
732
|
-
Types_1.XWAPaths.xwa2_wamo_fetch_adhoc_notice_by_id
|
|
733
|
-
),
|
|
734
|
-
|
|
735
|
-
wamoFetchIdentityToken: async jid =>
|
|
736
|
-
executeWMexQuery(
|
|
737
|
-
{ newsletter_id: jid },
|
|
738
|
-
Types_1.QueryIds.WAMO_FETCH_IDENTITY_TOKEN,
|
|
739
|
-
Types_1.XWAPaths.xwa2_wamo_fetch_identity_token
|
|
740
|
-
),
|
|
741
|
-
|
|
742
|
-
wamoSubComplianceInfo: async jid =>
|
|
743
|
-
executeWMexQuery(
|
|
744
|
-
{ newsletter_id: jid },
|
|
745
|
-
Types_1.QueryIds.WAMO_SUB_COMPLIANCE_INFO,
|
|
746
|
-
Types_1.XWAPaths.xwa2_wamo_sub_get_compliance_info
|
|
747
|
-
),
|
|
748
|
-
|
|
749
|
-
wamoUserIdVersion: async jid =>
|
|
750
|
-
executeWMexQuery(
|
|
751
|
-
{ newsletter_id: jid },
|
|
752
|
-
Types_1.QueryIds.WAMO_USER_ID_VERSION,
|
|
753
|
-
Types_1.XWAPaths.xwa2_wamo_user_id_version
|
|
754
|
-
),
|
|
755
|
-
|
|
756
|
-
wamoSetUserIdVersion: async (jid, version) =>
|
|
757
|
-
executeWMexQuery(
|
|
758
|
-
{ newsletter_id: jid, version },
|
|
759
|
-
Types_1.QueryIds.WAMO_SET_USER_ID_VERSION,
|
|
760
|
-
Types_1.XWAPaths.xwa2_wamo_set_user_id_version
|
|
761
|
-
),
|
|
762
|
-
|
|
763
|
-
newsletterLeave: async jid =>
|
|
764
|
-
executeWMexQuery({ newsletter_id: jid }, Types_1.QueryIds.LEAVE, Types_1.XWAPaths.xwa2_newsletter_leave_v2),
|
|
765
|
-
|
|
766
|
-
newsletterCreateVerified: async (name, description = null) =>
|
|
767
|
-
executeWMexQuery(
|
|
768
|
-
{ input: { name, description } },
|
|
769
|
-
Types_1.QueryIds.CREATE_VERIFIED,
|
|
770
|
-
Types_1.XWAPaths.xwa2_newsletter_create_verified
|
|
771
|
-
),
|
|
772
|
-
|
|
773
|
-
newsletterEnforcements: async jid =>
|
|
774
|
-
executeWMexQuery(
|
|
775
|
-
{ newsletter_id: jid },
|
|
776
|
-
Types_1.QueryIds.ENFORCEMENTS,
|
|
777
|
-
Types_1.XWAPaths.xwa2_newsletter_enforcements
|
|
778
|
-
),
|
|
779
|
-
|
|
780
|
-
newsletterUserReports: async (jid, cursor = null) => {
|
|
781
|
-
const variables = { newsletter_id: jid }
|
|
782
|
-
if (cursor) variables.cursor = cursor
|
|
783
|
-
return executeWMexQuery(variables, Types_1.QueryIds.USER_REPORTS, Types_1.XWAPaths.xwa2_newsletter_user_reports)
|
|
784
|
-
},
|
|
785
|
-
|
|
786
|
-
newsletterCreateReportAppeal: async (jid, reason) =>
|
|
787
|
-
executeWMexQuery(
|
|
788
|
-
{ newsletter_id: jid, reason },
|
|
789
|
-
Types_1.QueryIds.CREATE_REPORT_APPEAL,
|
|
790
|
-
Types_1.XWAPaths.xwa2_newsletter_create_report_appeal
|
|
791
|
-
),
|
|
792
|
-
|
|
793
|
-
newsletterLinkPreviewCheck: async url =>
|
|
794
|
-
executeWMexQuery(
|
|
795
|
-
{ url },
|
|
796
|
-
Types_1.QueryIds.LINK_PREVIEW_CHECK,
|
|
797
|
-
Types_1.XWAPaths.xwa2_newsletter_link_preview_check
|
|
798
|
-
),
|
|
799
|
-
|
|
800
|
-
newsletterUpdateVerification: async (jid, verification) =>
|
|
801
|
-
executeWMexQuery(
|
|
802
|
-
{ newsletter_id: jid, verification },
|
|
803
|
-
Types_1.QueryIds.UPDATE_VERIFICATION,
|
|
804
|
-
Types_1.XWAPaths.xwa2_newsletter_update_verification
|
|
805
|
-
),
|
|
806
|
-
|
|
807
|
-
newsletterLabelPaidPartnership: async (jid, serverId, messageType = 'MESSAGE') =>
|
|
808
|
-
executeWMexQuery(
|
|
809
|
-
{ newsletter_id: jid, server_id: String(serverId), message_type: messageType },
|
|
810
|
-
Types_1.QueryIds.LABEL_PAID_PARTNERSHIP,
|
|
811
|
-
Types_1.XWAPaths.xwa2_newsletter_label_paid_partnership
|
|
812
|
-
),
|
|
813
|
-
|
|
814
|
-
newsletterLogExposures: async events =>
|
|
815
|
-
executeWMexQuery({ events }, Types_1.QueryIds.LOG_EXPOSURES, Types_1.XWAPaths.xwa2_newsletter_log_exposures),
|
|
816
|
-
|
|
817
|
-
newsletterUpdateUserSetting: async (jid, setting) =>
|
|
818
|
-
executeWMexQuery(
|
|
819
|
-
{ newsletter_id: jid, ...setting },
|
|
820
|
-
Types_1.QueryIds.UPDATE_USER_SETTING,
|
|
821
|
-
Types_1.XWAPaths.xwa2_newsletter_update_user_setting
|
|
822
|
-
),
|
|
823
|
-
|
|
824
|
-
newsletterRankingFeatures: async jid =>
|
|
825
|
-
executeWMexQuery(
|
|
826
|
-
{ newsletter_id: jid },
|
|
827
|
-
Types_1.QueryIds.RANKING_FEATURES,
|
|
828
|
-
Types_1.XWAPaths.xwa2_newsletter_ranking_features
|
|
829
|
-
),
|
|
830
|
-
|
|
831
|
-
fetchReachoutTimelock: async () =>
|
|
832
|
-
executeWMexQuery({}, Types_1.QueryIds.REACHOUT_TIMELOCK, Types_1.XWAPaths.xwa2_fetch_account_reachout_timelock),
|
|
833
|
-
|
|
834
|
-
fetchMessageCappingInfo: async () =>
|
|
835
|
-
executeWMexQuery({}, Types_1.QueryIds.MESSAGE_CAPPING_INFO, Types_1.XWAPaths.xwa2_message_capping_info),
|
|
836
|
-
|
|
837
|
-
newsletterQuestionResponseStateUpdate: async (jid, serverId, state) =>
|
|
838
|
-
executeWMexQuery(
|
|
839
|
-
{ newsletter_id: jid, server_id: serverId, state },
|
|
840
|
-
Types_1.QueryIds.QUESTION_RESPONSE_STATE_UPDATE,
|
|
841
|
-
Types_1.XWAPaths.xwa2_newsletter_question_response_state_update
|
|
842
|
-
),
|
|
843
|
-
|
|
844
|
-
newsletterSendViewReceipt: async (jid, serverMessageIds) => {
|
|
845
|
-
const ids = Array.isArray(serverMessageIds) ? serverMessageIds : [serverMessageIds]
|
|
846
|
-
const receiptId = generateMessageTag()
|
|
847
|
-
await query({
|
|
848
|
-
tag: 'receipt',
|
|
849
|
-
attrs: {
|
|
850
|
-
to: jid,
|
|
851
|
-
id: receiptId,
|
|
852
|
-
type: 'view'
|
|
853
|
-
},
|
|
854
|
-
content: [
|
|
855
|
-
{
|
|
856
|
-
tag: 'list',
|
|
857
|
-
attrs: {},
|
|
858
|
-
content: ids.map(id => ({ tag: 'item', attrs: { server_id: String(id) } }))
|
|
859
|
-
}
|
|
860
|
-
]
|
|
861
|
-
})
|
|
862
|
-
}
|
|
863
|
-
}
|
|
864
|
-
}
|
|
865
|
-
exports.makeNewsletterSocket = makeNewsletterSocket
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
-
exports.waitForBackoff = exports.setProtocolBackoffMs = void 0
|
|
4
|
-
|
|
5
|
-
const backoffPromises = new Map()
|
|
6
|
-
|
|
7
|
-
const setProtocolBackoffMs = (protocolName, ms) => {
|
|
8
|
-
backoffPromises.set(protocolName, new Promise(resolve => setTimeout(resolve, ms)))
|
|
9
|
-
}
|
|
10
|
-
exports.setProtocolBackoffMs = setProtocolBackoffMs
|
|
11
|
-
|
|
12
|
-
const shouldWaitForBackoff = query => {
|
|
13
|
-
if (query.context === 'interactive') {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
const protocolNames = query.protocols.map(p => p.name)
|
|
17
|
-
return !(protocolNames.includes('devices') && (query.context === 'message' || query.context === 'voip'))
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const waitForBackoff = async query => {
|
|
21
|
-
if (!shouldWaitForBackoff(query)) {
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
await Promise.all(query.protocols.map(p => backoffPromises.get(p.name)))
|
|
25
|
-
}
|
|
26
|
-
exports.waitForBackoff = waitForBackoff
|