@bellaxchuu/flowred 0.8.6
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/LICENSE +21 -0
- package/README.md +214 -0
- package/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +6902 -0
- package/WAProto/fix-imports.js +85 -0
- package/WAProto/index.js +242946 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/index.js +190 -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 +92 -0
- package/lib/Signal/Group/group_cipher.js +89 -0
- package/lib/Signal/Group/index.js +136 -0
- package/lib/Signal/Group/keyhelper.js +73 -0
- package/lib/Signal/Group/sender-chain-key.js +32 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +44 -0
- package/lib/Signal/Group/sender-key-state.js +97 -0
- package/lib/Signal/Group/sender-message-key.js +30 -0
- package/lib/Signal/libsignal.js +490 -0
- package/lib/Signal/lid-mapping.js +262 -0
- package/lib/Socket/Client/index.js +30 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/aigroups.js +240 -0
- package/lib/Socket/business.js +422 -0
- package/lib/Socket/chats.js +1816 -0
- package/lib/Socket/communities.js +549 -0
- package/lib/Socket/graphql.js +656 -0
- package/lib/Socket/groups.js +764 -0
- package/lib/Socket/index.js +39 -0
- package/lib/Socket/interactive-handler.js +522 -0
- package/lib/Socket/interop.js +549 -0
- package/lib/Socket/luxu.js +387 -0
- package/lib/Socket/managed-account.js +183 -0
- package/lib/Socket/messages-recv.js +2440 -0
- package/lib/Socket/messages-send.js +1853 -0
- package/lib/Socket/mex.js +60 -0
- package/lib/Socket/newsletter.js +820 -0
- package/lib/Socket/privacy.js +449 -0
- package/lib/Socket/registration.js +427 -0
- package/lib/Socket/socket.js +1092 -0
- package/lib/Socket/text-router.js +83 -0
- package/lib/Socket/username.js +243 -0
- package/lib/Store/index.js +36 -0
- package/lib/Store/keyed-db.js +108 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.js +604 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.js +29 -0
- package/lib/Types/Auth.js +38 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +4 -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 +95 -0
- package/lib/Types/Mex.js +112 -0
- package/lib/Types/Newsletter.js +121 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +70 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +55 -0
- package/lib/Utils/auth-utils.js +306 -0
- package/lib/Utils/browser-utils.js +114 -0
- package/lib/Utils/business.js +247 -0
- package/lib/Utils/chat-utils.js +1208 -0
- package/lib/Utils/command-loader.js +100 -0
- package/lib/Utils/companion-reg-client-utils.js +42 -0
- package/lib/Utils/consumer-application.js +107 -0
- package/lib/Utils/crypto.js +155 -0
- package/lib/Utils/curve25519-js.js +275 -0
- package/lib/Utils/decode-wa-message.js +560 -0
- package/lib/Utils/event-buffer.js +607 -0
- package/lib/Utils/generics.js +563 -0
- package/lib/Utils/group-history.js +60 -0
- package/lib/Utils/history.js +244 -0
- package/lib/Utils/identity-change-handler.js +52 -0
- package/lib/Utils/index.js +57 -0
- package/lib/Utils/jid-display-normalization.js +218 -0
- package/lib/Utils/link-preview.js +143 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +39 -0
- package/lib/Utils/make-mutex.js +36 -0
- package/lib/Utils/message-composer.js +479 -0
- package/lib/Utils/message-retry-manager.js +270 -0
- package/lib/Utils/messages-media.js +896 -0
- package/lib/Utils/messages.js +2904 -0
- package/lib/Utils/meta-ai-msmsg.js +262 -0
- package/lib/Utils/native-bridge.js +82 -0
- package/lib/Utils/noise-handler.js +196 -0
- package/lib/Utils/offline-node-processor.js +42 -0
- package/lib/Utils/pre-key-manager.js +107 -0
- package/lib/Utils/process-message.js +1048 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/session-pool.js +94 -0
- package/lib/Utils/signal.js +224 -0
- package/lib/Utils/stanza-ack.js +40 -0
- package/lib/Utils/sticker.js +145 -0
- package/lib/Utils/sync-action-utils.js +54 -0
- package/lib/Utils/tc-token-utils.js +161 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.js +219 -0
- package/lib/Utils/view-once-cache.js +79 -0
- package/lib/Utils/voip-rekey.js +22 -0
- package/lib/WABinary/constants.js +1304 -0
- package/lib/WABinary/decode.js +343 -0
- package/lib/WABinary/encode.js +228 -0
- package/lib/WABinary/generic-utils.js +240 -0
- package/lib/WABinary/index.js +33 -0
- package/lib/WABinary/jid-utils.js +361 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +39486 -0
- package/lib/WAM/encode.js +142 -0
- package/lib/WAM/index.js +31 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +55 -0
- package/lib/WAUSync/Protocols/USyncBusinessProtocol.js +43 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncFeatureProtocol.js +59 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +31 -0
- package/lib/WAUSync/Protocols/USyncPictureProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncSidelistProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +39 -0
- package/lib/WAUSync/Protocols/USyncTextStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +27 -0
- package/lib/WAUSync/Protocols/index.js +39 -0
- package/lib/WAUSync/USyncQuery.js +133 -0
- package/lib/WAUSync/USyncUser.js +50 -0
- package/lib/WAUSync/index.js +31 -0
- package/lib/antiban.js +4637 -0
- package/lib/index.js +45 -0
- package/package.json +107 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
3
|
+
exports.makeInteropSocket = void 0
|
|
4
|
+
|
|
5
|
+
const { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } = require('../WABinary')
|
|
6
|
+
const { executeWMexQuery } = require('./mex')
|
|
7
|
+
|
|
8
|
+
const INTEROP_MEX_QUERY_IDS = {
|
|
9
|
+
CREATE_GROUP: '25726817620301612', // GroupsCreateInteropGroup
|
|
10
|
+
LEAVE_GROUP: '25346167795013270', // LeaveInteropGroup
|
|
11
|
+
ADD_PARTICIPANTS: '25732168276369452', // AddParticipantsToInteropGroup
|
|
12
|
+
QUERY_GROUP_INFO: '32734144032867936', // QueryInteropGroupInfo
|
|
13
|
+
PRIVACY_SETTINGS_QUERY: '24849123668112656', // InteropPrivacySettingsQuery
|
|
14
|
+
PRIVACY_SETTINGS_UPDATE: '25421856497452764', // InteropPrivacySettingsUpdate
|
|
15
|
+
PRIVACY_SETTINGS_WITH_CONTACT_LIST: '24913399124998600' // InteropPrivacySettingWithContactListUpdate
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Known integrator IDs (assigned by WhatsApp).
|
|
20
|
+
* BirdyChat → identifier_type="email"
|
|
21
|
+
* Haiket → identifier_type="pn"
|
|
22
|
+
*/
|
|
23
|
+
const INTEGRATOR_BIRDYCHAT = 12
|
|
24
|
+
const INTEGRATOR_HAIKET = 13
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* TOS trackable results sent by WA on first interop opt-in.
|
|
28
|
+
* 105 = TOS shown, 160 = TOS accepted.
|
|
29
|
+
*/
|
|
30
|
+
const TOS_TRACKABLE_ID = '20240306'
|
|
31
|
+
const TOS_RESULT_SHOWN = '105'
|
|
32
|
+
const TOS_RESULT_ACCEPTED = '160'
|
|
33
|
+
|
|
34
|
+
/** Maximum users per batch lookup (enforced server-side too). */
|
|
35
|
+
const INTEROP_BATCH_MAX = 256
|
|
36
|
+
|
|
37
|
+
const makeInteropSocket = sock => {
|
|
38
|
+
const { query, generateMessageTag, logger, signalRepository } = sock
|
|
39
|
+
|
|
40
|
+
const mexQuery = (variables, queryId, dataPath) =>
|
|
41
|
+
executeWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Fetch all available interop integrators from the server.
|
|
45
|
+
* Each integrator carries: id, name, status, icon, identifierType,
|
|
46
|
+
* optedIn, features.groupMessaging.
|
|
47
|
+
* status can be "active" | "onboarding" | "removed".
|
|
48
|
+
*/
|
|
49
|
+
const fetchIntegrators = async () => {
|
|
50
|
+
const result = await query({
|
|
51
|
+
tag: 'iq',
|
|
52
|
+
attrs: {
|
|
53
|
+
type: 'get',
|
|
54
|
+
xmlns: 'w:interop',
|
|
55
|
+
to: S_WHATSAPP_NET
|
|
56
|
+
},
|
|
57
|
+
content: [{ tag: 'integrator', attrs: { fetch: 'all' } }]
|
|
58
|
+
})
|
|
59
|
+
const listNode = getBinaryNodeChild(result, 'integrator_list')
|
|
60
|
+
if (!listNode) return []
|
|
61
|
+
const globalOptedIn = listNode.attrs?.opted_in === 'true'
|
|
62
|
+
return getBinaryNodeChildren(listNode, 'integrator').map(node => {
|
|
63
|
+
const featuresNode = getBinaryNodeChild(node, 'features')
|
|
64
|
+
return {
|
|
65
|
+
id: parseInt(node.attrs.id),
|
|
66
|
+
name: node.attrs.name,
|
|
67
|
+
// "active" | "onboarding" | "removed"
|
|
68
|
+
status: node.attrs.status,
|
|
69
|
+
icon: node.attrs.icon,
|
|
70
|
+
// "email" | "pn" | "username"
|
|
71
|
+
identifierType: node.attrs.identifier_type,
|
|
72
|
+
// Whether we are already opted-in to this integrator
|
|
73
|
+
optedIn: node.attrs.opted_in === 'true' || globalOptedIn,
|
|
74
|
+
features: {
|
|
75
|
+
groupMessaging: featuresNode?.attrs?.group_messaging === 'true'
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** Send a single TOS trackable item (shown or accepted). */
|
|
82
|
+
const sendTOSTrackable = async (id, result) => {
|
|
83
|
+
await query({
|
|
84
|
+
tag: 'iq',
|
|
85
|
+
attrs: { to: S_WHATSAPP_NET, type: 'set', xmlns: 'tos' },
|
|
86
|
+
content: [{ tag: 'trackable', attrs: { id, result } }]
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Accept TOS for interop.
|
|
92
|
+
* Sends two trackable items: shown (105) then accepted (160).
|
|
93
|
+
* Must be called before opting in.
|
|
94
|
+
*/
|
|
95
|
+
const acceptInteropTOS = async () => {
|
|
96
|
+
await sendTOSTrackable(TOS_TRACKABLE_ID, TOS_RESULT_SHOWN)
|
|
97
|
+
await sendTOSTrackable(TOS_TRACKABLE_ID, TOS_RESULT_ACCEPTED)
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Opt in to a list of integrators (by numeric ID).
|
|
102
|
+
* Defaults to both known integrators (BirdyChat + Haiket).
|
|
103
|
+
*/
|
|
104
|
+
const optInIntegrators = async (integratorIds = [INTEGRATOR_BIRDYCHAT, INTEGRATOR_HAIKET]) => {
|
|
105
|
+
await query({
|
|
106
|
+
tag: 'iq',
|
|
107
|
+
attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
108
|
+
content: [
|
|
109
|
+
{
|
|
110
|
+
tag: 'opt_in_integrators',
|
|
111
|
+
attrs: {},
|
|
112
|
+
content: [
|
|
113
|
+
{
|
|
114
|
+
tag: 'integrator_list',
|
|
115
|
+
attrs: {},
|
|
116
|
+
content: integratorIds.map(id => ({
|
|
117
|
+
tag: 'integrator',
|
|
118
|
+
attrs: { id: id.toString() }
|
|
119
|
+
}))
|
|
120
|
+
}
|
|
121
|
+
]
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Opt out of a list of integrators (by numeric ID).
|
|
129
|
+
* Mirror of optInIntegrators — uses <opt_out_integrators>.
|
|
130
|
+
*/
|
|
131
|
+
const optOutIntegrators = async (integratorIds = [INTEGRATOR_BIRDYCHAT, INTEGRATOR_HAIKET]) => {
|
|
132
|
+
await query({
|
|
133
|
+
tag: 'iq',
|
|
134
|
+
attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
135
|
+
content: [
|
|
136
|
+
{
|
|
137
|
+
tag: 'opt_out_integrators',
|
|
138
|
+
attrs: {},
|
|
139
|
+
content: [
|
|
140
|
+
{
|
|
141
|
+
tag: 'integrator_list',
|
|
142
|
+
attrs: {},
|
|
143
|
+
content: integratorIds.map(id => ({
|
|
144
|
+
tag: 'integrator',
|
|
145
|
+
attrs: { id: id.toString() }
|
|
146
|
+
}))
|
|
147
|
+
}
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
})
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Resolve one or more interop users by external ID in a single IQ.
|
|
156
|
+
* Each entry: { externalId, integratorId }
|
|
157
|
+
* - BirdyChat (12): externalId = email address
|
|
158
|
+
* - Haiket (13): externalId = phone number string (e.g. "19146088152")
|
|
159
|
+
*
|
|
160
|
+
* Max 256 entries per call (server limit).
|
|
161
|
+
*
|
|
162
|
+
* Returns an array of results:
|
|
163
|
+
* { jid, externalId, normalizedExternalId, integratorId } on success
|
|
164
|
+
* { externalId, integratorId, error: { code, text } } on failure
|
|
165
|
+
*/
|
|
166
|
+
const resolveInteropUsers = async users => {
|
|
167
|
+
if (!users || users.length === 0) return []
|
|
168
|
+
if (users.length > INTEROP_BATCH_MAX) {
|
|
169
|
+
throw new Error(`resolveInteropUsers: max ${INTEROP_BATCH_MAX} users per request`)
|
|
170
|
+
}
|
|
171
|
+
const result = await query({
|
|
172
|
+
tag: 'iq',
|
|
173
|
+
attrs: { type: 'get', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
174
|
+
content: [
|
|
175
|
+
{
|
|
176
|
+
tag: 'users',
|
|
177
|
+
attrs: {},
|
|
178
|
+
content: users.map(({ externalId, integratorId }) => ({
|
|
179
|
+
tag: 'user',
|
|
180
|
+
attrs: {
|
|
181
|
+
external_id: externalId,
|
|
182
|
+
integrator_id: integratorId.toString()
|
|
183
|
+
}
|
|
184
|
+
}))
|
|
185
|
+
}
|
|
186
|
+
]
|
|
187
|
+
})
|
|
188
|
+
const usersNode = getBinaryNodeChild(result, 'users')
|
|
189
|
+
if (!usersNode) return []
|
|
190
|
+
return getBinaryNodeChildren(usersNode, 'user').map(userNode => {
|
|
191
|
+
const errorNode = getBinaryNodeChild(userNode, 'error')
|
|
192
|
+
if (errorNode) {
|
|
193
|
+
return {
|
|
194
|
+
externalId: userNode.attrs.external_id,
|
|
195
|
+
integratorId: parseInt(userNode.attrs.integrator_id),
|
|
196
|
+
error: {
|
|
197
|
+
code: parseInt(errorNode.attrs.code),
|
|
198
|
+
text: errorNode.attrs.text
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
jid: userNode.attrs.jid,
|
|
204
|
+
externalId: userNode.attrs.external_id,
|
|
205
|
+
normalizedExternalId: userNode.attrs.normalized_external_id,
|
|
206
|
+
integratorId: parseInt(userNode.attrs.integrator_id)
|
|
207
|
+
}
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/**
|
|
212
|
+
* Convenience wrapper: resolve a single interop user.
|
|
213
|
+
* Returns the result object or null.
|
|
214
|
+
*/
|
|
215
|
+
const resolveInteropUser = async (externalId, integratorId) => {
|
|
216
|
+
const results = await resolveInteropUsers([{ externalId, integratorId }])
|
|
217
|
+
return results[0] ?? null
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Get reachability settings for interop contacts.
|
|
222
|
+
* Returns the raw <reachability_settings> node content.
|
|
223
|
+
* WA uses this as the interop presence/subscription mechanism.
|
|
224
|
+
*/
|
|
225
|
+
const getReachabilitySettings = async () => {
|
|
226
|
+
const result = await query({
|
|
227
|
+
tag: 'iq',
|
|
228
|
+
attrs: { type: 'get', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
229
|
+
content: [{ tag: 'reachability_settings', attrs: {} }]
|
|
230
|
+
})
|
|
231
|
+
const settingsNode = getBinaryNodeChild(result, 'reachability_settings')
|
|
232
|
+
if (!settingsNode) return null
|
|
233
|
+
return {
|
|
234
|
+
enabled: settingsNode.attrs?.enabled,
|
|
235
|
+
users: getBinaryNodeChildren(settingsNode, 'user').map(n => ({
|
|
236
|
+
externalId: n.attrs.external_id,
|
|
237
|
+
integratorId: parseInt(n.attrs.integrator_id),
|
|
238
|
+
jid: n.attrs.jid
|
|
239
|
+
}))
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Set reachability settings (subscribe to presence) for interop contacts.
|
|
245
|
+
* users: array of { externalId, integratorId }
|
|
246
|
+
* enabled: "true" | "false"
|
|
247
|
+
*/
|
|
248
|
+
const setReachabilitySettings = async (users, enabled = 'true') => {
|
|
249
|
+
await query({
|
|
250
|
+
tag: 'iq',
|
|
251
|
+
attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
252
|
+
content: [
|
|
253
|
+
{
|
|
254
|
+
tag: 'reachability_settings',
|
|
255
|
+
attrs: { enabled },
|
|
256
|
+
content: users.map(({ externalId, integratorId }) => ({
|
|
257
|
+
tag: 'user',
|
|
258
|
+
attrs: {
|
|
259
|
+
external_id: externalId,
|
|
260
|
+
integrator_id: integratorId.toString()
|
|
261
|
+
}
|
|
262
|
+
}))
|
|
263
|
+
}
|
|
264
|
+
]
|
|
265
|
+
})
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Block or unblock an interop user via the w:interop blocklist.
|
|
270
|
+
* Different from regular WA block (xmlns=blocklist).
|
|
271
|
+
*/
|
|
272
|
+
const updateInteropBlockStatus = async (jid, action) => {
|
|
273
|
+
await query({
|
|
274
|
+
tag: 'iq',
|
|
275
|
+
attrs: { type: 'set', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
276
|
+
content: [
|
|
277
|
+
{
|
|
278
|
+
tag: 'blocklist',
|
|
279
|
+
attrs: {},
|
|
280
|
+
content: [{ tag: 'item', attrs: { action, jid } }]
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
const blockInteropUser = jid => updateInteropBlockStatus(jid, 'block')
|
|
287
|
+
const unblockInteropUser = jid => updateInteropBlockStatus(jid, 'unblock')
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* Report an interop contact as spam.
|
|
291
|
+
* spam_flow="account_info_block" = block + report (WA Web default).
|
|
292
|
+
*/
|
|
293
|
+
const reportInteropSpam = async (jid, spamFlow = 'account_info_block') => {
|
|
294
|
+
await query({
|
|
295
|
+
tag: 'iq',
|
|
296
|
+
attrs: { type: 'set', xmlns: 'spam', to: S_WHATSAPP_NET },
|
|
297
|
+
content: [{ tag: 'spam_list', attrs: { jid, spam_flow: spamFlow } }]
|
|
298
|
+
})
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Mark an interop JID as trusted_contact in privacy tokens.
|
|
303
|
+
* WA calls this automatically after the first outgoing message.
|
|
304
|
+
*/
|
|
305
|
+
const trustInteropContact = async jid => {
|
|
306
|
+
const t = Math.floor(Date.now() / 1000).toString()
|
|
307
|
+
await query({
|
|
308
|
+
tag: 'iq',
|
|
309
|
+
attrs: { to: S_WHATSAPP_NET, xmlns: 'privacy', type: 'set' },
|
|
310
|
+
content: [
|
|
311
|
+
{
|
|
312
|
+
tag: 'tokens',
|
|
313
|
+
attrs: {},
|
|
314
|
+
content: [{ tag: 'token', attrs: { jid, type: 'trusted_contact', t } }]
|
|
315
|
+
}
|
|
316
|
+
]
|
|
317
|
+
})
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Full interop initialization sequence matching WA Web:
|
|
322
|
+
* 1. Fetch available integrators
|
|
323
|
+
* 2. Accept TOS (shown 105 + accepted 160)
|
|
324
|
+
* 3. Opt-in to all active/onboarding integrators
|
|
325
|
+
*
|
|
326
|
+
* Silently tolerates TOS/opt-in errors.
|
|
327
|
+
* Returns the full integrator list.
|
|
328
|
+
*/
|
|
329
|
+
const initInterop = async () => {
|
|
330
|
+
let integrators
|
|
331
|
+
try {
|
|
332
|
+
integrators = await fetchIntegrators()
|
|
333
|
+
} catch (err) {
|
|
334
|
+
logger.warn({ err }, 'interop: failed to fetch integrators')
|
|
335
|
+
return []
|
|
336
|
+
}
|
|
337
|
+
const toOptIn = integrators.filter(i => i.status === 'active' || i.status === 'onboarding')
|
|
338
|
+
if (toOptIn.length === 0) return integrators
|
|
339
|
+
try {
|
|
340
|
+
await acceptInteropTOS()
|
|
341
|
+
} catch (err) {
|
|
342
|
+
logger.warn({ err }, 'interop: failed to accept TOS')
|
|
343
|
+
}
|
|
344
|
+
try {
|
|
345
|
+
await optInIntegrators(toOptIn.map(i => i.id))
|
|
346
|
+
} catch (err) {
|
|
347
|
+
logger.warn({ err }, 'interop: failed to opt-in integrators')
|
|
348
|
+
}
|
|
349
|
+
logger.info({ integrators: toOptIn.map(i => i.name) }, 'interop: initialized')
|
|
350
|
+
return integrators
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* Reset the Signal session with an interop contact and force a fresh pkmsg handshake.
|
|
355
|
+
* Call this when incoming messages from an interop contact are not arriving or
|
|
356
|
+
* failing to decrypt — it clears the stale session so the next sendMessage
|
|
357
|
+
* generates a new pre-key message and re-establishes both directions.
|
|
358
|
+
*/
|
|
359
|
+
const resetInteropSession = async jid => {
|
|
360
|
+
await signalRepository.deleteSession([jid])
|
|
361
|
+
logger.info({ jid }, '[interop] session reset — next send will use pkmsg')
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Create an interop group via MEX.
|
|
366
|
+
* Confirmed from C80913Xf.java opcode 15:
|
|
367
|
+
* input: { participants: [{ jid }] }
|
|
368
|
+
* dataPath: xwa2_interop_group_create
|
|
369
|
+
*
|
|
370
|
+
* @param {string[]} participants - Interop JIDs to add
|
|
371
|
+
* @returns {{ gid, creationTime, creator, participants }}
|
|
372
|
+
*/
|
|
373
|
+
const createInteropGroup = async participants => {
|
|
374
|
+
const result = await mexQuery(
|
|
375
|
+
{ input: { participants: participants.map(jid => ({ jid })) } },
|
|
376
|
+
INTEROP_MEX_QUERY_IDS.CREATE_GROUP,
|
|
377
|
+
'xwa2_interop_group_create'
|
|
378
|
+
)
|
|
379
|
+
logger.info({ participants }, '[interop] group created via MEX')
|
|
380
|
+
return result
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Leave one or more interop groups via MEX.
|
|
385
|
+
* Confirmed from C80913Xf.java opcode 28:
|
|
386
|
+
* input: { groups_to_leave: [{ gid }] }
|
|
387
|
+
* dataPath: xwa2_interop_group_leave
|
|
388
|
+
*
|
|
389
|
+
* gid is the raw interop group ID (without @g.us suffix).
|
|
390
|
+
* @param {string|string[]} jids - Interop group JID(s)
|
|
391
|
+
*/
|
|
392
|
+
const leaveInteropGroup = async jids => {
|
|
393
|
+
const ids = Array.isArray(jids) ? jids : [jids]
|
|
394
|
+
const result = await mexQuery(
|
|
395
|
+
{ input: { groups_to_leave: ids.map(jid => ({ gid: jid.split('@')[0] })) } },
|
|
396
|
+
INTEROP_MEX_QUERY_IDS.LEAVE_GROUP,
|
|
397
|
+
'xwa2_interop_group_leave'
|
|
398
|
+
)
|
|
399
|
+
logger.info({ jids: ids }, '[interop] left group(s) via MEX')
|
|
400
|
+
return result
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
/**
|
|
404
|
+
* Add participants to an existing interop group via MEX.
|
|
405
|
+
* Confirmed from C3Wt.java opcode 9:
|
|
406
|
+
* input: { gid, participants: [{ jid }] }
|
|
407
|
+
* dataPath: xwa2_interop_add_participants_to_group
|
|
408
|
+
*
|
|
409
|
+
* @param {string} groupJid - Interop group JID
|
|
410
|
+
* @param {string[]} participants - Interop JIDs to add
|
|
411
|
+
*/
|
|
412
|
+
const addParticipantsToInteropGroup = async (groupJid, participants) => {
|
|
413
|
+
const gid = groupJid.split('@')[0]
|
|
414
|
+
return mexQuery(
|
|
415
|
+
{ input: { gid, participants: participants.map(jid => ({ jid })) } },
|
|
416
|
+
INTEROP_MEX_QUERY_IDS.ADD_PARTICIPANTS,
|
|
417
|
+
'xwa2_interop_add_participants_to_group'
|
|
418
|
+
)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Query info about an interop group via MEX.
|
|
423
|
+
* Confirmed from C3Wt.java opcode 10:
|
|
424
|
+
* group_input: { gid }
|
|
425
|
+
* dataPath: xwa2_interop_group_query_by_id
|
|
426
|
+
*
|
|
427
|
+
* @param {string} groupJid - Interop group JID
|
|
428
|
+
*/
|
|
429
|
+
const queryInteropGroupInfo = async groupJid => {
|
|
430
|
+
const gid = groupJid.split('@')[0]
|
|
431
|
+
return mexQuery(
|
|
432
|
+
{ group_input: { gid } },
|
|
433
|
+
INTEROP_MEX_QUERY_IDS.QUERY_GROUP_INFO,
|
|
434
|
+
'xwa2_interop_group_query_by_id'
|
|
435
|
+
)
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Update an interop privacy setting via MEX.
|
|
440
|
+
* Confirmed from C24385Ak0.java (InteropPrivacySettingsUpdate):
|
|
441
|
+
* feature, setting
|
|
442
|
+
* dataPath: xwa2_interop_privacy_setting_update
|
|
443
|
+
*
|
|
444
|
+
* Known features: "GROUPADD"
|
|
445
|
+
* Known settings: "ALL" | "CONTACTS" | "NONE"
|
|
446
|
+
*
|
|
447
|
+
* @param {string} feature - Privacy feature name
|
|
448
|
+
* @param {string} setting - New value
|
|
449
|
+
*/
|
|
450
|
+
const updateInteropPrivacySetting = async (feature, setting) => {
|
|
451
|
+
return mexQuery(
|
|
452
|
+
{ feature, setting },
|
|
453
|
+
INTEROP_MEX_QUERY_IDS.PRIVACY_SETTINGS_UPDATE,
|
|
454
|
+
'xwa2_interop_privacy_setting_update'
|
|
455
|
+
)
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
/**
|
|
459
|
+
* Update an interop privacy setting with an explicit contact list via MEX.
|
|
460
|
+
* Confirmed from C24388Ak8.java (InteropPrivacySettingWithContactListUpdate):
|
|
461
|
+
* feature, setting, contacts[], contact_list_type, dhash
|
|
462
|
+
* dataPath: xwa2_interop_privacy_setting_with_contact_list_update
|
|
463
|
+
*
|
|
464
|
+
* Used when setting is "CONTACTS" and you want to specify exact allowed contacts.
|
|
465
|
+
*
|
|
466
|
+
* @param {string} feature - Privacy feature (e.g. "GROUPADD")
|
|
467
|
+
* @param {string} setting - "CONTACTS"
|
|
468
|
+
* @param {string[]} contacts - List of JIDs to allow
|
|
469
|
+
* @param {string} contactListType - Contact list type string
|
|
470
|
+
* @param {string} [dhash] - Hash of the current contact list (or null/"none")
|
|
471
|
+
*/
|
|
472
|
+
const updateInteropPrivacySettingWithContactList = async (
|
|
473
|
+
feature,
|
|
474
|
+
setting,
|
|
475
|
+
contacts,
|
|
476
|
+
contactListType,
|
|
477
|
+
dhash = 'none'
|
|
478
|
+
) => {
|
|
479
|
+
return mexQuery(
|
|
480
|
+
{ feature, setting, contacts, contact_list_type: contactListType, dhash },
|
|
481
|
+
INTEROP_MEX_QUERY_IDS.PRIVACY_SETTINGS_WITH_CONTACT_LIST,
|
|
482
|
+
'xwa2_interop_privacy_setting_with_contact_list_update'
|
|
483
|
+
)
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Check whether an interop user allows being added to groups (GROUPADD privacy).
|
|
488
|
+
* Returns true if the user can be added, false if blocked by their privacy settings.
|
|
489
|
+
*
|
|
490
|
+
* Mirrors InteropPrivacySettingsManager.A01() in the APK which queries
|
|
491
|
+
* the "GROUPADD" feature for the given account.
|
|
492
|
+
*/
|
|
493
|
+
const getInteropGroupAddPrivacy = async (jid, integratorId) => {
|
|
494
|
+
const result = await query({
|
|
495
|
+
tag: 'iq',
|
|
496
|
+
attrs: { type: 'get', xmlns: 'w:interop', to: S_WHATSAPP_NET },
|
|
497
|
+
content: [
|
|
498
|
+
{
|
|
499
|
+
tag: 'privacy',
|
|
500
|
+
attrs: { feature: 'GROUPADD' },
|
|
501
|
+
content: [
|
|
502
|
+
{
|
|
503
|
+
tag: 'user',
|
|
504
|
+
attrs: {
|
|
505
|
+
jid,
|
|
506
|
+
integrator_id: integratorId.toString()
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
]
|
|
510
|
+
}
|
|
511
|
+
]
|
|
512
|
+
})
|
|
513
|
+
const privacyNode = getBinaryNodeChild(result, 'privacy')
|
|
514
|
+
const userNode = getBinaryNodeChild(privacyNode, 'user')
|
|
515
|
+
// "allowed" means the server confirmed the user can be added; any other value or
|
|
516
|
+
// absence of the attribute means the privacy setting blocks the add.
|
|
517
|
+
return userNode?.attrs?.result === 'allowed'
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
return {
|
|
521
|
+
...sock,
|
|
522
|
+
fetchIntegrators,
|
|
523
|
+
acceptInteropTOS,
|
|
524
|
+
optInIntegrators,
|
|
525
|
+
optOutIntegrators,
|
|
526
|
+
resolveInteropUser,
|
|
527
|
+
resolveInteropUsers,
|
|
528
|
+
getReachabilitySettings,
|
|
529
|
+
setReachabilitySettings,
|
|
530
|
+
blockInteropUser,
|
|
531
|
+
unblockInteropUser,
|
|
532
|
+
reportInteropSpam,
|
|
533
|
+
trustInteropContact,
|
|
534
|
+
initInterop,
|
|
535
|
+
resetInteropSession,
|
|
536
|
+
createInteropGroup,
|
|
537
|
+
leaveInteropGroup,
|
|
538
|
+
addParticipantsToInteropGroup,
|
|
539
|
+
queryInteropGroupInfo,
|
|
540
|
+
updateInteropPrivacySetting,
|
|
541
|
+
updateInteropPrivacySettingWithContactList,
|
|
542
|
+
getInteropGroupAddPrivacy,
|
|
543
|
+
INTEGRATOR_BIRDYCHAT,
|
|
544
|
+
INTEGRATOR_HAIKET,
|
|
545
|
+
INTEROP_MEX_QUERY_IDS
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
exports.makeInteropSocket = makeInteropSocket
|