@pontalabs/baileys 1.0.10 → 1.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/README.md +96 -85
- package/lib/Defaults/connection.js +39 -0
- package/lib/Defaults/constants.js +50 -0
- package/lib/Defaults/history.js +13 -0
- package/lib/Defaults/index.js +36 -151
- package/lib/Defaults/media.js +43 -0
- package/lib/Defaults/phonenumber-mcc.json +221 -221
- package/lib/Defaults/prefix.js +12 -0
- package/lib/Defaults/vialeys-version.json +7 -0
- package/lib/Signal/Group/ciphertext-message.js +10 -15
- package/lib/Signal/Group/group-session-builder.js +34 -60
- package/lib/Signal/Group/group_cipher.js +69 -76
- package/lib/Signal/Group/index.js +41 -60
- package/lib/Signal/Group/keyhelper.js +12 -57
- package/lib/Signal/Group/sender-chain-key.js +20 -33
- package/lib/Signal/Group/sender-key-distribution-message.js +43 -48
- package/lib/Signal/Group/sender-key-message.js +58 -53
- package/lib/Signal/Group/sender-key-name.js +21 -31
- package/lib/Signal/Group/sender-key-record.js +21 -34
- package/lib/Signal/Group/sender-key-state.js +59 -106
- package/lib/Signal/Group/sender-message-key.js +16 -21
- package/lib/Signal/libsignal.js +282 -203
- package/lib/Signal/lid-mapping.js +164 -184
- package/lib/Socket/Client/index.js +31 -22
- package/lib/Socket/Client/types.js +9 -15
- package/lib/Socket/Client/websocket.js +42 -37
- package/lib/Socket/business.js +212 -336
- package/lib/Socket/chats.js +696 -940
- package/lib/Socket/community.js +454 -369
- package/lib/Socket/groups.js +278 -280
- package/lib/Socket/index.js +9 -21
- package/lib/Socket/messages-recv.js +1027 -1570
- package/lib/Socket/messages-send.js +1180 -1136
- package/lib/Socket/mex.js +59 -0
- package/lib/Socket/newsletter.js +193 -251
- package/lib/Socket/socket.js +758 -898
- package/lib/Store/index.js +35 -24
- package/lib/Store/make-cache-manager-store.js +53 -66
- package/lib/Store/make-in-memory-store.js +319 -325
- package/lib/Store/make-ordered-dictionary.js +49 -57
- package/lib/Store/object-repository.js +10 -15
- package/lib/Types/Auth.js +2 -3
- package/lib/Types/Bussines.js +2 -3
- package/lib/Types/Call.js +2 -3
- package/lib/Types/Chat.js +10 -9
- package/lib/Types/Contact.js +2 -3
- package/lib/Types/Events.js +2 -3
- package/lib/Types/GroupMetadata.js +2 -3
- package/lib/Types/Label.js +6 -12
- package/lib/Types/LabelAssociation.js +4 -13
- package/lib/Types/Message.js +10 -18
- package/lib/Types/MexUpdates.js +15 -18
- package/lib/Types/Newsletter.js +26 -34
- package/lib/Types/Product.js +2 -3
- package/lib/Types/Signal.js +2 -3
- package/lib/Types/Socket.js +2 -3
- package/lib/Types/State.js +8 -13
- package/lib/Types/USync.js +2 -3
- package/lib/Types/index.js +49 -40
- package/lib/Utils/auth-utils.js +190 -495
- package/lib/Utils/browser-utils.js +29 -0
- package/lib/Utils/business.js +177 -199
- package/lib/Utils/chat-utils.js +711 -624
- package/lib/Utils/crypto.js +116 -161
- package/lib/Utils/decode-wa-message.js +225 -321
- package/lib/Utils/event-buffer.js +363 -405
- package/lib/Utils/generics.js +318 -472
- package/lib/Utils/history.js +72 -76
- package/lib/Utils/index.js +49 -41
- package/lib/Utils/link-preview.js +59 -103
- package/lib/Utils/logger.js +4 -7
- package/lib/Utils/lt-hash.js +29 -42
- package/lib/Utils/make-mutex.js +26 -42
- package/lib/Utils/message-retry-manager.js +134 -160
- package/lib/Utils/messages-media.js +665 -731
- package/lib/Utils/messages.js +518 -1
- package/lib/Utils/noise-handler.js +127 -125
- package/lib/Utils/pre-key-manager.js +86 -0
- package/lib/Utils/process-message.js +739 -351
- package/lib/Utils/signal.js +146 -129
- package/lib/Utils/use-multi-file-auth-state.js +68 -135
- package/lib/Utils/validate-connection.js +183 -142
- package/lib/Utils/vialeys-event-stream.js +41 -0
- package/lib/WABinary/constants.js +1281 -1289
- package/lib/WABinary/decode.js +145 -200
- package/lib/WABinary/encode.js +149 -202
- package/lib/WABinary/generic-utils.js +79 -97
- package/lib/WABinary/index.js +36 -25
- package/lib/WABinary/jid-utils.js +91 -123
- package/lib/WABinary/types.js +2 -3
- package/lib/WAM/BinaryInfo.js +8 -13
- package/lib/WAM/constants.js +16584 -11464
- package/lib/WAM/encode.js +117 -133
- package/lib/WAM/index.js +34 -23
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +62 -69
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +11 -25
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +32 -44
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +13 -23
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +24 -38
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +17 -31
- package/lib/WAUSync/Protocols/index.js +37 -26
- package/lib/WAUSync/USyncQuery.js +66 -66
- package/lib/WAUSync/USyncUser.js +13 -18
- package/lib/WAUSync/index.js +34 -23
- package/lib/index.js +95 -28
- package/package.json +4 -3
- package/lib/Defaults/baileys-version.json +0 -3
- package/lib/Signal/Group/queue-job.d.ts +0 -1
- package/lib/Signal/Group/queue-job.js +0 -57
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/baileys-event-stream.js +0 -70
- package/lib/Utils/signal-housekeeping.d.ts +0 -19
- package/lib/Utils/signal-housekeeping.js +0 -73
- package/lib/Utils/use-mongo-file-auth-state.d.ts +0 -6
- package/lib/Utils/use-mongo-file-auth-state.js +0 -84
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const { Boom: Boom } = require("@hapi/boom");
|
|
4
|
+
const {
|
|
5
|
+
getBinaryNodeChild: getBinaryNodeChild,
|
|
6
|
+
S_WHATSAPP_NET: S_WHATSAPP_NET,
|
|
7
|
+
} = require("../WABinary");
|
|
8
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) =>
|
|
9
|
+
query({
|
|
10
|
+
tag: "iq",
|
|
11
|
+
attrs: {
|
|
12
|
+
id: generateMessageTag(),
|
|
13
|
+
type: "get",
|
|
14
|
+
to: S_WHATSAPP_NET,
|
|
15
|
+
xmlns: "w:mex",
|
|
16
|
+
},
|
|
17
|
+
content: [
|
|
18
|
+
{
|
|
19
|
+
tag: "query",
|
|
20
|
+
attrs: { query_id: queryId },
|
|
21
|
+
content: Buffer.from(JSON.stringify({ variables: variables }), "utf-8"),
|
|
22
|
+
},
|
|
23
|
+
],
|
|
24
|
+
});
|
|
25
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
26
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag);
|
|
27
|
+
const child = getBinaryNodeChild(result, "result");
|
|
28
|
+
if (child?.content) {
|
|
29
|
+
const data = JSON.parse(child.content.toString());
|
|
30
|
+
if (data.errors && data.errors.length > 0) {
|
|
31
|
+
const errorMessages = data.errors
|
|
32
|
+
.map((err) => err.message || "Unknown error")
|
|
33
|
+
.join(", ");
|
|
34
|
+
const firstError = data.errors[0];
|
|
35
|
+
const errorCode = firstError.extensions?.error_code || 400;
|
|
36
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, {
|
|
37
|
+
statusCode: errorCode,
|
|
38
|
+
data: firstError,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const response =
|
|
42
|
+
(dataPath ? data?.data?.[dataPath] : data?.data) ??
|
|
43
|
+
data?.[dataPath] ??
|
|
44
|
+
data?.result ??
|
|
45
|
+
data
|
|
46
|
+
|
|
47
|
+
if (typeof response !== "undefined") {
|
|
48
|
+
return response
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const action = (dataPath || "").startsWith("xwa2_")
|
|
52
|
+
? dataPath.substring(5).replace(/_/g, " ")
|
|
53
|
+
: dataPath?.replace(/_/g, " ");
|
|
54
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, {
|
|
55
|
+
statusCode: 400,
|
|
56
|
+
data: result,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
module.exports = { executeWMexQuery: executeWMexQuery };
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -1,277 +1,219 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
const { QueryIds, XWAPaths } = require("../Types");
|
|
5
|
+
const { generateProfilePicture } = require("../Utils");
|
|
6
|
+
const { getBinaryNodeChild } = require("../WABinary");
|
|
7
|
+
const { makeGroupsSocket } = require("./groups");
|
|
8
|
+
const { executeWMexQuery: genericExecuteWMexQuery } = require("./mex");
|
|
4
9
|
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
10
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
11
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response;
|
|
12
|
+
return {
|
|
13
|
+
id,
|
|
14
|
+
owner: undefined,
|
|
15
|
+
name: thread.name.text,
|
|
16
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
17
|
+
description: thread.description.text,
|
|
18
|
+
invite: thread.invite,
|
|
19
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
20
|
+
verification: thread.verification,
|
|
21
|
+
picture: {
|
|
22
|
+
id: thread.picture.id,
|
|
23
|
+
directPath: thread.picture.direct_path,
|
|
24
|
+
},
|
|
25
|
+
mute_state: viewer.mute,
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const parseNewsletterMetadata = (result) => {
|
|
30
|
+
if (typeof result !== "object" || result === null) return null;
|
|
31
|
+
if ("id" in result && typeof result.id === "string") return result;
|
|
32
|
+
|
|
33
|
+
if (
|
|
34
|
+
"result" in result &&
|
|
35
|
+
typeof result.result === "object" &&
|
|
36
|
+
result.result !== null &&
|
|
37
|
+
"id" in result.result
|
|
38
|
+
) {
|
|
39
|
+
return result.result;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return null;
|
|
43
|
+
};
|
|
9
44
|
|
|
10
45
|
const makeNewsletterSocket = (config) => {
|
|
11
|
-
const
|
|
12
|
-
const {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
id: generateMessageTag(),
|
|
20
|
-
type,
|
|
21
|
-
xmlns: 'newsletter',
|
|
22
|
-
to: jid,
|
|
23
|
-
},
|
|
24
|
-
content
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
const newsletterWMexQuery = async (jid, queryId, content) => (query({
|
|
28
|
-
tag: 'iq',
|
|
29
|
-
attrs: {
|
|
30
|
-
id: generateMessageTag(),
|
|
31
|
-
type: 'get',
|
|
32
|
-
xmlns: 'w:mex',
|
|
33
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
34
|
-
},
|
|
35
|
-
content: [
|
|
46
|
+
const conn = makeGroupsSocket(config);
|
|
47
|
+
const { query, generateMessageTag } = conn;
|
|
48
|
+
|
|
49
|
+
const executeWMexQuery = (variables, queryId, dataPath) =>
|
|
50
|
+
genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag);
|
|
51
|
+
|
|
52
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
53
|
+
return executeWMexQuery(
|
|
36
54
|
{
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
content: encoder.encode(JSON.stringify({
|
|
40
|
-
variables: {
|
|
41
|
-
'newsletter_id': jid,
|
|
42
|
-
...content
|
|
43
|
-
}
|
|
44
|
-
}))
|
|
45
|
-
}
|
|
46
|
-
]
|
|
47
|
-
}))
|
|
48
|
-
|
|
49
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
50
|
-
let child
|
|
51
|
-
if (type === 'messages') {
|
|
52
|
-
child = WABinary_1.getBinaryNodeChild(node, 'messages')
|
|
53
|
-
} else {
|
|
54
|
-
const parent = WABinary_1.getBinaryNodeChild(node, 'message_updates')
|
|
55
|
-
child = WABinary_1.getBinaryNodeChild(parent, 'messages')
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
return await Promise.all(WABinary_1.getAllBinaryNodeChildren(child).map(async (messageNode) => {
|
|
59
|
-
messageNode.attrs.from = child?.attrs.jid
|
|
60
|
-
|
|
61
|
-
const views = parseInt(WABinary_1.getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0')
|
|
62
|
-
const reactionNode = WABinary_1.getBinaryNodeChild(messageNode, 'reactions')
|
|
63
|
-
const reactions = WABinary_1.getBinaryNodeChildren(reactionNode, 'reaction')
|
|
64
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }))
|
|
65
|
-
|
|
66
|
-
const data = {
|
|
67
|
-
'server_id': messageNode.attrs.server_id,
|
|
68
|
-
views,
|
|
69
|
-
reactions
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
if (type === 'messages') {
|
|
73
|
-
const { fullMessage: message, decrypt } = await Utils_1.decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger)
|
|
74
|
-
await decrypt()
|
|
75
|
-
data.message = message
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return data
|
|
79
|
-
}))
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const newsletterMetadata = async (type, key, role) => {
|
|
83
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
84
|
-
input: {
|
|
85
|
-
key,
|
|
86
|
-
type: type.toUpperCase(),
|
|
87
|
-
view_role: role || 'GUEST'
|
|
55
|
+
newsletter_id: jid,
|
|
56
|
+
updates: { ...updates, settings: null },
|
|
88
57
|
},
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return extractNewsletterMetadata(result)
|
|
95
|
-
}
|
|
96
|
-
|
|
58
|
+
QueryIds.UPDATE_METADATA,
|
|
59
|
+
XWAPaths.UPDATE
|
|
60
|
+
);
|
|
61
|
+
};
|
|
97
62
|
|
|
98
|
-
|
|
99
|
-
...
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
newsletterUpdateDescription: async (jid, description) => {
|
|
113
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
114
|
-
updates: { description: description || '', settings: null }
|
|
115
|
-
})
|
|
63
|
+
const self = {
|
|
64
|
+
...conn,
|
|
65
|
+
executeWMexQuery,
|
|
66
|
+
|
|
67
|
+
newsletterCreate: async (name, description) => {
|
|
68
|
+
const rawResponse = await executeWMexQuery(
|
|
69
|
+
{
|
|
70
|
+
input: { name, description: description ?? null },
|
|
71
|
+
},
|
|
72
|
+
QueryIds.CREATE,
|
|
73
|
+
XWAPaths.CREATE
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
return parseNewsletterCreateResponse(rawResponse);
|
|
116
77
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
78
|
+
|
|
79
|
+
newsletterUpdate,
|
|
80
|
+
|
|
81
|
+
newsletterSubscribers: async (jid) =>
|
|
82
|
+
executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.SUBSCRIBERS),
|
|
83
|
+
|
|
84
|
+
newsletterMetadata: async (type, key) => {
|
|
85
|
+
const result = await executeWMexQuery(
|
|
86
|
+
{
|
|
87
|
+
fetch_creation_time: true,
|
|
88
|
+
fetch_full_image: true,
|
|
89
|
+
fetch_viewer_metadata: true,
|
|
90
|
+
input: { key, type: type.toUpperCase() },
|
|
91
|
+
},
|
|
92
|
+
QueryIds.METADATA,
|
|
93
|
+
XWAPaths.METADATA
|
|
94
|
+
);
|
|
95
|
+
|
|
96
|
+
return parseNewsletterMetadata(result);
|
|
121
97
|
},
|
|
98
|
+
|
|
99
|
+
newsletterFollow: (jid) =>
|
|
100
|
+
executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.FOLLOW),
|
|
101
|
+
|
|
102
|
+
newsletterUnfollow: (jid) =>
|
|
103
|
+
executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.UNFOLLOW),
|
|
104
|
+
|
|
105
|
+
newsletterMute: (jid) =>
|
|
106
|
+
executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.MUTE_V2),
|
|
107
|
+
|
|
108
|
+
newsletterUnmute: (jid) =>
|
|
109
|
+
executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.UNMUTE_V2),
|
|
110
|
+
|
|
111
|
+
newsletterUpdateName: async (jid, name) => newsletterUpdate(jid, { name }),
|
|
112
|
+
|
|
113
|
+
newsletterUpdateDescription: async (jid, description) =>
|
|
114
|
+
newsletterUpdate(jid, { description }),
|
|
115
|
+
|
|
122
116
|
newsletterUpdatePicture: async (jid, content) => {
|
|
123
|
-
const { img } = await
|
|
124
|
-
|
|
125
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
126
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
127
|
-
})
|
|
128
|
-
},
|
|
129
|
-
newsletterRemovePicture: async (jid) => {
|
|
130
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
131
|
-
updates: { picture: '', settings: null }
|
|
132
|
-
})
|
|
117
|
+
const { img } = await generateProfilePicture(content);
|
|
118
|
+
return newsletterUpdate(jid, { picture: img.toString("base64") });
|
|
133
119
|
},
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.FOLLOW)
|
|
139
|
-
},
|
|
140
|
-
newsletterUnmute: async (jid) => {
|
|
141
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.UNMUTE)
|
|
142
|
-
},
|
|
143
|
-
newsletterMute: async (jid) => {
|
|
144
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.MUTE)
|
|
145
|
-
},
|
|
146
|
-
newsletterAction: async (jid, type) => {
|
|
147
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds[type.toUpperCase()])
|
|
148
|
-
},
|
|
149
|
-
newsletterCreate: async (name, description, picture) => {
|
|
120
|
+
|
|
121
|
+
newsletterRemovePicture: async (jid) => newsletterUpdate(jid, { picture: "" }),
|
|
122
|
+
|
|
123
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
150
124
|
await query({
|
|
151
|
-
tag:
|
|
125
|
+
tag: "message",
|
|
152
126
|
attrs: {
|
|
153
|
-
to:
|
|
154
|
-
|
|
127
|
+
to: jid,
|
|
128
|
+
...(reaction ? {} : { edit: "7" }),
|
|
129
|
+
type: "reaction",
|
|
130
|
+
server_id: serverId,
|
|
155
131
|
id: generateMessageTag(),
|
|
156
|
-
type: 'set'
|
|
157
132
|
},
|
|
158
133
|
content: [
|
|
159
134
|
{
|
|
160
|
-
tag:
|
|
161
|
-
attrs: {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
content: []
|
|
166
|
-
}
|
|
167
|
-
]
|
|
168
|
-
})
|
|
169
|
-
|
|
170
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.CREATE, {
|
|
171
|
-
input: {
|
|
172
|
-
name,
|
|
173
|
-
description: description || null,
|
|
174
|
-
picture: picture ? (await Utils_1.generateProfilePicture(picture)).img.toString('base64') : null,
|
|
175
|
-
settings: {
|
|
176
|
-
reaction_codes: {
|
|
177
|
-
value: 'ALL'
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
return extractNewsletterMetadata(result, true)
|
|
135
|
+
tag: "reaction",
|
|
136
|
+
attrs: reaction ? { code: reaction } : {},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
});
|
|
184
140
|
},
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
141
|
+
|
|
142
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
143
|
+
const messageUpdateAttrs = { count: count.toString() };
|
|
144
|
+
|
|
145
|
+
if (typeof since === "number") {
|
|
146
|
+
messageUpdateAttrs.since = since.toString();
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
if (after) {
|
|
150
|
+
messageUpdateAttrs.after = after.toString();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
return query({
|
|
154
|
+
tag: "iq",
|
|
155
|
+
attrs: {
|
|
156
|
+
id: generateMessageTag(),
|
|
157
|
+
type: "get",
|
|
158
|
+
xmlns: "newsletter",
|
|
159
|
+
to: jid,
|
|
160
|
+
},
|
|
161
|
+
content: [{ tag: "message_updates", attrs: messageUpdateAttrs }],
|
|
162
|
+
});
|
|
203
163
|
},
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
164
|
+
|
|
165
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
166
|
+
const result = await query({
|
|
167
|
+
tag: "iq",
|
|
168
|
+
attrs: {
|
|
169
|
+
id: generateMessageTag(),
|
|
170
|
+
type: "set",
|
|
171
|
+
xmlns: "newsletter",
|
|
172
|
+
to: jid,
|
|
173
|
+
},
|
|
174
|
+
content: [{ tag: "live_updates", attrs: {}, content: [] }],
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
const liveUpdatesNode = getBinaryNodeChild(result, "live_updates");
|
|
178
|
+
const duration = liveUpdatesNode?.attrs?.duration;
|
|
179
|
+
|
|
180
|
+
return duration ? { duration } : null;
|
|
208
181
|
},
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
182
|
+
|
|
183
|
+
newsletterAdminCount: async (jid) => {
|
|
184
|
+
const response = await executeWMexQuery(
|
|
185
|
+
{ newsletter_id: jid },
|
|
186
|
+
QueryIds.ADMIN_COUNT,
|
|
187
|
+
XWAPaths.ADMIN_COUNT
|
|
188
|
+
);
|
|
189
|
+
return response.admin_count;
|
|
213
190
|
},
|
|
214
|
-
|
|
215
|
-
|
|
191
|
+
|
|
192
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
193
|
+
await executeWMexQuery(
|
|
194
|
+
{ newsletter_id: jid, user_id: newOwnerJid },
|
|
195
|
+
QueryIds.CHANGE_OWNER,
|
|
196
|
+
XWAPaths.CHANGE_OWNER
|
|
197
|
+
);
|
|
216
198
|
},
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}]
|
|
225
|
-
})
|
|
199
|
+
|
|
200
|
+
newsletterDemote: async (jid, userJid) => {
|
|
201
|
+
await executeWMexQuery(
|
|
202
|
+
{ newsletter_id: jid, user_id: userJid },
|
|
203
|
+
QueryIds.DEMOTE,
|
|
204
|
+
XWAPaths.DEMOTE
|
|
205
|
+
);
|
|
226
206
|
},
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
tag: 'messages',
|
|
231
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: after?.toString() || '100' }
|
|
232
|
-
}
|
|
233
|
-
])
|
|
234
|
-
|
|
235
|
-
return await parseFetchedUpdates(result, 'messages')
|
|
207
|
+
|
|
208
|
+
newsletterDelete: async (jid) => {
|
|
209
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.DELETE_V2);
|
|
236
210
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
242
|
-
}
|
|
243
|
-
])
|
|
244
|
-
|
|
245
|
-
return await parseFetchedUpdates(result, 'updates')
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
251
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
252
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
253
|
-
|
|
254
|
-
const metadata = {
|
|
255
|
-
id: metadataPath?.id,
|
|
256
|
-
state: metadataPath?.state?.type,
|
|
257
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
258
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
259
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
260
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
261
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
262
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
263
|
-
handle: metadataPath?.thread_metadata?.handle,
|
|
264
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
265
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
266
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
267
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
268
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
269
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
270
|
-
}
|
|
271
|
-
return metadata
|
|
272
|
-
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
return self;
|
|
214
|
+
};
|
|
273
215
|
|
|
274
216
|
module.exports = {
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
}
|
|
217
|
+
makeNewsletterSocket,
|
|
218
|
+
parseNewsletterMetadata,
|
|
219
|
+
};
|