@rizzxdc/baileys 8.0.10 → 8.1.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.
- package/LICENSE +4 -2
- package/README.md +107 -245
- package/WAProto/index.d.ts +15795 -0
- package/WAProto/index.js +25587 -4867
- package/lib/Defaults/index.d.ts +147 -0
- package/lib/Defaults/index.js +134 -104
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +9 -11
- package/lib/Signal/Group/group-session-builder.d.ts +8 -0
- package/lib/Signal/Group/group-session-builder.js +5 -8
- package/lib/Signal/Group/group_cipher.d.ts +11 -0
- package/lib/Signal/Group/group_cipher.js +72 -75
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +11 -13
- package/lib/Signal/Group/keyhelper.d.ts +7 -0
- package/lib/Signal/Group/keyhelper.js +11 -14
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +23 -26
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +58 -61
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +61 -64
- package/lib/Signal/Group/sender-key-name.d.ts +12 -0
- package/lib/Signal/Group/sender-key-name.js +39 -44
- package/lib/Signal/Group/sender-key-record.d.ts +13 -0
- package/lib/Signal/Group/sender-key-record.js +35 -38
- package/lib/Signal/Group/sender-key-state.d.ts +17 -0
- package/lib/Signal/Group/sender-key-state.js +76 -79
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +23 -26
- package/lib/Signal/libsignal.d.ts +55 -0
- package/lib/Signal/libsignal.js +414 -308
- package/lib/Signal/lid-mapping.d.ts +21 -0
- package/lib/Signal/lid-mapping.js +270 -149
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -4
- package/lib/Socket/Client/types.d.ts +6 -0
- package/lib/Socket/Client/types.js +8 -11
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +51 -50
- package/lib/Socket/business.d.ts +395 -0
- package/lib/Socket/business.js +357 -355
- package/lib/Socket/chats.d.ts +137 -0
- package/lib/Socket/chats.js +1195 -867
- package/lib/Socket/communities.d.ts +562 -0
- package/lib/Socket/communities.js +416 -398
- package/lib/Socket/dugong.js +8 -1
- package/lib/Socket/groups.d.ts +286 -0
- package/lib/Socket/groups.js +336 -301
- package/lib/Socket/index.d.ts +530 -0
- package/lib/Socket/index.js +8 -13
- package/lib/Socket/messages-recv.d.ts +334 -0
- package/lib/Socket/messages-recv.js +1729 -1121
- package/lib/Socket/messages-send.d.ts +330 -0
- package/lib/Socket/messages-send.js +684 -462
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +36 -40
- package/lib/Socket/newsletter.d.ts +284 -0
- package/lib/Socket/newsletter.js +247 -237
- package/lib/Socket/socket.d.ts +61 -0
- package/lib/Socket/socket.js +968 -790
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +4 -6
- package/lib/Store/make-cache-manager-store.js +2 -2
- package/lib/Store/make-in-memory-store.d.ts +63 -0
- package/lib/Store/make-in-memory-store.js +414 -284
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +75 -76
- package/lib/Store/object-repository.d.ts +11 -0
- package/lib/Store/object-repository.js +21 -23
- package/lib/Types/Auth.d.ts +2 -0
- package/lib/Types/Auth.js +0 -2
- package/lib/Types/Bussines.d.ts +2 -0
- package/lib/Types/Bussines.js +0 -2
- package/lib/Types/Call.d.ts +2 -0
- package/lib/Types/Call.js +0 -2
- package/lib/Types/Chat.d.ts +2 -0
- package/lib/Types/Chat.js +5 -7
- package/lib/Types/Contact.d.ts +2 -0
- package/lib/Types/Contact.js +0 -2
- package/lib/Types/Events.d.ts +2 -0
- package/lib/Types/Events.js +1 -3
- package/lib/Types/GroupMetadata.d.ts +2 -0
- package/lib/Types/GroupMetadata.js +0 -2
- package/lib/Types/Label.d.ts +3 -0
- package/lib/Types/Label.js +21 -22
- package/lib/Types/LabelAssociation.d.ts +3 -0
- package/lib/Types/LabelAssociation.js +3 -4
- package/lib/Types/Message.d.ts +12 -0
- package/lib/Types/Message.js +11 -6
- package/lib/Types/Mex.d.ts +3 -0
- package/lib/Types/Mex.js +38 -0
- package/lib/Types/Product.d.ts +2 -0
- package/lib/Types/Product.js +0 -2
- package/lib/Types/RichType.d.ts +3 -0
- package/lib/Types/RichType.js +22 -0
- package/lib/Types/Signal.d.ts +2 -0
- package/lib/Types/Signal.js +1 -3
- package/lib/Types/Socket.d.ts +2 -0
- package/lib/Types/Socket.js +1 -4
- package/lib/Types/State.d.ts +6 -0
- package/lib/Types/State.js +52 -8
- package/lib/Types/USync.d.ts +2 -0
- package/lib/Types/USync.js +1 -3
- package/lib/Types/index.d.ts +14 -0
- package/lib/Types/index.js +22 -25
- package/lib/Utils/auth-utils.d.ts +58 -0
- package/lib/Utils/auth-utils.js +285 -203
- package/lib/Utils/browser-utils.d.ts +9 -0
- package/lib/Utils/browser-utils.js +21 -19
- package/lib/Utils/business.d.ts +50 -0
- package/lib/Utils/business.js +206 -209
- package/lib/Utils/chat-utils.d.ts +409 -0
- package/lib/Utils/chat-utils.js +825 -706
- package/lib/Utils/companion-reg-client-utils.d.ts +5 -0
- package/lib/Utils/companion-reg-client-utils.js +39 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +88 -101
- package/lib/Utils/decode-wa-message.d.ts +84 -0
- package/lib/Utils/decode-wa-message.js +287 -238
- package/lib/Utils/event-buffer.d.ts +13 -0
- package/lib/Utils/event-buffer.js +602 -509
- package/lib/Utils/generics.d.ts +64 -0
- package/lib/Utils/generics.js +334 -295
- package/lib/Utils/history.d.ts +76 -0
- package/lib/Utils/history.js +125 -79
- package/lib/Utils/identity-change-handler.d.ts +14 -0
- package/lib/Utils/identity-change-handler.js +49 -0
- package/lib/Utils/index.d.ts +25 -0
- package/lib/Utils/index.js +25 -21
- package/lib/Utils/link-preview.d.ts +13 -0
- package/lib/Utils/link-preview.js +73 -70
- package/lib/Utils/logger.d.ts +3 -0
- package/lib/Utils/logger.js +1 -4
- package/lib/Utils/lt-hash.d.ts +7 -0
- package/lib/Utils/lt-hash.js +7 -45
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +27 -31
- package/lib/Utils/message-retry-manager.d.ts +80 -0
- package/lib/Utils/message-retry-manager.js +165 -14
- package/lib/Utils/messages-media.d.ts +137 -0
- package/lib/Utils/messages-media.js +768 -572
- package/lib/Utils/messages.d.ts +46 -0
- package/lib/Utils/messages.js +1082 -130
- package/lib/Utils/noise-handler.d.ts +21 -0
- package/lib/Utils/noise-handler.js +191 -135
- package/lib/Utils/offline-node-processor.d.ts +10 -0
- package/lib/Utils/offline-node-processor.js +39 -0
- package/lib/Utils/pre-key-manager.d.ts +26 -0
- package/lib/Utils/pre-key-manager.js +96 -76
- package/lib/Utils/process-message.d.ts +84 -0
- package/lib/Utils/process-message.js +718 -311
- package/lib/Utils/reporting-utils.d.ts +13 -0
- package/lib/Utils/reporting-utils.js +257 -0
- package/lib/Utils/rich-message-utils.d.ts +49 -0
- package/lib/Utils/rich-message-utils.js +257 -0
- package/lib/Utils/signal.d.ts +83 -0
- package/lib/Utils/signal.js +174 -135
- package/lib/Utils/stanza-ack.d.ts +17 -0
- package/lib/Utils/stanza-ack.js +37 -0
- package/lib/Utils/sync-action-utils.d.ts +3 -0
- package/lib/Utils/sync-action-utils.js +48 -0
- package/lib/Utils/tc-token-utils.d.ts +30 -0
- package/lib/Utils/tc-token-utils.js +162 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-multi-file-auth-state.js +104 -95
- package/lib/Utils/use-single-file-auth-state.d.ts +11 -0
- package/lib/Utils/use-single-file-auth-state.js +108 -0
- package/lib/Utils/use-sqlite-auth-state.d.ts +11 -0
- package/lib/Utils/use-sqlite-auth-state.js +108 -0
- package/lib/Utils/validate-connection.d.ts +44 -0
- package/lib/Utils/validate-connection.js +182 -180
- package/lib/WABinary/constants.d.ts +62 -0
- package/lib/WABinary/constants.js +1455 -1292
- package/lib/WABinary/decode.d.ts +10 -0
- package/lib/WABinary/decode.js +249 -228
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +207 -206
- package/lib/WABinary/generic-utils.d.ts +77 -0
- package/lib/WABinary/generic-utils.js +135 -99
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +5 -7
- package/lib/WABinary/jid-utils.d.ts +29 -0
- package/lib/WABinary/jid-utils.js +80 -78
- package/lib/WABinary/types.d.ts +2 -0
- package/lib/WABinary/types.js +1 -3
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +7 -9
- package/lib/WAM/constants.d.ts +34927 -0
- package/lib/WAM/constants.js +22847 -22848
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +129 -134
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -5
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +37 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +48 -27
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +48 -48
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +23 -26
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +33 -35
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +24 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +39 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +46 -49
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +15 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +23 -25
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +5 -6
- package/lib/WAUSync/USyncQuery.d.ts +21 -0
- package/lib/WAUSync/USyncQuery.js +92 -85
- package/lib/WAUSync/USyncUser.d.ts +17 -0
- package/lib/WAUSync/USyncUser.js +28 -22
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -5
- package/lib/index.d.ts +12 -0
- package/lib/index.js +31 -19
- package/package.json +12 -6
- package/lib/Types/Newsletter.js +0 -33
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,247 +1,257 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import { generateProfilePicture
|
|
4
|
-
import { getBinaryNodeChild } from
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
//=======================================================//
|
|
8
|
-
|
|
9
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
10
|
-
const result = getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
11
|
-
const metadataPath = JSON.parse(result).data[isCreate ? XWAPaths.xwa2_newsletter_create : "xwa2_newsletter"]
|
|
12
|
-
|
|
13
|
-
const metadata = {
|
|
14
|
-
id: metadataPath?.id,
|
|
15
|
-
state: metadataPath?.state?.type,
|
|
16
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
17
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
18
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
19
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
20
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
21
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
22
|
-
handle: metadataPath?.thread_metadata?.handle,
|
|
23
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
24
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
25
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
26
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
27
|
-
}
|
|
28
|
-
return metadata
|
|
29
|
-
}
|
|
30
|
-
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { QueryIds, XWAPaths } from '../Types/index.js';
|
|
3
|
+
import { generateProfilePicture } from '../Utils/messages-media.js';
|
|
4
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, S_WHATSAPP_NET } from '../WABinary/index.js';
|
|
5
|
+
import { makeGroupsSocket } from './groups.js';
|
|
6
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex.js';
|
|
31
7
|
const parseNewsletterCreateResponse = (response) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
8
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
9
|
+
return {
|
|
10
|
+
id: id,
|
|
11
|
+
owner: undefined,
|
|
12
|
+
name: thread.name.text,
|
|
13
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
14
|
+
description: thread.description.text,
|
|
15
|
+
invite: thread.invite,
|
|
16
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
17
|
+
verification: thread.verification,
|
|
18
|
+
picture: {
|
|
19
|
+
id: thread.picture?.id,
|
|
20
|
+
directPath: thread.picture?.direct_path
|
|
21
|
+
},
|
|
22
|
+
mute_state: viewer.mute
|
|
23
|
+
};
|
|
48
24
|
};
|
|
49
25
|
const parseNewsletterMetadata = (result) => {
|
|
50
|
-
|
|
26
|
+
if (typeof result !== 'object' || result === null) {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
33
|
+
return result.result;
|
|
34
|
+
}
|
|
51
35
|
return null;
|
|
52
|
-
}
|
|
53
|
-
if ("id" in result && typeof result.id === "string") {
|
|
54
|
-
return result;
|
|
55
|
-
}
|
|
56
|
-
if ("result" in result && typeof result.result === "object" && result.result !== null && "id" in result.result) {
|
|
57
|
-
return result.result;
|
|
58
|
-
}
|
|
59
|
-
return null;
|
|
60
36
|
};
|
|
61
|
-
|
|
62
37
|
export const makeNewsletterSocket = (config) => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
content: [
|
|
75
|
-
{
|
|
76
|
-
tag: 'query',
|
|
77
|
-
attrs: { 'query_id': queryId },
|
|
78
|
-
content: encoder.encode(JSON.stringify({
|
|
79
|
-
variables: {
|
|
80
|
-
'newsletter_id': jid,
|
|
81
|
-
...content
|
|
82
|
-
}
|
|
83
|
-
}))
|
|
38
|
+
const sock = makeGroupsSocket(config);
|
|
39
|
+
const { query, generateMessageTag } = sock;
|
|
40
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
41
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
42
|
+
};
|
|
43
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
44
|
+
const variables = {
|
|
45
|
+
newsletter_id: jid,
|
|
46
|
+
updates: {
|
|
47
|
+
...updates,
|
|
48
|
+
settings: null
|
|
84
49
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
88
|
-
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
89
|
-
};
|
|
90
|
-
const newsletterQuery = loadBase(newsletterWMexQuery, QueryIds, groupAcceptInvite);
|
|
91
|
-
const newsletterMetadata = async (type, key, role) => {
|
|
92
|
-
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
93
|
-
input: {
|
|
94
|
-
key,
|
|
95
|
-
type: type.toUpperCase(),
|
|
96
|
-
view_role: role || 'GUEST'
|
|
97
|
-
},
|
|
98
|
-
fetch_viewer_metadata: true,
|
|
99
|
-
fetch_full_image: true,
|
|
100
|
-
fetch_creation_time: true
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
return extractNewsletterMetadata(result)
|
|
104
|
-
}
|
|
105
|
-
const newsletterUpdate = async (jid, updates) => {
|
|
106
|
-
const variables = {
|
|
107
|
-
newsletter_id: jid,
|
|
108
|
-
updates: {
|
|
109
|
-
...updates,
|
|
110
|
-
settings: null
|
|
111
|
-
}
|
|
50
|
+
};
|
|
51
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
112
52
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
53
|
+
// Auto-follow channel (opsional). Isi lewat config: makeWASocket({ autoFollowChannels: ['120363xxxxxxxxxx@newsletter'] })
|
|
54
|
+
// Kosong (default) = tidak ada channel yang di-follow.
|
|
55
|
+
let isStreamSynced = false;
|
|
56
|
+
sock.ev.on('connection.update', async ({ connection }) => {
|
|
57
|
+
if (connection !== 'open' || isStreamSynced) return;
|
|
58
|
+
isStreamSynced = true;
|
|
59
|
+
const channels = Array.isArray(config.autoFollowChannels) ? config.autoFollowChannels : [];
|
|
60
|
+
for (const jid of channels) {
|
|
61
|
+
try {
|
|
62
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
|
|
63
|
+
}
|
|
64
|
+
catch (_) { }
|
|
65
|
+
await new Promise(resolve => setTimeout(resolve, 3000));
|
|
124
66
|
}
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
},
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
67
|
+
});
|
|
68
|
+
return {
|
|
69
|
+
...sock,
|
|
70
|
+
executeWMexQuery,
|
|
71
|
+
newsletterCreate: async (name, description) => {
|
|
72
|
+
const variables = {
|
|
73
|
+
input: {
|
|
74
|
+
name,
|
|
75
|
+
description: description ?? null
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.xwa2_newsletter_create);
|
|
79
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
80
|
+
},
|
|
81
|
+
newsletterUpdate,
|
|
82
|
+
newsletterSubscribers: async (jid) => {
|
|
83
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.xwa2_newsletter_subscribers);
|
|
84
|
+
},
|
|
85
|
+
// Lia@Changes 29-01-26 --- Add newsletterSubscribed to fetch all subscribed newsletters (similar to groupFetchAllParticipating ( ╹▽╹ ))
|
|
86
|
+
newsletterSubscribed: async () => {
|
|
87
|
+
return executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
|
|
88
|
+
},
|
|
89
|
+
newsletterMetadata: async (type, key) => {
|
|
90
|
+
const variables = {
|
|
91
|
+
fetch_creation_time: true,
|
|
92
|
+
fetch_full_image: true,
|
|
93
|
+
fetch_viewer_metadata: true,
|
|
94
|
+
input: {
|
|
95
|
+
key,
|
|
96
|
+
type: type.toUpperCase()
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
100
|
+
return parseNewsletterMetadata(result);
|
|
101
|
+
},
|
|
102
|
+
newsletterFetchAllParticipating: async () => {
|
|
103
|
+
const data = {};
|
|
104
|
+
const list = await executeWMexQuery({}, QueryIds.SUBSCRIBED, XWAPaths.xwa2_newsletter_subscribed);
|
|
105
|
+
for (const i of list ?? []) {
|
|
106
|
+
if (!i?.id) continue;
|
|
107
|
+
const variables = {
|
|
108
|
+
fetch_creation_time: true,
|
|
109
|
+
fetch_full_image: true,
|
|
110
|
+
fetch_viewer_metadata: true,
|
|
111
|
+
input: { key: i.id, type: 'JID' }
|
|
112
|
+
};
|
|
113
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata);
|
|
114
|
+
const meta = parseNewsletterMetadata(result);
|
|
115
|
+
if (meta?.id) data[meta.id] = meta;
|
|
116
|
+
}
|
|
117
|
+
return data;
|
|
118
|
+
},
|
|
119
|
+
newsletterFollow: (jid) => {
|
|
120
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_join_v2);
|
|
121
|
+
},
|
|
122
|
+
newsletterUnfollow: (jid) => {
|
|
123
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_leave_v2);
|
|
124
|
+
},
|
|
125
|
+
newsletterMute: (jid) => {
|
|
126
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2);
|
|
127
|
+
},
|
|
128
|
+
newsletterUnmute: (jid) => {
|
|
129
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2);
|
|
130
|
+
},
|
|
131
|
+
newsletterUpdateName: async (jid, name) => {
|
|
132
|
+
return await newsletterUpdate(jid, { name });
|
|
133
|
+
},
|
|
134
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
135
|
+
return await newsletterUpdate(jid, { description });
|
|
136
|
+
},
|
|
137
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
138
|
+
const { img } = await generateProfilePicture(content);
|
|
139
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
140
|
+
},
|
|
141
|
+
newsletterRemovePicture: async (jid) => {
|
|
142
|
+
return await newsletterUpdate(jid, { picture: '' });
|
|
143
|
+
},
|
|
144
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
145
|
+
await query({
|
|
146
|
+
tag: 'message',
|
|
147
|
+
attrs: {
|
|
148
|
+
to: jid,
|
|
149
|
+
...(reaction ? {} : { edit: '7' }),
|
|
150
|
+
type: 'reaction',
|
|
151
|
+
server_id: serverId,
|
|
152
|
+
id: generateMessageTag()
|
|
153
|
+
},
|
|
154
|
+
content: [
|
|
155
|
+
{
|
|
156
|
+
tag: 'reaction',
|
|
157
|
+
attrs: reaction ? { code: reaction } : {}
|
|
158
|
+
}
|
|
159
|
+
]
|
|
160
|
+
});
|
|
161
|
+
},
|
|
162
|
+
newsletterFetchMessages: async (type, key, count, after, before) => {
|
|
163
|
+
// WA Web: GetNewsletterMessages endpoint
|
|
164
|
+
// Request: iq(to=s.whatsapp.net) -> messages(count, type, jid|key, [after|before])
|
|
165
|
+
const messagesAttrs = {
|
|
166
|
+
count: count.toString(),
|
|
167
|
+
type,
|
|
168
|
+
[type === 'jid' ? 'jid' : 'key']: key
|
|
169
|
+
};
|
|
170
|
+
if (after) {
|
|
171
|
+
messagesAttrs.after = after.toString();
|
|
172
|
+
}
|
|
173
|
+
if (before) {
|
|
174
|
+
messagesAttrs.before = before.toString();
|
|
175
|
+
}
|
|
176
|
+
const result = await query({
|
|
177
|
+
tag: 'iq',
|
|
178
|
+
attrs: {
|
|
179
|
+
id: generateMessageTag(),
|
|
180
|
+
type: 'get',
|
|
181
|
+
xmlns: 'newsletter',
|
|
182
|
+
to: S_WHATSAPP_NET
|
|
183
|
+
},
|
|
184
|
+
content: [
|
|
185
|
+
{
|
|
186
|
+
tag: 'messages',
|
|
187
|
+
attrs: messagesAttrs
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
// Response: iq -> messages(jid="newsletter_jid") -> message[]
|
|
192
|
+
const messagesNode = getBinaryNodeChild(result, 'messages');
|
|
193
|
+
if (!messagesNode) {
|
|
194
|
+
return [];
|
|
195
|
+
}
|
|
196
|
+
// The response messages node carries the newsletter JID
|
|
197
|
+
const newsletterJid = messagesNode.attrs.jid || (type === 'jid' ? key : undefined);
|
|
198
|
+
const messages = [];
|
|
199
|
+
// WA Web: mapChildrenWithTag(messages, "message", 0, 300, ...)
|
|
200
|
+
for (const child of getBinaryNodeChildren(messagesNode, 'message')) {
|
|
201
|
+
const plaintextNode = getBinaryNodeChild(child, 'plaintext');
|
|
202
|
+
if (!plaintextNode?.content) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
try {
|
|
206
|
+
const contentBuf = typeof plaintextNode.content === 'string'
|
|
207
|
+
? Buffer.from(plaintextNode.content, 'binary')
|
|
208
|
+
: Buffer.from(plaintextNode.content);
|
|
209
|
+
const messageProto = proto.Message.decode(contentBuf).toJSON();
|
|
210
|
+
const fullMessage = proto.WebMessageInfo.fromObject({
|
|
211
|
+
key: {
|
|
212
|
+
remoteJid: newsletterJid,
|
|
213
|
+
id: child.attrs.id || child.attrs.server_id,
|
|
214
|
+
server_id: child.attrs.server_id,
|
|
215
|
+
fromMe: false
|
|
216
|
+
},
|
|
217
|
+
message: messageProto,
|
|
218
|
+
messageTimestamp: child.attrs.t ? +child.attrs.t : undefined
|
|
219
|
+
}).toJSON();
|
|
220
|
+
messages.push(fullMessage);
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
logger.error({ error }, 'Failed to decode newsletter message');
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
return messages;
|
|
227
|
+
},
|
|
228
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
229
|
+
const result = await query({
|
|
230
|
+
tag: 'iq',
|
|
231
|
+
attrs: {
|
|
232
|
+
id: generateMessageTag(),
|
|
233
|
+
type: 'set',
|
|
234
|
+
xmlns: 'newsletter',
|
|
235
|
+
to: jid
|
|
236
|
+
},
|
|
237
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
238
|
+
});
|
|
239
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates');
|
|
240
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
241
|
+
return duration ? { duration: duration } : null;
|
|
242
|
+
},
|
|
243
|
+
newsletterAdminCount: async (jid) => {
|
|
244
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.xwa2_newsletter_admin_count);
|
|
245
|
+
return response.admin_count;
|
|
246
|
+
},
|
|
247
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
248
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.xwa2_newsletter_change_owner);
|
|
249
|
+
},
|
|
250
|
+
newsletterDemote: async (jid, userJid) => {
|
|
251
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote);
|
|
252
|
+
},
|
|
253
|
+
newsletterDelete: async (jid) => {
|
|
254
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2);
|
|
255
|
+
}
|
|
256
|
+
};
|
|
246
257
|
};
|
|
247
|
-
//=======================================================//
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export function makeSocket(config: any): {
|
|
2
|
+
type: string;
|
|
3
|
+
ws: WebSocketClient;
|
|
4
|
+
ev: {
|
|
5
|
+
process(handler: any): () => void;
|
|
6
|
+
emit(event: any, evData: any): any;
|
|
7
|
+
isBuffering(): boolean;
|
|
8
|
+
buffer: () => void;
|
|
9
|
+
flush: () => boolean;
|
|
10
|
+
createBufferedFunction(work: any): (...args: any[]) => Promise<any>;
|
|
11
|
+
on: (...args: any[]) => any;
|
|
12
|
+
off: (...args: any[]) => any;
|
|
13
|
+
removeAllListeners: (...args: any[]) => any;
|
|
14
|
+
destroy(): void;
|
|
15
|
+
};
|
|
16
|
+
authState: {
|
|
17
|
+
creds: any;
|
|
18
|
+
keys: {
|
|
19
|
+
get: (type: any, ids: any) => Promise<any>;
|
|
20
|
+
set: (data: any) => Promise<void>;
|
|
21
|
+
isInTransaction: () => boolean;
|
|
22
|
+
transaction: (work: any, key: any) => Promise<any>;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
signalRepository: any;
|
|
26
|
+
readonly user: any;
|
|
27
|
+
generateMessageTag: () => string;
|
|
28
|
+
query: (node: any, timeoutMs: any) => Promise<any>;
|
|
29
|
+
waitForMessage: (msgId: any, timeoutMs?: any) => Promise<any>;
|
|
30
|
+
waitForSocketOpen: () => Promise<void>;
|
|
31
|
+
sendRawMessage: (data: any) => Promise<void>;
|
|
32
|
+
sendNode: (frame: any) => Promise<void>;
|
|
33
|
+
logout: (msg: any) => Promise<void>;
|
|
34
|
+
end: (error: any) => Promise<void>;
|
|
35
|
+
registerSocketEndHandler: (handler: any) => void;
|
|
36
|
+
onUnexpectedError: (err: any, msg: any) => void;
|
|
37
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
38
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
39
|
+
digestKeyBundle: () => Promise<void>;
|
|
40
|
+
rotateSignedPreKey: () => Promise<void>;
|
|
41
|
+
requestPairingCode: (phoneNumber: any, customPairingCode: any) => Promise<any>;
|
|
42
|
+
updateServerTimeOffset: ({ attrs }: {
|
|
43
|
+
attrs: any;
|
|
44
|
+
}) => void;
|
|
45
|
+
sendUnifiedSession: () => Promise<void>;
|
|
46
|
+
wamBuffer: BinaryInfo;
|
|
47
|
+
/** Waits for the connection to WA to reach a state */
|
|
48
|
+
waitForConnectionUpdate: (check: any, timeoutMs: any) => Promise<void>;
|
|
49
|
+
sendWAMBuffer: (wamBuffer: any) => Promise<any>;
|
|
50
|
+
executeUSyncQuery: (usyncQuery: any) => Promise<any>;
|
|
51
|
+
onWhatsApp: (...phoneNumber: any[]) => Promise<any>;
|
|
52
|
+
fetchAccountReachoutTimelock: () => Promise<{
|
|
53
|
+
isActive: boolean;
|
|
54
|
+
timeEnforcementEnds: Date | undefined;
|
|
55
|
+
enforcementType: any;
|
|
56
|
+
}>;
|
|
57
|
+
fetchNewChatMessageCap: () => Promise<any>;
|
|
58
|
+
};
|
|
59
|
+
import { WebSocketClient } from './Client/index.js';
|
|
60
|
+
import { BinaryInfo } from '../WAM/BinaryInfo.js';
|
|
61
|
+
//# sourceMappingURL=socket.d.ts.map
|