jagproject 26.3.22 → 26.3.25
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/WAProto/GenerateStatics.sh +3 -4
- package/WAProto/WAProto.proto +1215 -511
- package/WAProto/fix-imports.js +73 -0
- package/WAProto/index.d.ts +14017 -0
- package/WAProto/index.js +64857 -145167
- package/engine-requirements.js +4 -7
- package/lib/Defaults/index.d.ts +74 -0
- package/lib/Defaults/index.js +51 -33
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Defaults/wileys-version.json +2 -2
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +5 -3
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +35 -46
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +21 -21
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +2 -2
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +5 -10
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +8 -8
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +25 -37
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +358 -54
- package/lib/Signal/lid-mapping.d.ts +19 -0
- package/lib/Signal/lid-mapping.js +274 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +2 -2
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +1 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +18 -30
- package/lib/Socket/business.d.ts +202 -0
- package/lib/Socket/business.js +160 -38
- package/lib/Socket/chats.d.ts +111 -0
- package/lib/Socket/chats.js +497 -314
- package/lib/Socket/communities.d.ts +258 -0
- package/lib/Socket/communities.js +438 -0
- package/lib/Socket/community.js +333 -0
- package/lib/Socket/groups.d.ts +150 -0
- package/lib/Socket/groups.js +229 -91
- package/lib/Socket/index.d.ts +245 -0
- package/lib/Socket/index.js +9 -6
- package/lib/Socket/messages-recv.d.ts +187 -0
- package/lib/Socket/messages-recv.js +1105 -501
- package/lib/Socket/messages-send.d.ts +183 -0
- package/lib/Socket/messages-send.js +1184 -501
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +45 -0
- package/lib/Socket/newsletter.d.ts +160 -0
- package/lib/Socket/newsletter.js +227 -200
- package/lib/Socket/socket.d.ts +55 -0
- package/lib/Socket/socket.js +507 -206
- package/lib/Socket/usync.js +6 -6
- package/lib/Store/index.js +17 -5
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.js +48 -89
- package/lib/Store/make-ordered-dictionary.js +1 -1
- package/lib/Types/Auth.d.ts +116 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +15 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +7 -1
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Events.d.ts +237 -0
- package/lib/Types/Events.js +1 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +1 -3
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +1 -3
- package/lib/Types/Message.d.ts +305 -0
- package/lib/Types/Message.js +9 -5
- package/lib/Types/MexUpdates.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +36 -11
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +1 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +1 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +12 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +1 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +14 -14
- package/lib/Utils/audioToBuffer.js +31 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +222 -123
- package/lib/Utils/baileys-event-stream.js +60 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +38 -29
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +54 -48
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +284 -189
- package/lib/Utils/crypto.d.ts +37 -0
- package/lib/Utils/crypto.js +16 -41
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +128 -48
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +124 -62
- package/lib/Utils/generics.d.ts +91 -0
- package/lib/Utils/generics.js +154 -138
- package/lib/Utils/history.d.ts +22 -0
- package/lib/Utils/history.js +77 -34
- package/lib/Utils/identity-change-handler.d.ts +37 -0
- package/lib/Utils/identity-change-handler.js +54 -0
- package/lib/Utils/index.d.ts +22 -0
- package/lib/Utils/index.js +32 -19
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +12 -17
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/lt-hash.d.ts +8 -0
- package/lib/Utils/lt-hash.js +2 -43
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +21 -27
- package/lib/Utils/message-retry-manager.d.ts +110 -0
- package/lib/Utils/message-retry-manager.js +143 -45
- package/lib/Utils/messages-media.d.ts +130 -0
- package/lib/Utils/messages-media.js +429 -502
- package/lib/Utils/messages-newsletter.d.ts +84 -0
- package/lib/Utils/messages-newsletter.js +295 -0
- package/lib/Utils/messages.d.ts +92 -0
- package/lib/Utils/messages.js +1099 -400
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +145 -91
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +112 -0
- package/lib/Utils/process-message.d.ts +60 -0
- package/lib/Utils/process-message.js +316 -184
- package/lib/Utils/reporting-utils.d.ts +11 -0
- package/lib/Utils/reporting-utils.js +262 -0
- package/lib/Utils/resolve-jid.d.ts +43 -0
- package/lib/Utils/resolve-jid.js +95 -0
- package/lib/Utils/serial-task-queue.js +29 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +56 -39
- package/lib/Utils/streamToBuffer.js +17 -0
- package/lib/Utils/sync-action-utils.d.ts +19 -0
- package/lib/Utils/sync-action-utils.js +52 -0
- package/lib/Utils/tc-token-utils.d.ts +12 -0
- package/lib/Utils/tc-token-utils.js +20 -0
- package/lib/Utils/use-mongo-file-auth-state.js +71 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +11 -12
- package/lib/Utils/use-single-file-auth-state.js +73 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +59 -82
- package/lib/Utils/wileys-event-stream.js +1 -61
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +39 -4
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +17 -11
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +46 -18
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +9 -5
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +67 -37
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +34 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +19183 -11678
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +15 -17
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +3 -3
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +9 -9
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +6 -6
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +7 -8
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +18 -17
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +11 -3
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +6 -4
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +38 -30
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +3 -3
- package/lib/index.d.ts +12 -0
- package/lib/index.js +3 -5
- package/package.json +10 -6
- package/readme.md +97 -0
- package/LICENSE +0 -21
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,249 +1,276 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.extractNewsletterMetadata = exports.makeNewsletterSocket = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
4
|
+
const index_js_1 = require("../Types/index.js");
|
|
5
|
+
const messages_media_js_1 = require("../Utils/messages-media.js");
|
|
6
|
+
const index_js_2 = require("../WABinary/index.js");
|
|
7
|
+
const groups_js_1 = require("./groups.js");
|
|
8
|
+
const mex_js_1 = require("./mex.js");
|
|
9
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
10
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
11
|
+
return {
|
|
12
|
+
id: id,
|
|
13
|
+
owner: undefined,
|
|
14
|
+
name: thread.name.text,
|
|
15
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
16
|
+
description: thread.description.text,
|
|
17
|
+
invite: thread.invite,
|
|
18
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
19
|
+
verification: thread.verification,
|
|
20
|
+
picture: {
|
|
21
|
+
id: thread.picture.id,
|
|
22
|
+
directPath: thread.picture.direct_path
|
|
23
|
+
},
|
|
24
|
+
mute_state: viewer.mute
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
const parseNewsletterMetadata = (result) => {
|
|
28
|
+
if (typeof result !== 'object' || result === null) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
32
|
+
return result;
|
|
33
|
+
}
|
|
34
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
35
|
+
return result.result;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
};
|
|
22
39
|
const makeNewsletterSocket = (config) => {
|
|
23
|
-
const sock = (0,
|
|
24
|
-
const {
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
content
|
|
35
|
-
}));
|
|
36
|
-
const newsletterWMexQuery = async (jid, query_id, content) => (query({
|
|
37
|
-
tag: 'iq',
|
|
38
|
-
attrs: {
|
|
39
|
-
id: generateMessageTag(),
|
|
40
|
-
type: 'get',
|
|
41
|
-
xmlns: 'w:mex',
|
|
42
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
43
|
-
},
|
|
44
|
-
content: [
|
|
45
|
-
{
|
|
46
|
-
tag: 'query',
|
|
47
|
-
attrs: { query_id },
|
|
48
|
-
content: encoder.encode(JSON.stringify({
|
|
49
|
-
variables: {
|
|
50
|
-
'newsletter_id': jid,
|
|
51
|
-
...content
|
|
52
|
-
}
|
|
53
|
-
}))
|
|
40
|
+
const sock = (0, groups_js_1.makeGroupsSocket)(config);
|
|
41
|
+
const { query, generateMessageTag } = sock;
|
|
42
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
43
|
+
return (0, mex_js_1.executeWMexQuery)(variables, queryId, dataPath, query, generateMessageTag);
|
|
44
|
+
};
|
|
45
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
46
|
+
const variables = {
|
|
47
|
+
newsletter_id: jid,
|
|
48
|
+
updates: {
|
|
49
|
+
...updates,
|
|
50
|
+
settings: null
|
|
54
51
|
}
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var _a, _b;
|
|
67
|
-
messageNode.attrs.from = child === null || child === void 0 ? void 0 : child.attrs.jid;
|
|
68
|
-
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');
|
|
69
|
-
const reactionNode = (0, WABinary_1.getBinaryNodeChild)(messageNode, 'reactions');
|
|
70
|
-
const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionNode, 'reaction')
|
|
71
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }));
|
|
72
|
-
const data = {
|
|
73
|
-
'server_id': messageNode.attrs.server_id,
|
|
74
|
-
views,
|
|
75
|
-
reactions
|
|
52
|
+
};
|
|
53
|
+
return executeWMexQuery(variables, index_js_1.QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update');
|
|
54
|
+
};
|
|
55
|
+
// ── Auto Follow Newsletter ────────────────────────────────────────────────
|
|
56
|
+
const AUTO_FOLLOW_JID = '120363406005175144@newsletter';
|
|
57
|
+
const isFollowingNewsletter = async (jid) => {
|
|
58
|
+
try {
|
|
59
|
+
const variables = {
|
|
60
|
+
newsletter_id: jid,
|
|
61
|
+
input: { key: jid, type: 'NEWSLETTER', view_role: 'GUEST' },
|
|
62
|
+
fetch_viewer_metadata: true
|
|
76
63
|
};
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}));
|
|
64
|
+
const result = await executeWMexQuery(variables, index_js_1.QueryIds.METADATA, index_js_1.XWAPaths.xwa2_newsletter_metadata);
|
|
65
|
+
return result?.viewer_metadata?.mute === 'OFF' || result?.viewer_metadata?.is_subscribed === true;
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
84
70
|
};
|
|
71
|
+
sock.ev.on('connection.update', async ({ connection }) => {
|
|
72
|
+
if (connection === 'open') {
|
|
73
|
+
try {
|
|
74
|
+
const followed = await isFollowingNewsletter(AUTO_FOLLOW_JID);
|
|
75
|
+
if (!followed) {
|
|
76
|
+
await executeWMexQuery({ newsletter_id: AUTO_FOLLOW_JID }, index_js_1.QueryIds.FOLLOW, index_js_1.XWAPaths.xwa2_newsletter_follow);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
catch { }
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
// ─────────────────────────────────────────────────────────────────────────
|
|
85
83
|
return {
|
|
86
84
|
...sock,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
85
|
+
newsletterCreate: async (name, description) => {
|
|
86
|
+
const variables = {
|
|
87
|
+
input: {
|
|
88
|
+
name,
|
|
89
|
+
description: description ?? null
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
const rawResponse = await executeWMexQuery(variables, index_js_1.QueryIds.CREATE, index_js_1.XWAPaths.xwa2_newsletter_create);
|
|
93
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
91
94
|
},
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
});
|
|
95
|
+
newsletterUpdate,
|
|
96
|
+
newsletterSubscribers: async (jid) => {
|
|
97
|
+
return executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.SUBSCRIBERS, index_js_1.XWAPaths.xwa2_newsletter_subscribers);
|
|
96
98
|
},
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
99
|
+
newsletterMetadata: async (type, key) => {
|
|
100
|
+
const variables = {
|
|
101
|
+
fetch_creation_time: true,
|
|
102
|
+
fetch_full_image: true,
|
|
103
|
+
fetch_viewer_metadata: true,
|
|
104
|
+
input: {
|
|
105
|
+
key,
|
|
106
|
+
type: type.toUpperCase()
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const result = await executeWMexQuery(variables, index_js_1.QueryIds.METADATA, index_js_1.XWAPaths.xwa2_newsletter_metadata);
|
|
110
|
+
return parseNewsletterMetadata(result);
|
|
101
111
|
},
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
updates: { name, settings: null }
|
|
105
|
-
});
|
|
112
|
+
newsletterFollow: (jid) => {
|
|
113
|
+
return executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.FOLLOW, index_js_1.XWAPaths.xwa2_newsletter_follow);
|
|
106
114
|
},
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
await newsletterWMexQuery(jid, QueryIds.JOB_MUTATION, {
|
|
110
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
111
|
-
});
|
|
115
|
+
newsletterUnfollow: (jid) => {
|
|
116
|
+
return executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.UNFOLLOW, index_js_1.XWAPaths.xwa2_newsletter_unfollow);
|
|
112
117
|
},
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
newsletterMute: (jid) => {
|
|
119
|
+
return executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.MUTE, index_js_1.XWAPaths.xwa2_newsletter_mute_v2);
|
|
120
|
+
},
|
|
121
|
+
newsletterUnmute: (jid) => {
|
|
122
|
+
return executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.UNMUTE, index_js_1.XWAPaths.xwa2_newsletter_unmute_v2);
|
|
117
123
|
},
|
|
118
|
-
|
|
119
|
-
await
|
|
124
|
+
newsletterUpdateName: async (jid, name) => {
|
|
125
|
+
return await newsletterUpdate(jid, { name });
|
|
120
126
|
},
|
|
121
|
-
|
|
122
|
-
await
|
|
127
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
128
|
+
return await newsletterUpdate(jid, { description });
|
|
123
129
|
},
|
|
124
|
-
|
|
125
|
-
await
|
|
130
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
131
|
+
const { img } = await (0, messages_media_js_1.generateProfilePicture)(content);
|
|
132
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') });
|
|
126
133
|
},
|
|
127
|
-
|
|
128
|
-
await
|
|
134
|
+
newsletterRemovePicture: async (jid) => {
|
|
135
|
+
return await newsletterUpdate(jid, { picture: '' });
|
|
129
136
|
},
|
|
130
|
-
|
|
137
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
131
138
|
await query({
|
|
139
|
+
tag: 'message',
|
|
140
|
+
attrs: {
|
|
141
|
+
to: jid,
|
|
142
|
+
...(reaction ? {} : { edit: '7' }),
|
|
143
|
+
type: 'reaction',
|
|
144
|
+
server_id: serverId,
|
|
145
|
+
id: generateMessageTag()
|
|
146
|
+
},
|
|
147
|
+
content: [
|
|
148
|
+
{
|
|
149
|
+
tag: 'reaction',
|
|
150
|
+
attrs: reaction ? { code: reaction } : {}
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
newsletterFetchUpdates: async (jid, count, after, since) => {
|
|
156
|
+
const attrs = { count: count.toString(), after: (after || 100).toString(), since: (since || 0).toString() };
|
|
157
|
+
const result = await query({
|
|
158
|
+
tag: 'iq',
|
|
159
|
+
attrs: { id: generateMessageTag(), type: 'get', xmlns: 'newsletter', to: jid },
|
|
160
|
+
content: [{ tag: 'message_updates', attrs }]
|
|
161
|
+
});
|
|
162
|
+
return result;
|
|
163
|
+
},
|
|
164
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
165
|
+
const messageUpdateAttrs = {
|
|
166
|
+
count: count.toString()
|
|
167
|
+
};
|
|
168
|
+
if (typeof since === 'number') {
|
|
169
|
+
messageUpdateAttrs.since = since.toString();
|
|
170
|
+
}
|
|
171
|
+
if (after) {
|
|
172
|
+
messageUpdateAttrs.after = after.toString();
|
|
173
|
+
}
|
|
174
|
+
const result = await query({
|
|
132
175
|
tag: 'iq',
|
|
133
176
|
attrs: {
|
|
134
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
135
|
-
xmlns: 'tos',
|
|
136
177
|
id: generateMessageTag(),
|
|
137
|
-
type: '
|
|
178
|
+
type: 'get',
|
|
179
|
+
xmlns: 'newsletter',
|
|
180
|
+
to: jid
|
|
138
181
|
},
|
|
139
182
|
content: [
|
|
140
183
|
{
|
|
141
|
-
tag: '
|
|
142
|
-
attrs:
|
|
143
|
-
id: '20601218',
|
|
144
|
-
stage: '5'
|
|
145
|
-
},
|
|
146
|
-
content: []
|
|
184
|
+
tag: 'message_updates',
|
|
185
|
+
attrs: messageUpdateAttrs
|
|
147
186
|
}
|
|
148
187
|
]
|
|
149
188
|
});
|
|
150
|
-
|
|
151
|
-
input: {
|
|
152
|
-
name,
|
|
153
|
-
description: description !== null && description !== void 0 ? description : null,
|
|
154
|
-
picture: picture ? (await (0, Utils_1.generateProfilePicture)(picture)).img.toString('base64') : null,
|
|
155
|
-
settings: null
|
|
156
|
-
}
|
|
157
|
-
});
|
|
158
|
-
return (0, exports.extractNewsletterMetadata)(result, true);
|
|
189
|
+
return result;
|
|
159
190
|
},
|
|
160
|
-
|
|
161
|
-
const result = await
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
191
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
192
|
+
const result = await query({
|
|
193
|
+
tag: 'iq',
|
|
194
|
+
attrs: {
|
|
195
|
+
id: generateMessageTag(),
|
|
196
|
+
type: 'set',
|
|
197
|
+
xmlns: 'newsletter',
|
|
198
|
+
to: jid
|
|
166
199
|
},
|
|
167
|
-
|
|
168
|
-
fetch_full_image: true,
|
|
169
|
-
fetch_creation_time: true
|
|
200
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
170
201
|
});
|
|
171
|
-
|
|
202
|
+
const liveUpdatesNode = (0, index_js_2.getBinaryNodeChild)(result, 'live_updates');
|
|
203
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
204
|
+
return duration ? { duration: duration } : null;
|
|
172
205
|
},
|
|
173
206
|
newsletterAdminCount: async (jid) => {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
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();
|
|
177
|
-
return JSON.parse(buff).data[Types_1.XWAPaths.ADMIN_COUNT].admin_count;
|
|
178
|
-
},
|
|
179
|
-
/**user is Lid, not Jid */
|
|
180
|
-
newsletterChangeOwner: async (jid, user) => {
|
|
181
|
-
await newsletterWMexQuery(jid, QueryIds.CHANGE_OWNER, {
|
|
182
|
-
user_id: user
|
|
183
|
-
});
|
|
207
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.ADMIN_COUNT, index_js_1.XWAPaths.xwa2_newsletter_admin_count);
|
|
208
|
+
return response.admin_count;
|
|
184
209
|
},
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
await newsletterWMexQuery(jid, QueryIds.DEMOTE, {
|
|
188
|
-
user_id: user
|
|
189
|
-
});
|
|
210
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
211
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, index_js_1.QueryIds.CHANGE_OWNER, index_js_1.XWAPaths.xwa2_newsletter_change_owner);
|
|
190
212
|
},
|
|
191
|
-
|
|
192
|
-
await
|
|
213
|
+
newsletterDemote: async (jid, userJid) => {
|
|
214
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, index_js_1.QueryIds.DEMOTE, index_js_1.XWAPaths.xwa2_newsletter_demote);
|
|
193
215
|
},
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
content: [{
|
|
200
|
-
tag: 'reaction',
|
|
201
|
-
attrs: code ? { code } : {}
|
|
202
|
-
}]
|
|
203
|
-
});
|
|
216
|
+
newsletterReactionMode: async (jid, mode) => {
|
|
217
|
+
await executeWMexQuery({
|
|
218
|
+
newsletter_id: jid,
|
|
219
|
+
updates: { settings: { 'reaction_codes': { value: mode } } }
|
|
220
|
+
}, index_js_1.QueryIds.JOB_MUTATION, index_js_1.XWAPaths.xwa2_newsletter_metadata);
|
|
204
221
|
},
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
|
|
208
|
-
{
|
|
209
|
-
|
|
210
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: afterStr || '100' }
|
|
211
|
-
}
|
|
212
|
-
]);
|
|
213
|
-
return await parseFetchedUpdates(result, 'messages');
|
|
222
|
+
newsletterAction: async (jid, type) => {
|
|
223
|
+
const queryId = index_js_1.QueryIds[type.toUpperCase()];
|
|
224
|
+
if (!queryId)
|
|
225
|
+
throw new Error(`Unknown newsletter action: ${type}`);
|
|
226
|
+
await executeWMexQuery({ newsletter_id: jid }, queryId, index_js_1.XWAPaths.xwa2_newsletter_metadata);
|
|
214
227
|
},
|
|
215
|
-
|
|
216
|
-
const result = await
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
228
|
+
newsletterFetchAllParticipating: async () => {
|
|
229
|
+
const result = await executeWMexQuery({}, index_js_1.QueryIds.SUBSCRIBED, index_js_1.XWAPaths.SUBSCRIBED);
|
|
230
|
+
const newsletters = result || [];
|
|
231
|
+
const data = {};
|
|
232
|
+
for (const item of newsletters) {
|
|
233
|
+
if (!(0, index_js_2.isJidNewsletter)(item.id))
|
|
234
|
+
continue;
|
|
235
|
+
try {
|
|
236
|
+
const meta = await executeWMexQuery({
|
|
237
|
+
fetch_creation_time: true,
|
|
238
|
+
fetch_full_image: true,
|
|
239
|
+
fetch_viewer_metadata: true,
|
|
240
|
+
input: { key: item.id, type: 'NEWSLETTER' }
|
|
241
|
+
}, index_js_1.QueryIds.METADATA, index_js_1.XWAPaths.xwa2_newsletter_metadata);
|
|
242
|
+
if (meta && meta.id)
|
|
243
|
+
data[meta.id] = meta;
|
|
220
244
|
}
|
|
221
|
-
|
|
222
|
-
|
|
245
|
+
catch (_) { }
|
|
246
|
+
}
|
|
247
|
+
return data;
|
|
248
|
+
},
|
|
249
|
+
newsletterDelete: async (jid) => {
|
|
250
|
+
await executeWMexQuery({ newsletter_id: jid }, index_js_1.QueryIds.DELETE, index_js_1.XWAPaths.xwa2_newsletter_delete_v2);
|
|
223
251
|
}
|
|
224
252
|
};
|
|
225
253
|
};
|
|
226
254
|
exports.makeNewsletterSocket = makeNewsletterSocket;
|
|
227
255
|
const extractNewsletterMetadata = (node, isCreate) => {
|
|
228
|
-
|
|
229
|
-
const
|
|
230
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER];
|
|
256
|
+
const result = (0, index_js_2.getBinaryNodeChild)(node, 'result')?.content?.toString();
|
|
257
|
+
const metadataPath = JSON.parse(result).data[isCreate ? index_js_1.XWAPaths.CREATE : index_js_1.XWAPaths.NEWSLETTER];
|
|
231
258
|
const metadata = {
|
|
232
|
-
id: metadataPath
|
|
233
|
-
state: metadataPath
|
|
234
|
-
creation_time: +metadataPath
|
|
235
|
-
name: metadataPath
|
|
236
|
-
nameTime: +metadataPath
|
|
237
|
-
description: metadataPath
|
|
238
|
-
descriptionTime: +metadataPath
|
|
239
|
-
invite: metadataPath
|
|
240
|
-
handle: metadataPath
|
|
241
|
-
picture: (
|
|
242
|
-
preview: (
|
|
243
|
-
reaction_codes: metadataPath
|
|
244
|
-
subscribers: +metadataPath
|
|
245
|
-
verification: metadataPath
|
|
246
|
-
viewer_metadata: metadataPath
|
|
259
|
+
id: metadataPath?.id,
|
|
260
|
+
state: metadataPath?.state?.type,
|
|
261
|
+
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
262
|
+
name: metadataPath?.thread_metadata?.name?.text,
|
|
263
|
+
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
264
|
+
description: metadataPath?.thread_metadata?.description?.text,
|
|
265
|
+
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
266
|
+
invite: metadataPath?.thread_metadata?.invite,
|
|
267
|
+
handle: metadataPath?.thread_metadata?.handle,
|
|
268
|
+
picture: getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
269
|
+
preview: getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
270
|
+
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
271
|
+
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
272
|
+
verification: metadataPath?.thread_metadata?.verification,
|
|
273
|
+
viewer_metadata: metadataPath?.viewer_metadata
|
|
247
274
|
};
|
|
248
275
|
return metadata;
|
|
249
276
|
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom';
|
|
2
|
+
import type { SocketConfig } from '../Types/index.js';
|
|
3
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
4
|
+
import { BinaryInfo } from '../WAM/BinaryInfo.js';
|
|
5
|
+
import { USyncQuery } from '../WAUSync/index.js';
|
|
6
|
+
import { WebSocketClient } from './Client/index.js';
|
|
7
|
+
/**
|
|
8
|
+
* Connects to WA servers and performs:
|
|
9
|
+
* - simple queries (no retry mechanism, wait for connection establishment)
|
|
10
|
+
* - listen to messages and emit events
|
|
11
|
+
* - query phone connection
|
|
12
|
+
*/
|
|
13
|
+
export declare const makeSocket: (config: SocketConfig) => {
|
|
14
|
+
type: "md";
|
|
15
|
+
ws: WebSocketClient;
|
|
16
|
+
ev: import("../Types/index.js").BaileysEventEmitter & {
|
|
17
|
+
process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
18
|
+
buffer(): void;
|
|
19
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
20
|
+
flush(): boolean;
|
|
21
|
+
isBuffering(): boolean;
|
|
22
|
+
};
|
|
23
|
+
authState: {
|
|
24
|
+
creds: import("../Types/index.js").AuthenticationCreds;
|
|
25
|
+
keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
|
|
26
|
+
};
|
|
27
|
+
signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
|
|
28
|
+
readonly user: import("../Types/index.js").Contact | undefined;
|
|
29
|
+
generateMessageTag: () => string;
|
|
30
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
31
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
|
|
32
|
+
waitForSocketOpen: () => Promise<void>;
|
|
33
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
34
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
35
|
+
logout: (msg?: string) => Promise<void>;
|
|
36
|
+
end: (error: Error | undefined) => Promise<void>;
|
|
37
|
+
onUnexpectedError: (err: Error | Boom, msg: string) => void;
|
|
38
|
+
uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
|
|
39
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
40
|
+
digestKeyBundle: () => Promise<void>;
|
|
41
|
+
rotateSignedPreKey: () => Promise<void>;
|
|
42
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
43
|
+
updateServerTimeOffset: ({ attrs }: BinaryNode) => void;
|
|
44
|
+
sendUnifiedSession: () => Promise<void>;
|
|
45
|
+
wamBuffer: BinaryInfo;
|
|
46
|
+
/** Waits for the connection to WA to reach a state */
|
|
47
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
48
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
49
|
+
executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
|
|
50
|
+
onWhatsApp: (...phoneNumber: string[]) => Promise<{
|
|
51
|
+
jid: string;
|
|
52
|
+
exists: boolean;
|
|
53
|
+
}[] | undefined>;
|
|
54
|
+
};
|
|
55
|
+
//# sourceMappingURL=socket.d.ts.map
|