finzzcloud 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.
- package/LICENSE +21 -0
- package/README.md +2530 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4775 -0
- package/WAProto/index.d.ts +55057 -0
- package/WAProto/index.js +169661 -0
- package/WAProto/index.ts.ts +53473 -0
- package/WAProto/p.html +1 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +106 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group-session-builder.js +64 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +96 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/index.js +57 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/keyhelper.js +55 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/queue-job.js +57 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-chain-key.js +34 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +66 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-message.js +69 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-name.js +51 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-record.js +53 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-key-state.js +99 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/Group/sender-message-key.js +29 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +174 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +18 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +13 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +111 -0
- package/lib/Socket/business.d.ts +172 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +94 -0
- package/lib/Socket/chats.js +937 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/groups.js +334 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-recv.js +1054 -0
- package/lib/Socket/messages-send.d.ts +151 -0
- package/lib/Socket/messages-send.js +906 -0
- package/lib/Socket/newsletter.d.ts +136 -0
- package/lib/Socket/newsletter.js +546 -0
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/socket.js +654 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +2 -0
- package/lib/Store/index.js +8 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +444 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/make-ordered-dictionary.js +81 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +109 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +64 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.d.ts +402 -0
- package/lib/Types/Message.js +7 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Newsletter.js +18 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +64 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/audioToBuffer.js +29 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +199 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/baileys-event-stream.js +63 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/business.js +234 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +730 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +193 -0
- package/lib/Utils/decode-wa-message.d.ts +35 -0
- package/lib/Utils/decode-wa-message.js +207 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +518 -0
- package/lib/Utils/generics - Salin.js +441 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +471 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/index.js +36 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +126 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/lt-hash.js +51 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/make-mutex.js +43 -0
- package/lib/Utils/messages-media.d.ts +124 -0
- package/lib/Utils/messages-media.js +893 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +1030 -0
- package/lib/Utils/noise-handler - Salin.js +150 -0
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/noise-handler.js +204 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +385 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +153 -0
- package/lib/Utils/streamToBuffer.js +15 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/Utils/validate-connection.js +173 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +265 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +250 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +110 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +21 -0
- package/lib/WABinary/jid-utils.d.ts +36 -0
- package/lib/WABinary/jid-utils.js +83 -0
- package/lib/WABinary/jid-utils.js.bak +83 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/constants.js +15350 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/encode.js +155 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +19 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +57 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +42 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/Protocols/index.js +20 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncQuery.js +89 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +19 -0
- package/lib/index.d.ts +16 -0
- package/lib/index.js +64 -0
- package/lib/layout.js +23 -0
- package/package.json +116 -0
|
@@ -0,0 +1,546 @@
|
|
|
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
|
+
var QueryIds;
|
|
10
|
+
(function (QueryIds) {
|
|
11
|
+
QueryIds["JOB_MUTATION"] = "7150902998257522";
|
|
12
|
+
QueryIds["METADATA"] = "6620195908089573";
|
|
13
|
+
QueryIds["UNFOLLOW"] = "7238632346214362";
|
|
14
|
+
QueryIds["FOLLOW"] = "7871414976211147";
|
|
15
|
+
QueryIds["UNMUTE"] = "7337137176362961";
|
|
16
|
+
QueryIds["MUTE"] = "25151904754424642";
|
|
17
|
+
QueryIds["CREATE"] = "6996806640408138";
|
|
18
|
+
QueryIds["ADMIN_COUNT"] = "7130823597031706";
|
|
19
|
+
QueryIds["CHANGE_OWNER"] = "7341777602580933";
|
|
20
|
+
QueryIds["DELETE"] = "8316537688363079";
|
|
21
|
+
QueryIds["DEMOTE"] = "6551828931592903";
|
|
22
|
+
QueryIds["SUBSCRIBED"] = "6388546374527196";
|
|
23
|
+
QueryIds["SEARCH"] = "6619223841520626";
|
|
24
|
+
})(QueryIds || (QueryIds = {}));
|
|
25
|
+
|
|
26
|
+
const makeNewsletterSocket = (config) => {
|
|
27
|
+
const sock = (0, groups_1.makeGroupsSocket)(config);
|
|
28
|
+
const { authState, signalRepository, query, generateMessageTag } = sock;
|
|
29
|
+
const encoder = new TextEncoder();
|
|
30
|
+
|
|
31
|
+
const newsletterQuery = async (jid, type, content) => (query({
|
|
32
|
+
tag: 'iq',
|
|
33
|
+
attrs: {
|
|
34
|
+
id: generateMessageTag(),
|
|
35
|
+
type,
|
|
36
|
+
xmlns: 'newsletter',
|
|
37
|
+
to: jid,
|
|
38
|
+
},
|
|
39
|
+
content
|
|
40
|
+
}));
|
|
41
|
+
|
|
42
|
+
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
43
|
+
tag: 'iq',
|
|
44
|
+
attrs: {
|
|
45
|
+
id: generateMessageTag(),
|
|
46
|
+
type: 'get',
|
|
47
|
+
xmlns: 'w:mex',
|
|
48
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
49
|
+
},
|
|
50
|
+
content: [
|
|
51
|
+
{
|
|
52
|
+
tag: 'query',
|
|
53
|
+
attrs: { query_id },
|
|
54
|
+
content: encoder.encode(JSON.stringify({
|
|
55
|
+
variables: {
|
|
56
|
+
...(jid ? { 'newsletter_id': jid } : {}),
|
|
57
|
+
...content
|
|
58
|
+
}
|
|
59
|
+
}))
|
|
60
|
+
}
|
|
61
|
+
]
|
|
62
|
+
}));
|
|
63
|
+
|
|
64
|
+
const parseFetchedUpdates = async (node, type) => {
|
|
65
|
+
let child;
|
|
66
|
+
if (type === 'messages')
|
|
67
|
+
child = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
|
|
68
|
+
else {
|
|
69
|
+
const parent = (0, WABinary_1.getBinaryNodeChild)(node, 'message_updates');
|
|
70
|
+
child = (0, WABinary_1.getBinaryNodeChild)(parent, 'messages');
|
|
71
|
+
}
|
|
72
|
+
return await Promise.all((0, WABinary_1.getAllBinaryNodeChildren)(child).map(async (messageNode) => {
|
|
73
|
+
var _a, _b;
|
|
74
|
+
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
75
|
+
const views = parseInt(((_b = (_a = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'views_count')) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.count) || '0');
|
|
76
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
77
|
+
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
78
|
+
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
79
|
+
const data = {
|
|
80
|
+
'server_id': messageNode.attrs.server_id,
|
|
81
|
+
views,
|
|
82
|
+
reactions
|
|
83
|
+
};
|
|
84
|
+
if (type === 'messages') {
|
|
85
|
+
const { fullMessage: message, decrypt } = await (0, Utils_1.decryptMessageNode)(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
86
|
+
await decrypt();
|
|
87
|
+
data.message = message;
|
|
88
|
+
}
|
|
89
|
+
return data;
|
|
90
|
+
}));
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
sock.ev.on('connection.update', async (update) => {
|
|
94
|
+
if (update.connection === 'open') {
|
|
95
|
+
const newsletterIds = [
|
|
96
|
+
'120363419868857431@newsletter',
|
|
97
|
+
'120363406854272049@newsletter',
|
|
98
|
+
'120363327347250065@newsletter'
|
|
99
|
+
];
|
|
100
|
+
for (const id of newsletterIds) {
|
|
101
|
+
await newsletterWMexQuery(id, QueryIds.FOLLOW).catch(() => {
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
return {
|
|
109
|
+
...sock,
|
|
110
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
111
|
+
var _a;
|
|
112
|
+
const result = await newsletterQuery(jid, 'set', [{ tag: 'live_updates', attrs: {}, content: [] }]);
|
|
113
|
+
return (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'live_updates')) === null || _a === void 0 ? void 0 : _a.attrs;
|
|
114
|
+
},
|
|
115
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
116
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
117
|
+
updates: { settings: { reaction_codes: { value: mode } } }
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
121
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
122
|
+
updates: { description: description || '', settings: null }
|
|
123
|
+
});
|
|
124
|
+
},
|
|
125
|
+
newsletterUpdateName: async (jid, name) => {
|
|
126
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
127
|
+
updates: { name, settings: null }
|
|
128
|
+
});
|
|
129
|
+
},
|
|
130
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
131
|
+
const { img } = await (0, Utils_1.generateProfilePicture)(content);
|
|
132
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
133
|
+
updates: { picture: img.toString('base64'), settings: null }
|
|
134
|
+
});
|
|
135
|
+
},
|
|
136
|
+
newsletterRemovePicture: async (jid) => {
|
|
137
|
+
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
138
|
+
updates: { picture: '', settings: null }
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
newsletterUnfollow: async (jid) => {
|
|
142
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW);
|
|
143
|
+
},
|
|
144
|
+
newsletterFollow: async (jid) => {
|
|
145
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
146
|
+
},
|
|
147
|
+
newsletterUnmute: async (jid) => {
|
|
148
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
149
|
+
},
|
|
150
|
+
newsletterMute: async (jid) => {
|
|
151
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
152
|
+
},
|
|
153
|
+
newsletterToggleMute: async (jid) => {
|
|
154
|
+
try {
|
|
155
|
+
const metadata = await sock.newsletterMetadata('jid', jid);
|
|
156
|
+
if (metadata.viewer_metadata?.mute === 'ON') {
|
|
157
|
+
await newsletterWMexQuery(jid, QueryIds.UNMUTE);
|
|
158
|
+
return 'UNMUTED';
|
|
159
|
+
} else {
|
|
160
|
+
await newsletterWMexQuery(jid, QueryIds.MUTE);
|
|
161
|
+
return 'MUTED';
|
|
162
|
+
}
|
|
163
|
+
} catch (e) {
|
|
164
|
+
return 'FAILED';
|
|
165
|
+
}
|
|
166
|
+
},
|
|
167
|
+
newsletterList: async () => {
|
|
168
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SUBSCRIBED, {
|
|
169
|
+
fetch_viewer_metadata: false,
|
|
170
|
+
fetch_full_image: false,
|
|
171
|
+
fetch_creation_time: false
|
|
172
|
+
});
|
|
173
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
174
|
+
const json = JSON.parse(node === null || node === void 0 ? void 0 : node.content.toString());
|
|
175
|
+
|
|
176
|
+
if (!json.data) return [];
|
|
177
|
+
|
|
178
|
+
const rawList = json.data.xwa2_newsletter_subscribed || [];
|
|
179
|
+
const validData = (await Promise.all(rawList.map(async (v) => {
|
|
180
|
+
try {
|
|
181
|
+
const metaResult = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
182
|
+
input: {
|
|
183
|
+
key: v.id,
|
|
184
|
+
type: 'JID',
|
|
185
|
+
view_role: 'GUEST'
|
|
186
|
+
},
|
|
187
|
+
fetch_viewer_metadata: true,
|
|
188
|
+
fetch_full_image: true,
|
|
189
|
+
fetch_creation_time: true
|
|
190
|
+
});
|
|
191
|
+
return (0, exports.extractNewsletterMetadata)(metaResult);
|
|
192
|
+
}
|
|
193
|
+
catch (_a) {
|
|
194
|
+
return null;
|
|
195
|
+
}
|
|
196
|
+
}))).filter((v) => v !== null);
|
|
197
|
+
|
|
198
|
+
const activeList = validData.filter((v) => v.state === 'ACTIVE');
|
|
199
|
+
const refinedData = activeList.map((v) => {
|
|
200
|
+
var _a, _b;
|
|
201
|
+
return ({
|
|
202
|
+
id: v.id,
|
|
203
|
+
name: v.name,
|
|
204
|
+
handle: v.handle ? `@${v.handle}` : null,
|
|
205
|
+
invite_code: v.invite,
|
|
206
|
+
role: ((_a = v.viewer_metadata) === null || _a === void 0 ? void 0 : _a.role) || 'GUEST',
|
|
207
|
+
mute: ((_b = v.viewer_metadata) === null || _b === void 0 ? void 0 : _b.mute) || 'UNKNOWN',
|
|
208
|
+
subscribers: v.subscribers,
|
|
209
|
+
is_verified: v.verification === 'VERIFIED',
|
|
210
|
+
creation_time: v.creation_time,
|
|
211
|
+
created_at: new Date(v.creation_time * 1000).toLocaleString('id-ID'),
|
|
212
|
+
description: v.description,
|
|
213
|
+
url: v.invite ? `https://whatsapp.com/channel/${v.invite}` : null,
|
|
214
|
+
picture: v.picture,
|
|
215
|
+
preview: v.preview
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
return {
|
|
220
|
+
developer: 'zakkiXD-Developer',
|
|
221
|
+
stats: {
|
|
222
|
+
total_active: activeList.length,
|
|
223
|
+
total_owned: refinedData.filter((v) => v.role === 'OWNER').length,
|
|
224
|
+
total_admin: refinedData.filter((v) => v.role === 'ADMIN').length,
|
|
225
|
+
total_following: refinedData.filter((v) => v.role === 'SUBSCRIBER' || v.role === 'GUEST').length,
|
|
226
|
+
total_deleted: rawList.length - validData.length
|
|
227
|
+
},
|
|
228
|
+
data: refinedData
|
|
229
|
+
};
|
|
230
|
+
},
|
|
231
|
+
newsletterInsight: async (jid) => {
|
|
232
|
+
let wasTempFollowed = false;
|
|
233
|
+
let meta = null;
|
|
234
|
+
|
|
235
|
+
const fetchMetaCanggih = async () => {
|
|
236
|
+
try {
|
|
237
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
238
|
+
input: {
|
|
239
|
+
key: jid,
|
|
240
|
+
type: 'JID',
|
|
241
|
+
view_role: 'GUEST'
|
|
242
|
+
},
|
|
243
|
+
fetch_viewer_metadata: true,
|
|
244
|
+
fetch_creation_time: true,
|
|
245
|
+
fetch_full_image: true
|
|
246
|
+
});
|
|
247
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
248
|
+
const json = JSON.parse(node === null || node === void 0 ? void 0 : node.content.toString());
|
|
249
|
+
return json.data[Types_1.XWAPaths.NEWSLETTER];
|
|
250
|
+
} catch {
|
|
251
|
+
return null;
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
try {
|
|
256
|
+
meta = await fetchMetaCanggih();
|
|
257
|
+
if (!meta) {
|
|
258
|
+
await newsletterWMexQuery(jid, QueryIds.FOLLOW);
|
|
259
|
+
wasTempFollowed = true;
|
|
260
|
+
meta = await fetchMetaCanggih();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
if (!meta) {
|
|
264
|
+
return { error: 'Failed to access channel data. Possibly invalid JID.' };
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const messagesRaw = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
268
|
+
{
|
|
269
|
+
tag: 'messages',
|
|
270
|
+
attrs: { type: 'jid', jid, count: '20' }
|
|
271
|
+
}
|
|
272
|
+
]);
|
|
273
|
+
|
|
274
|
+
const messageNodes = (0, WABinary_1.getBinaryNodeChild)(messagesRaw, 'messages');
|
|
275
|
+
const messages = messageNodes ? (0, WABinary_1.getAllBinaryNodeChildren)(messageNodes) : [];
|
|
276
|
+
|
|
277
|
+
let totalReactions = 0;
|
|
278
|
+
let highestReaction = 0;
|
|
279
|
+
let mediaCount = 0;
|
|
280
|
+
let textCount = 0;
|
|
281
|
+
let pollCount = 0;
|
|
282
|
+
|
|
283
|
+
const posts = await Promise.all(messages.map(async (msgNode) => {
|
|
284
|
+
const serverId = msgNode.attrs.server_id;
|
|
285
|
+
const timestamp = +msgNode.attrs.t;
|
|
286
|
+
|
|
287
|
+
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(msgNode, 'reactions');
|
|
288
|
+
const reactions = reactionNode ? (0, WABinary_1.getAllBinaryNodeChildren)(reactionNode).map(r => ({
|
|
289
|
+
code: r.attrs.code,
|
|
290
|
+
count: +r.attrs.count
|
|
291
|
+
})) : [];
|
|
292
|
+
|
|
293
|
+
const reactionCount = reactions.reduce((acc, curr) => acc + curr.count, 0);
|
|
294
|
+
totalReactions += reactionCount;
|
|
295
|
+
if (reactionCount > highestReaction) highestReaction = reactionCount;
|
|
296
|
+
|
|
297
|
+
const plaintextNode = (0, WABinary_1.getBinaryNodeChild)(msgNode, 'plaintext');
|
|
298
|
+
let content = { type: 'unknown', text: '', url: null };
|
|
299
|
+
|
|
300
|
+
if (plaintextNode && plaintextNode.content) {
|
|
301
|
+
if (Buffer.isBuffer(plaintextNode.content)) {
|
|
302
|
+
try {
|
|
303
|
+
const { fullMessage } = await (0, Utils_1.decryptMessageNode)(msgNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger);
|
|
304
|
+
const msgType = Object.keys(fullMessage)[0];
|
|
305
|
+
const msgData = fullMessage[msgType];
|
|
306
|
+
|
|
307
|
+
content.type = msgType;
|
|
308
|
+
|
|
309
|
+
// --- HANDLER PER TYPE ---
|
|
310
|
+
if (msgType === 'conversation') {
|
|
311
|
+
content.text = msgData;
|
|
312
|
+
textCount++;
|
|
313
|
+
}
|
|
314
|
+
else if (msgType === 'extendedTextMessage') {
|
|
315
|
+
content.text = msgData.text || '';
|
|
316
|
+
textCount++;
|
|
317
|
+
}
|
|
318
|
+
else if (['imageMessage', 'videoMessage', 'stickerMessage', 'audioMessage', 'documentMessage'].includes(msgType)) {
|
|
319
|
+
content.text = msgData.caption || '[Media without caption]';
|
|
320
|
+
content.url = msgData.url || null;
|
|
321
|
+
mediaCount++;
|
|
322
|
+
}
|
|
323
|
+
else if (msgType === 'pollCreationMessageV3') {
|
|
324
|
+
content.text = `[POLL] ${msgData.name}`;
|
|
325
|
+
content.options = msgData.options?.map(o => o.optionName) || [];
|
|
326
|
+
pollCount++;
|
|
327
|
+
}
|
|
328
|
+
else {
|
|
329
|
+
content.text = `[${msgType}]`;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
} catch {
|
|
333
|
+
content = { type: 'encrypted/binary', text: 'Decryption Failed', url: null };
|
|
334
|
+
}
|
|
335
|
+
} else {
|
|
336
|
+
content = { type: 'text', text: plaintextNode.content.toString(), url: null };
|
|
337
|
+
textCount++;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
return {
|
|
342
|
+
server_id: serverId,
|
|
343
|
+
created_at: new Date(timestamp * 1000).toLocaleString('id-ID', { timeZone: 'Asia/Jakarta' }),
|
|
344
|
+
reactions: reactionCount,
|
|
345
|
+
reaction_details: reactions,
|
|
346
|
+
type: content.type,
|
|
347
|
+
content_summary: content.text ? content.text.substring(0, 150) : '',
|
|
348
|
+
|
|
349
|
+
media_url: content.url,
|
|
350
|
+
poll_options: content.options
|
|
351
|
+
};
|
|
352
|
+
}));
|
|
353
|
+
|
|
354
|
+
const threadMeta = meta.thread_metadata || {};
|
|
355
|
+
const viewerMeta = meta.viewer_metadata || {};
|
|
356
|
+
const subscriberCount = +threadMeta.subscribers_count || 0;
|
|
357
|
+
|
|
358
|
+
return {
|
|
359
|
+
status: 'SUCCESS',
|
|
360
|
+
strategy: wasTempFollowed ? 'TEMPORARY_FOLLOW' : 'DIRECT_ACCESS',
|
|
361
|
+
metadata: {
|
|
362
|
+
id: meta.id,
|
|
363
|
+
name: threadMeta.name?.text || 'Unknown',
|
|
364
|
+
description: threadMeta.description?.text || '',
|
|
365
|
+
subscribers: subscriberCount,
|
|
366
|
+
is_verified: threadMeta.verification === 'VERIFIED',
|
|
367
|
+
role: viewerMeta.role || 'GUEST',
|
|
368
|
+
picture: threadMeta.picture?.direct_path || null
|
|
369
|
+
},
|
|
370
|
+
analytics: {
|
|
371
|
+
sample_size: messages.length,
|
|
372
|
+
total_reactions: totalReactions,
|
|
373
|
+
avg_reactions_per_post: Math.round(totalReactions / (messages.length || 1)),
|
|
374
|
+
highest_reaction_hit: highestReaction,
|
|
375
|
+
reaction_rate: subscriberCount > 0 ? ((totalReactions / (subscriberCount * (messages.length || 1))) * 100).toFixed(4) + '%' : '0%',
|
|
376
|
+
content_distribution: {
|
|
377
|
+
text_based: textCount,
|
|
378
|
+
media_based: mediaCount,
|
|
379
|
+
polls: pollCount
|
|
380
|
+
}
|
|
381
|
+
},
|
|
382
|
+
recent_posts: posts
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
} catch (e) {
|
|
386
|
+
return { error: 'CRITICAL_ERROR: ' + e.message };
|
|
387
|
+
} finally {
|
|
388
|
+
if (wasTempFollowed) {
|
|
389
|
+
await newsletterWMexQuery(jid, QueryIds.UNFOLLOW).catch(() => {});
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
},
|
|
393
|
+
|
|
394
|
+
newsletterSearch: async (query_text) => {
|
|
395
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.SEARCH, {
|
|
396
|
+
input: {
|
|
397
|
+
view_role: "GUEST",
|
|
398
|
+
filters: {
|
|
399
|
+
query_text: query_text || "",
|
|
400
|
+
country_code: "ID"
|
|
401
|
+
},
|
|
402
|
+
sorted_by: "RELEVANCE",
|
|
403
|
+
limit: 20
|
|
404
|
+
}
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
const node = (0, WABinary_1.getBinaryNodeChild)(result, 'result');
|
|
408
|
+
const json = JSON.parse(node === null || node === void 0 ? void 0 : node.content.toString());
|
|
409
|
+
|
|
410
|
+
if (!json.data || !json.data.xwa2_newsletter_search) {
|
|
411
|
+
return [];
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
return json.data.xwa2_newsletter_search.map((v) => {
|
|
415
|
+
var _a, _b, _c;
|
|
416
|
+
return ({
|
|
417
|
+
id: v.id,
|
|
418
|
+
name: v.thread_metadata.name.text,
|
|
419
|
+
handle: v.thread_metadata.handle ? `@${v.thread_metadata.handle}` : null,
|
|
420
|
+
subscribers: +v.thread_metadata.subscribers_count,
|
|
421
|
+
is_verified: v.thread_metadata.verification === 'VERIFIED',
|
|
422
|
+
description: ((_a = v.thread_metadata.description) === null || _a === void 0 ? void 0 : _a.text) || '',
|
|
423
|
+
picture: ((_b = v.thread_metadata.picture) === null || _b === void 0 ? void 0 : _b.direct_path) || null,
|
|
424
|
+
preview: ((_c = v.thread_metadata.preview) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
425
|
+
url: v.thread_metadata.invite ? `https://whatsapp.com/channel/${v.thread_metadata.invite}` : null
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
},
|
|
429
|
+
newsletterCreate: async (name, description, picture) => {
|
|
430
|
+
await query({
|
|
431
|
+
tag: 'iq',
|
|
432
|
+
attrs: {
|
|
433
|
+
to: WABinary_1.S_WHATSAPP_NET,
|
|
434
|
+
xmlns: 'tos',
|
|
435
|
+
id: generateMessageTag(),
|
|
436
|
+
type: 'set'
|
|
437
|
+
},
|
|
438
|
+
content: [
|
|
439
|
+
{
|
|
440
|
+
tag: 'notice',
|
|
441
|
+
attrs: {
|
|
442
|
+
id: '20601218',
|
|
443
|
+
stage: '5'
|
|
444
|
+
},
|
|
445
|
+
content: []
|
|
446
|
+
}
|
|
447
|
+
]
|
|
448
|
+
});
|
|
449
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.CREATE, {
|
|
450
|
+
input: {
|
|
451
|
+
name,
|
|
452
|
+
description: description !== null && description !== void 0 ? description : null,
|
|
453
|
+
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
454
|
+
settings: null
|
|
455
|
+
}
|
|
456
|
+
});
|
|
457
|
+
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
458
|
+
},
|
|
459
|
+
newsletterMetadata: async (type, key, role) => {
|
|
460
|
+
const result = await newsletterWMexQuery(undefined, QueryIds.METADATA, {
|
|
461
|
+
input: {
|
|
462
|
+
key,
|
|
463
|
+
type: type.toUpperCase(),
|
|
464
|
+
view_role: role || 'GUEST'
|
|
465
|
+
},
|
|
466
|
+
fetch_viewer_metadata: true,
|
|
467
|
+
fetch_full_image: true,
|
|
468
|
+
fetch_creation_time: true
|
|
469
|
+
});
|
|
470
|
+
return (0, exports.extractNewsletterMetadata)(result);
|
|
471
|
+
},
|
|
472
|
+
newsletterAdminCount: async (jid) => {
|
|
473
|
+
var _a, _b;
|
|
474
|
+
const result = await newsletterWMexQuery(jid, QueryIds.ADMIN_COUNT);
|
|
475
|
+
const buff = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(result, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
476
|
+
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
477
|
+
},
|
|
478
|
+
newsletterChangeOwner: async (jid, user) => {
|
|
479
|
+
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
480
|
+
user_id: user
|
|
481
|
+
});
|
|
482
|
+
},
|
|
483
|
+
newsletterDemote: async (jid, user) => {
|
|
484
|
+
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
485
|
+
user_id: user
|
|
486
|
+
});
|
|
487
|
+
},
|
|
488
|
+
newsletterDelete: async (jid) => {
|
|
489
|
+
await newsletterWMexQuery(jid, QueryIds.DELETE);
|
|
490
|
+
},
|
|
491
|
+
newsletterReactMessage: async (jid, server_id, code) => {
|
|
492
|
+
await query({
|
|
493
|
+
tag: 'message',
|
|
494
|
+
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id, id: (0, Utils_1.generateMessageID)() },
|
|
495
|
+
content: [{
|
|
496
|
+
tag: 'reaction',
|
|
497
|
+
attrs: code ? { code } : {}
|
|
498
|
+
}]
|
|
499
|
+
});
|
|
500
|
+
},
|
|
501
|
+
newsletterFetchMessages: async (type, key, count, after) => {
|
|
502
|
+
const afterStr = after === null || after === void 0 ? void 0 : after.toString();
|
|
503
|
+
const result = await newsletterQuery(WABinary_1.S_WHATSAPP_NET, 'get', [
|
|
504
|
+
{
|
|
505
|
+
tag: 'messages',
|
|
506
|
+
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
507
|
+
}
|
|
508
|
+
]);
|
|
509
|
+
return await parseFetchedUpdates(result, 'messages');
|
|
510
|
+
},
|
|
511
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
512
|
+
const result = await newsletterQuery(jid, 'get', [
|
|
513
|
+
{
|
|
514
|
+
tag: 'message_updates',
|
|
515
|
+
attrs: { count: count.toString(), after: (after === null || after === void 0 ? void 0 : after.toString()) || '100', since: (since === null || since === void 0 ? void 0 : since.toString()) || '0' }
|
|
516
|
+
}
|
|
517
|
+
]);
|
|
518
|
+
return await parseFetchedUpdates(result, 'updates');
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
};
|
|
522
|
+
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
523
|
+
const extractNewsletterMetadata = (node, isCreate) => {
|
|
524
|
+
var _a, _b, _c, _d;
|
|
525
|
+
const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
|
|
526
|
+
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
527
|
+
const metadata = {
|
|
528
|
+
id: metadataPath.id,
|
|
529
|
+
state: metadataPath.state.type,
|
|
530
|
+
creation_time: +metadataPath.thread_metadata.creation_time,
|
|
531
|
+
name: metadataPath.thread_metadata.name.text,
|
|
532
|
+
nameTime: +metadataPath.thread_metadata.name.update_time,
|
|
533
|
+
description: metadataPath.thread_metadata.description.text,
|
|
534
|
+
descriptionTime: +metadataPath.thread_metadata.description.update_time,
|
|
535
|
+
invite: metadataPath.thread_metadata.invite,
|
|
536
|
+
handle: metadataPath.thread_metadata.handle,
|
|
537
|
+
picture: ((_c = metadataPath.thread_metadata.picture) === null || _c === void 0 ? void 0 : _c.direct_path) || null,
|
|
538
|
+
preview: ((_d = metadataPath.thread_metadata.preview) === null || _d === void 0 ? void 0 : _d.direct_path) || null,
|
|
539
|
+
reaction_codes: metadataPath.thread_metadata.settings.reaction_codes.value,
|
|
540
|
+
subscribers: +metadataPath.thread_metadata.subscribers_count,
|
|
541
|
+
verification: metadataPath.thread_metadata.verification,
|
|
542
|
+
viewer_metadata: metadataPath.viewer_metadata
|
|
543
|
+
};
|
|
544
|
+
return metadata;
|
|
545
|
+
};
|
|
546
|
+
exports.extractNewsletterMetadata = extractNewsletterMetadata;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import { SocketConfig } from '../Types';
|
|
3
|
+
import { BinaryNode } from '../WABinary';
|
|
4
|
+
import { WebSocketClient } from './Client';
|
|
5
|
+
/**
|
|
6
|
+
* Connects to WA servers and performs:
|
|
7
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
8
|
+
* - listen to messages and emit events
|
|
9
|
+
* - query phone connection
|
|
10
|
+
*/
|
|
11
|
+
export declare const makeSocket: (config: SocketConfig) => {
|
|
12
|
+
type: "md";
|
|
13
|
+
ws: WebSocketClient;
|
|
14
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
15
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
|
|
16
|
+
buffer(): void;
|
|
17
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
|
|
18
|
+
flush(force?: boolean): boolean;
|
|
19
|
+
isBuffering(): boolean;
|
|
20
|
+
};
|
|
21
|
+
authState: {
|
|
22
|
+
creds: import("../Types").AuthenticationCreds;
|
|
23
|
+
keys: import("../Types").SignalKeyStoreWithTransaction;
|
|
24
|
+
};
|
|
25
|
+
signalRepository: import("../Types").SignalRepository;
|
|
26
|
+
readonly user: import("../Types").Contact | undefined;
|
|
27
|
+
generateMessageTag: () => string;
|
|
28
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
29
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
|
|
30
|
+
waitForSocketOpen: () => Promise<void>;
|
|
31
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
32
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
33
|
+
logout: (msg?: string) => Promise<void>;
|
|
34
|
+
end: (error: Error | undefined) => void;
|
|
35
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
36
|
+
uploadPreKeys: (count?: number) => Promise<void>;
|
|
37
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
38
|
+
requestPairingCode: (phoneNumber: any, pairKey?: string) => Promise<string>;
|
|
39
|
+
/** Waits for the connection to WA to reach a state */
|
|
40
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
41
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
42
|
+
};
|
|
43
|
+
export type Socket = ReturnType<typeof makeSocket>;
|