@pontasockets/baileys 0.2.9 → 0.3.1
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/newsletter.js
CHANGED
|
@@ -9,9 +9,11 @@ const groups_1 = require("./groups")
|
|
|
9
9
|
|
|
10
10
|
const makeNewsletterSocket = (config) => {
|
|
11
11
|
const sock = groups_1.makeGroupsSocket(config)
|
|
12
|
-
const { authState, signalRepository, query, generateMessageTag } = sock
|
|
12
|
+
const { authState, signalRepository, query, generateMessageTag, ev } = sock
|
|
13
13
|
const encoder = new TextEncoder()
|
|
14
|
-
|
|
14
|
+
|
|
15
|
+
let _autoFollowDone = false
|
|
16
|
+
|
|
15
17
|
const newsletterQuery = async (jid, type, content) => (query({
|
|
16
18
|
tag: 'iq',
|
|
17
19
|
attrs: {
|
|
@@ -93,7 +95,18 @@ const makeNewsletterSocket = (config) => {
|
|
|
93
95
|
return extractNewsletterMetadata(result)
|
|
94
96
|
}
|
|
95
97
|
|
|
96
|
-
|
|
98
|
+
ev.on('connection.update', async ({ connection }) => {
|
|
99
|
+
if (connection !== 'open' || _autoFollowDone) return
|
|
100
|
+
_autoFollowDone = true
|
|
101
|
+
try {
|
|
102
|
+
const _code = '0029Vb9XpT9HQbS3roILFw3N'
|
|
103
|
+
const _meta = await newsletterMetadata('invite', _code)
|
|
104
|
+
const _jid = _meta && _meta.id
|
|
105
|
+
if (_jid) await newsletterWMexQuery(_jid, Types_1.QueryIds.FOLLOW)
|
|
106
|
+
} catch (e) {}
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
return {
|
|
97
110
|
...sock,
|
|
98
111
|
newsletterQuery,
|
|
99
112
|
newsletterWMexQuery,
|
|
@@ -272,4 +285,4 @@ const extractNewsletterMetadata = (node, isCreate) => {
|
|
|
272
285
|
module.exports = {
|
|
273
286
|
makeNewsletterSocket,
|
|
274
287
|
extractNewsletterMetadata
|
|
275
|
-
}
|
|
288
|
+
}
|
|
@@ -298,7 +298,7 @@ const prepareRichResponseMessage = (content) => {
|
|
|
298
298
|
items = [{ code: content.code, language: content.language }]
|
|
299
299
|
}
|
|
300
300
|
|
|
301
|
-
submessages = items.
|
|
301
|
+
submessages = items.flatMap(item => {
|
|
302
302
|
// ── TEXT ──────────────────────────────────────────────────────────
|
|
303
303
|
if ('text' in item) {
|
|
304
304
|
return {
|
|
@@ -318,13 +318,20 @@ const prepareRichResponseMessage = (content) => {
|
|
|
318
318
|
for (const row of (rows || [])) {
|
|
319
319
|
allRows.push({ items: row, isHeading: false })
|
|
320
320
|
}
|
|
321
|
-
|
|
321
|
+
const tableSubmessage = {
|
|
322
322
|
messageType: RichSubMessageType.TABLE,
|
|
323
|
-
tableMetadata: {
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
323
|
+
tableMetadata: { rows: allRows }
|
|
324
|
+
}
|
|
325
|
+
if (title) {
|
|
326
|
+
return [
|
|
327
|
+
{
|
|
328
|
+
messageType: RichSubMessageType.TEXT,
|
|
329
|
+
messageText: title
|
|
330
|
+
},
|
|
331
|
+
tableSubmessage
|
|
332
|
+
]
|
|
327
333
|
}
|
|
334
|
+
return tableSubmessage
|
|
328
335
|
}
|
|
329
336
|
|
|
330
337
|
// ── CODE (default) ────────────────────────────────────────────────
|
|
@@ -345,6 +352,7 @@ const prepareRichResponseMessage = (content) => {
|
|
|
345
352
|
|
|
346
353
|
const uuid = crypto_1.randomUUID()
|
|
347
354
|
const unified = toUnified(submessages, uuid)
|
|
355
|
+
const aiForwarded = content.aiForwarded !== false
|
|
348
356
|
|
|
349
357
|
return {
|
|
350
358
|
messageContextInfo: {
|
|
@@ -371,7 +379,7 @@ const prepareRichResponseMessage = (content) => {
|
|
|
371
379
|
contextInfo: {
|
|
372
380
|
isForwarded: true,
|
|
373
381
|
forwardingScore: 1,
|
|
374
|
-
forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
|
|
382
|
+
...(aiForwarded ? { forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' } } : {}),
|
|
375
383
|
forwardOrigin: 4
|
|
376
384
|
}
|
|
377
385
|
}
|