@hansaka02/baileys 7.3.2 → 7.3.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/Defaults/baileys-version.json +2 -2
- package/lib/Defaults/connection.js +51 -0
- package/lib/Defaults/constants.js +74 -0
- package/lib/Defaults/history.js +19 -0
- package/lib/Defaults/index.js +36 -142
- package/lib/Defaults/media.js +48 -0
- package/lib/Defaults/prefix.js +18 -0
- package/lib/Signal/Group/group-session-builder.js +10 -42
- package/lib/Signal/Group/group_cipher.js +9 -6
- package/lib/Signal/Group/index.js +39 -53
- package/lib/Signal/Group/keyhelper.js +8 -41
- package/lib/Signal/Group/sender-chain-key.js +5 -18
- package/lib/Signal/Group/sender-key-distribution-message.js +7 -7
- package/lib/Signal/Group/sender-key-message.js +12 -8
- package/lib/Signal/Group/sender-key-record.js +7 -16
- package/lib/Signal/Group/sender-key-state.js +15 -61
- package/lib/Signal/Group/sender-message-key.js +2 -2
- package/lib/Signal/libsignal.js +237 -177
- package/lib/Signal/lid-mapping.js +128 -71
- package/lib/Socket/Client/types.js +2 -2
- package/lib/Socket/Client/websocket.js +25 -16
- package/lib/Socket/business.js +46 -33
- package/lib/Socket/chats.js +286 -170
- package/lib/Socket/community.js +215 -77
- package/lib/Socket/groups.js +77 -61
- package/lib/Socket/index.js +4 -4
- package/lib/Socket/messages-recv.js +629 -457
- package/lib/Socket/messages-send.js +645 -656
- package/lib/Socket/mex.js +61 -0
- package/lib/Socket/newsletter.js +166 -245
- package/lib/Socket/socket.js +396 -170
- package/lib/Store/index.js +27 -11
- package/lib/Store/make-cache-manager-store.js +14 -15
- package/lib/Store/make-in-memory-store.js +28 -24
- package/lib/Types/LabelAssociation.js +2 -2
- package/lib/Types/Message.js +6 -6
- package/lib/Types/MexUpdates.js +5 -5
- package/lib/Types/Newsletter.js +32 -25
- package/lib/Types/State.js +4 -4
- package/lib/Types/index.js +28 -12
- package/lib/Utils/auth-utils.js +212 -375
- package/lib/Utils/baileys-event-stream.js +68 -69
- package/lib/Utils/browser-utils.js +43 -0
- package/lib/Utils/business.js +63 -53
- package/lib/Utils/chat-utils.js +241 -106
- package/lib/Utils/crypto.js +25 -45
- package/lib/Utils/decode-wa-message.js +361 -311
- package/lib/Utils/event-buffer.js +97 -42
- package/lib/Utils/generics.js +90 -207
- package/lib/Utils/history.js +29 -27
- package/lib/Utils/index.js +28 -14
- package/lib/Utils/link-preview.js +24 -62
- package/lib/Utils/logger.js +5 -5
- package/lib/Utils/lt-hash.js +29 -23
- package/lib/Utils/make-mutex.js +26 -28
- package/lib/Utils/message-retry-manager.js +55 -7
- package/lib/Utils/messages-media.js +434 -247
- package/lib/Utils/messages.js +963 -917
- package/lib/Utils/noise-handler.js +60 -20
- package/lib/Utils/pre-key-manager.js +126 -0
- package/lib/Utils/process-message.js +216 -141
- package/lib/Utils/signal.js +75 -37
- package/lib/Utils/use-multi-file-auth-state.js +18 -22
- package/lib/Utils/validate-connection.js +96 -66
- package/lib/WABinary/constants.js +1268 -1268
- package/lib/WABinary/decode.js +62 -34
- package/lib/WABinary/encode.js +57 -36
- package/lib/WABinary/generic-utils.js +4 -4
- package/lib/WABinary/index.js +27 -11
- package/lib/WABinary/jid-utils.js +58 -11
- package/lib/WAM/constants.js +19064 -11563
- package/lib/WAM/encode.js +71 -14
- package/lib/WAM/index.js +27 -11
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +20 -16
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +7 -4
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +2 -2
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +0 -2
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +2 -2
- package/lib/WAUSync/Protocols/index.js +27 -11
- package/lib/WAUSync/USyncQuery.js +51 -28
- package/lib/WAUSync/index.js +27 -11
- package/lib/index.js +60 -31
- package/package.json +12 -17
- package/WAProto/AICommon/AICommon.d.ts +0 -11702
- package/WAProto/Adv/Adv.d.ts +0 -643
- package/WAProto/BotMetadata/BotMetadata.d.ts +0 -5654
- package/WAProto/Cert/Cert.d.ts +0 -613
- package/WAProto/ChatLockSettings/ChatLockSettings.d.ts +0 -476
- package/WAProto/CompanionReg/CompanionReg.d.ts +0 -1361
- package/WAProto/DeviceCapabilities/DeviceCapabilities.d.ts +0 -577
- package/WAProto/E2E/E2E.d.ts +0 -41724
- package/WAProto/Ephemeral/Ephemeral.d.ts +0 -114
- package/WAProto/HistorySync/HistorySync.d.ts +0 -51700
- package/WAProto/LidMigrationSyncPayload/LidMigrationSyncPayload.d.ts +0 -229
- package/WAProto/MdStorageChatRowOpaqueData/MdStorageChatRowOpaqueData.d.ts +0 -583
- package/WAProto/MdStorageMsgRowOpaqueData/MdStorageMsgRowOpaqueData.d.ts +0 -42897
- package/WAProto/MmsRetry/MmsRetry.d.ts +0 -243
- package/WAProto/Protocol/Protocol.d.ts +0 -270
- package/WAProto/Reporting/Reporting.d.ts +0 -371
- package/WAProto/ServerSync/ServerSync.d.ts +0 -1285
- package/WAProto/SignalLocalStorageProtocol/SignalLocalStorageProtocol.d.ts +0 -1868
- package/WAProto/SignalWhisperTextProtocol/SignalWhisperTextProtocol.d.ts +0 -767
- package/WAProto/StatusAttributions/StatusAttributions.d.ts +0 -1027
- package/WAProto/SyncAction/SyncAction.d.ts +0 -11193
- package/WAProto/UserPassword/UserPassword.d.ts +0 -363
- package/WAProto/VnameCert/VnameCert.d.ts +0 -821
- package/WAProto/Wa6/Wa6.d.ts +0 -2128
- package/WAProto/Web/Web.d.ts +0 -46383
- package/WAProto/index.d.ts +0 -55
- package/lib/Defaults/index.d.ts +0 -77
- package/lib/Signal/Group/ciphertext-message.d.ts +0 -9
- package/lib/Signal/Group/group-session-builder.d.ts +0 -17
- package/lib/Signal/Group/group_cipher.d.ts +0 -19
- package/lib/Signal/Group/index.d.ts +0 -11
- package/lib/Signal/Group/keyhelper.d.ts +0 -16
- package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
- package/lib/Signal/Group/sender-key-message.d.ts +0 -19
- package/lib/Signal/Group/sender-key-name.d.ts +0 -19
- package/lib/Signal/Group/sender-key-record.d.ts +0 -32
- package/lib/Signal/Group/sender-key-state.d.ts +0 -44
- package/lib/Signal/Group/sender-message-key.d.ts +0 -11
- package/lib/Signal/libsignal.d.ts +0 -8
- package/lib/Signal/lid-mapping.d.ts +0 -28
- package/lib/Socket/Client/index.d.ts +0 -2
- package/lib/Socket/Client/types.d.ts +0 -16
- package/lib/Socket/Client/websocket.d.ts +0 -13
- package/lib/Socket/business.d.ts +0 -187
- package/lib/Socket/chats.d.ts +0 -97
- package/lib/Socket/community.d.ts +0 -129
- package/lib/Socket/groups.d.ts +0 -129
- package/lib/Socket/index.d.ts +0 -191
- package/lib/Socket/messages-recv.d.ts +0 -174
- package/lib/Socket/messages-send.d.ts +0 -165
- package/lib/Socket/newsletter.d.ts +0 -145
- package/lib/Socket/socket.d.ts +0 -45
- package/lib/Socket/usync.d.ts +0 -37
- package/lib/Socket/usync.js +0 -83
- package/lib/Store/index.d.ts +0 -4
- package/lib/Store/make-cache-manager-store.d.ts +0 -14
- package/lib/Store/make-in-memory-store.d.ts +0 -123
- package/lib/Store/make-ordered-dictionary.d.ts +0 -12
- package/lib/Store/object-repository.d.ts +0 -10
- package/lib/Types/Auth.d.ts +0 -121
- package/lib/Types/Bussiness.d.ts +0 -28
- package/lib/Types/Call.d.ts +0 -14
- package/lib/Types/Chat.d.ts +0 -143
- package/lib/Types/Contact.d.ts +0 -23
- package/lib/Types/Events.d.ts +0 -226
- package/lib/Types/GroupMetadata.d.ts +0 -66
- package/lib/Types/Label.d.ts +0 -48
- package/lib/Types/LabelAssociation.d.ts +0 -35
- package/lib/Types/Message.d.ts +0 -484
- package/lib/Types/MexUpdates.d.ts +0 -9
- package/lib/Types/Newsletter.d.ts +0 -109
- package/lib/Types/Product.d.ts +0 -92
- package/lib/Types/Signal.d.ts +0 -98
- package/lib/Types/Socket.d.ts +0 -141
- package/lib/Types/State.d.ts +0 -41
- package/lib/Types/USync.d.ts +0 -26
- package/lib/Types/index.d.ts +0 -80
- package/lib/Utils/auth-utils.d.ts +0 -21
- package/lib/Utils/baileys-event-stream.d.ts +0 -18
- package/lib/Utils/business.d.ts +0 -29
- package/lib/Utils/chat-utils.d.ts +0 -82
- package/lib/Utils/crypto.d.ts +0 -56
- package/lib/Utils/decode-wa-message.d.ts +0 -53
- package/lib/Utils/event-buffer.d.ts +0 -39
- package/lib/Utils/generics.d.ts +0 -117
- package/lib/Utils/history.d.ts +0 -23
- package/lib/Utils/index.d.ts +0 -20
- package/lib/Utils/link-preview.d.ts +0 -23
- package/lib/Utils/logger.d.ts +0 -13
- package/lib/Utils/lt-hash.d.ts +0 -14
- package/lib/Utils/make-mutex.d.ts +0 -9
- package/lib/Utils/message-retry-manager.d.ts +0 -88
- package/lib/Utils/messages-media.d.ts +0 -135
- package/lib/Utils/messages.d.ts +0 -105
- package/lib/Utils/noise-handler.d.ts +0 -20
- package/lib/Utils/process-message.d.ts +0 -49
- package/lib/Utils/signal.d.ts +0 -42
- 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-multi-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.d.ts +0 -13
- package/lib/Utils/use-single-file-auth-state.js +0 -80
- package/lib/Utils/validate-connection.d.ts +0 -13
- package/lib/WABinary/constants.d.ts +0 -30
- package/lib/WABinary/decode.d.ts +0 -9
- package/lib/WABinary/encode.d.ts +0 -3
- package/lib/WABinary/generic-utils.d.ts +0 -28
- package/lib/WABinary/index.d.ts +0 -5
- package/lib/WABinary/jid-utils.d.ts +0 -58
- package/lib/WABinary/types.d.ts +0 -22
- package/lib/WAM/BinaryInfo.d.ts +0 -16
- package/lib/WAM/constants.d.ts +0 -47
- package/lib/WAM/encode.d.ts +0 -3
- package/lib/WAM/index.d.ts +0 -3
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +0 -28
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -26
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +0 -10
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -14
- package/lib/WAUSync/Protocols/index.d.ts +0 -6
- package/lib/WAUSync/USyncQuery.d.ts +0 -31
- package/lib/WAUSync/USyncUser.d.ts +0 -12
- package/lib/WAUSync/index.d.ts +0 -3
- package/lib/index.d.ts +0 -13
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
|
+
|
|
5
|
+
const { Boom } = require("@hapi/boom")
|
|
6
|
+
const {
|
|
7
|
+
getBinaryNodeChild,
|
|
8
|
+
S_WHATSAPP_NET
|
|
9
|
+
} = require("../WABinary")
|
|
10
|
+
|
|
11
|
+
const wMexQuery = (variables, queryId, query, generateMessageTag) => {
|
|
12
|
+
return query({
|
|
13
|
+
tag: 'iq',
|
|
14
|
+
attrs: {
|
|
15
|
+
id: generateMessageTag(),
|
|
16
|
+
type: 'get',
|
|
17
|
+
to: S_WHATSAPP_NET,
|
|
18
|
+
xmlns: 'w:mex'
|
|
19
|
+
},
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
tag: 'query',
|
|
23
|
+
attrs: { query_id: queryId },
|
|
24
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const executeWMexQuery = async (variables, queryId, dataPath, query, generateMessageTag) => {
|
|
31
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
32
|
+
const child = getBinaryNodeChild(result, 'result')
|
|
33
|
+
|
|
34
|
+
if (child?.content) {
|
|
35
|
+
const data = JSON.parse(child.content.toString())
|
|
36
|
+
|
|
37
|
+
if (data.errors && data.errors.length > 0) {
|
|
38
|
+
const errorMessages = data.errors.map((err) => err.message || 'Unknown error').join(', ')
|
|
39
|
+
const firstError = data.errors[0]
|
|
40
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
41
|
+
|
|
42
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
46
|
+
|
|
47
|
+
if (typeof response !== 'undefined') {
|
|
48
|
+
return response
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
53
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
54
|
+
: dataPath?.replace(/_/g, ' ')
|
|
55
|
+
|
|
56
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
executeWMexQuery
|
|
61
|
+
}
|
package/lib/Socket/newsletter.js
CHANGED
|
@@ -2,294 +2,215 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true })
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
const {
|
|
6
|
+
QueryIds,
|
|
7
|
+
XWAPaths
|
|
8
|
+
} = require("../Types")
|
|
9
|
+
const { generateProfilePicture } = require("../Utils")
|
|
10
|
+
const { getBinaryNodeChild } = require("../WABinary")
|
|
11
|
+
const { makeGroupsSocket } = require("./groups")
|
|
12
|
+
const { executeWMexQuery: genericExecuteWMexQuery } = require("./mex")
|
|
13
|
+
|
|
14
|
+
const parseNewsletterCreateResponse = (response) => {
|
|
15
|
+
const { id, thread_metadata: thread, viewer_metadata: viewer } = response
|
|
16
|
+
return {
|
|
17
|
+
id: id,
|
|
18
|
+
owner: undefined,
|
|
19
|
+
name: thread.name.text,
|
|
20
|
+
creation_time: parseInt(thread.creation_time, 10),
|
|
21
|
+
description: thread.description.text,
|
|
22
|
+
invite: thread.invite,
|
|
23
|
+
subscribers: parseInt(thread.subscribers_count, 10),
|
|
24
|
+
verification: thread.verification,
|
|
25
|
+
picture: {
|
|
26
|
+
id: thread.picture.id,
|
|
27
|
+
directPath: thread.picture.direct_path
|
|
28
|
+
},
|
|
29
|
+
mute_state: viewer.mute
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const parseNewsletterMetadata = (result) => {
|
|
34
|
+
if (typeof result !== 'object' || result === null) {
|
|
35
|
+
return null
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
43
|
+
return result.result
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return null
|
|
47
|
+
}
|
|
9
48
|
|
|
10
49
|
const makeNewsletterSocket = (config) => {
|
|
11
|
-
const suki =
|
|
12
|
-
const {
|
|
13
|
-
|
|
50
|
+
const suki = makeGroupsSocket(config)
|
|
51
|
+
const {
|
|
52
|
+
query,
|
|
53
|
+
generateMessageTag
|
|
54
|
+
} = suki
|
|
14
55
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
id: generateMessageTag(),
|
|
19
|
-
type,
|
|
20
|
-
xmlns: 'newsletter',
|
|
21
|
-
to: jid,
|
|
22
|
-
},
|
|
23
|
-
content
|
|
24
|
-
}))
|
|
56
|
+
const executeWMexQuery = (variables, queryId, dataPath) => {
|
|
57
|
+
return genericExecuteWMexQuery(variables, queryId, dataPath, query, generateMessageTag)
|
|
58
|
+
}
|
|
25
59
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
to: WABinary_1.S_WHATSAPP_NET,
|
|
33
|
-
},
|
|
34
|
-
content: [
|
|
35
|
-
{
|
|
36
|
-
tag: 'query',
|
|
37
|
-
attrs: { 'query_id': queryId },
|
|
38
|
-
content: encoder.encode(JSON.stringify({
|
|
39
|
-
variables: {
|
|
40
|
-
'newsletter_id': jid,
|
|
41
|
-
...content
|
|
42
|
-
}
|
|
43
|
-
}))
|
|
60
|
+
const newsletterUpdate = async (jid, updates) => {
|
|
61
|
+
const variables = {
|
|
62
|
+
newsletter_id: jid,
|
|
63
|
+
updates: {
|
|
64
|
+
...updates,
|
|
65
|
+
settings: null
|
|
44
66
|
}
|
|
45
|
-
]
|
|
46
|
-
}))
|
|
47
|
-
|
|
48
|
-
const parseFetchedUpdates = async (node, type) => {
|
|
49
|
-
let child
|
|
50
|
-
if (type === 'messages') {
|
|
51
|
-
child = WABinary_1.getBinaryNodeChild(node, 'messages')
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
else {
|
|
55
|
-
const parent = WABinary_1.getBinaryNodeChild(node, 'message_updates')
|
|
56
|
-
child = WABinary_1.getBinaryNodeChild(parent, 'messages')
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
return
|
|
60
|
-
messageNode.attrs.from = child?.attrs.jid
|
|
61
|
-
|
|
62
|
-
const views = parseInt(WABinary_1.getBinaryNodeChild(messageNode, 'views_count')?.attrs?.count || '0')
|
|
63
|
-
const reactionNode = WABinary_1.getBinaryNodeChild(messageNode, 'reactions')
|
|
64
|
-
const reactions = WABinary_1.getBinaryNodeChildren(reactionNode, 'reaction')
|
|
65
|
-
.map(({ attrs }) => ({ count: +attrs.count, code: attrs.code }))
|
|
66
|
-
|
|
67
|
-
const data = {
|
|
68
|
-
'server_id': messageNode.attrs.server_id,
|
|
69
|
-
views,
|
|
70
|
-
reactions
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (type === 'messages') {
|
|
74
|
-
const { fullMessage: message, decrypt } = await Utils_1.decryptMessageNode(messageNode, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, config.logger)
|
|
75
|
-
await decrypt()
|
|
76
|
-
data.message = message
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return data
|
|
80
|
-
}))
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
const newsletterMetadata = async (type, key, role) => {
|
|
84
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
|
|
85
|
-
input: {
|
|
86
|
-
key,
|
|
87
|
-
type: type.toUpperCase(),
|
|
88
|
-
view_role: role || 'GUEST'
|
|
89
|
-
},
|
|
90
|
-
fetch_viewer_metadata: true,
|
|
91
|
-
fetch_full_image: true,
|
|
92
|
-
fetch_creation_time: true
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
return extractNewsletterMetadata(result)
|
|
69
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, XWAPaths.UPDATE)
|
|
96
70
|
}
|
|
97
71
|
|
|
98
72
|
return {
|
|
99
73
|
...suki,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
74
|
+
executeWMexQuery,
|
|
75
|
+
newsletterCreate: async (name, description) => {
|
|
76
|
+
const variables = {
|
|
77
|
+
input: {
|
|
78
|
+
name,
|
|
79
|
+
description: description ?? null
|
|
80
|
+
}
|
|
81
|
+
}
|
|
104
82
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
83
|
+
const rawResponse = await executeWMexQuery(variables, QueryIds.CREATE, XWAPaths.CREATE)
|
|
84
|
+
|
|
85
|
+
return parseNewsletterCreateResponse(rawResponse)
|
|
86
|
+
},
|
|
87
|
+
newsletterUpdate,
|
|
88
|
+
newsletterSubscribers: async (jid) => {
|
|
89
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.SUBSCRIBERS, XWAPaths.SUBSCRIBERS)
|
|
90
|
+
},
|
|
91
|
+
newsletterMetadata: async (type, key) => {
|
|
92
|
+
const variables = {
|
|
93
|
+
fetch_creation_time: true,
|
|
94
|
+
fetch_full_image: true,
|
|
95
|
+
fetch_viewer_metadata: true,
|
|
96
|
+
input: {
|
|
97
|
+
key,
|
|
98
|
+
type: type.toUpperCase()
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const result = await executeWMexQuery(variables, QueryIds.METADATA, XWAPaths.METADATA)
|
|
103
|
+
|
|
104
|
+
return parseNewsletterMetadata(result)
|
|
116
105
|
},
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
updates: { name, settings: null }
|
|
120
|
-
})
|
|
106
|
+
newsletterFollow: (jid) => {
|
|
107
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.FOLLOW)
|
|
121
108
|
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.JOB_MUTATION, {
|
|
126
|
-
updates: { picture: img.toString('base64'), settings: null }
|
|
127
|
-
})
|
|
109
|
+
newsletterUnfollow: (jid) => {
|
|
110
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.UNFOLLOW)
|
|
128
111
|
},
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
updates: { picture: '', settings: null }
|
|
132
|
-
})
|
|
112
|
+
newsletterMute: (jid) => {
|
|
113
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.MUTE_V2)
|
|
133
114
|
},
|
|
134
|
-
|
|
135
|
-
|
|
115
|
+
newsletterUnmute: (jid) => {
|
|
116
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.UNMUTE_V2)
|
|
136
117
|
},
|
|
137
|
-
|
|
138
|
-
await
|
|
118
|
+
newsletterUpdateName: async (jid, name) => {
|
|
119
|
+
return await newsletterUpdate(jid, { name })
|
|
139
120
|
},
|
|
140
|
-
|
|
141
|
-
await
|
|
121
|
+
newsletterUpdateDescription: async (jid, description) => {
|
|
122
|
+
return await newsletterUpdate(jid, { description })
|
|
142
123
|
},
|
|
143
|
-
|
|
144
|
-
await
|
|
124
|
+
newsletterUpdatePicture: async (jid, content) => {
|
|
125
|
+
const { img } = await generateProfilePicture(content)
|
|
126
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') })
|
|
145
127
|
},
|
|
146
|
-
|
|
147
|
-
await
|
|
128
|
+
newsletterRemovePicture: async (jid) => {
|
|
129
|
+
return await newsletterUpdate(jid, { picture: '' })
|
|
148
130
|
},
|
|
149
|
-
|
|
150
|
-
//TODO: Implement TOS system wide for Meta AI, communities, and here etc.
|
|
151
|
-
/**tos query */
|
|
131
|
+
newsletterReactMessage: async (jid, serverId, reaction) => {
|
|
152
132
|
await query({
|
|
153
|
-
tag: '
|
|
133
|
+
tag: 'message',
|
|
154
134
|
attrs: {
|
|
155
|
-
to:
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
135
|
+
to: jid,
|
|
136
|
+
...(reaction ? {} : { edit: '7' }),
|
|
137
|
+
type: 'reaction',
|
|
138
|
+
server_id: serverId,
|
|
139
|
+
id: generateMessageTag()
|
|
159
140
|
},
|
|
160
141
|
content: [
|
|
161
142
|
{
|
|
162
|
-
tag: '
|
|
163
|
-
attrs: {
|
|
164
|
-
id: '20601218',
|
|
165
|
-
stage: '5'
|
|
166
|
-
},
|
|
167
|
-
content: []
|
|
143
|
+
tag: 'reaction',
|
|
144
|
+
attrs: reaction ? { code: reaction } : {}
|
|
168
145
|
}
|
|
169
146
|
]
|
|
170
147
|
})
|
|
148
|
+
},
|
|
149
|
+
newsletterFetchMessages: async (jid, count, since, after) => {
|
|
150
|
+
const messageUpdateAttrs = {
|
|
151
|
+
count: count.toString()
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (typeof since === 'number') {
|
|
155
|
+
messageUpdateAttrs.since = since.toString()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
if (after) {
|
|
159
|
+
messageUpdateAttrs.after = after.toString()
|
|
160
|
+
}
|
|
171
161
|
|
|
172
|
-
const result = await
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
162
|
+
const result = await query({
|
|
163
|
+
tag: 'iq',
|
|
164
|
+
attrs: {
|
|
165
|
+
id: generateMessageTag(),
|
|
166
|
+
type: 'get',
|
|
167
|
+
xmlns: 'newsletter',
|
|
168
|
+
to: jid
|
|
169
|
+
},
|
|
170
|
+
content: [
|
|
171
|
+
{
|
|
172
|
+
tag: 'message_updates',
|
|
173
|
+
attrs: messageUpdateAttrs
|
|
181
174
|
}
|
|
182
|
-
|
|
175
|
+
]
|
|
183
176
|
})
|
|
184
177
|
|
|
185
|
-
return
|
|
186
|
-
},
|
|
187
|
-
newsletterMetadata,
|
|
188
|
-
newsletterFetchAllParticipating: async () => {
|
|
189
|
-
const data = {}
|
|
190
|
-
|
|
191
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.SUBSCRIBED)
|
|
192
|
-
const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
193
|
-
const newsletters = child.data[Types_1.XWAPaths.SUBSCRIBED]
|
|
194
|
-
|
|
195
|
-
for (const i of newsletters) {
|
|
196
|
-
if (!WABinary_1.isJidNewsletter(i.id)) {
|
|
197
|
-
continue
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const metadata = await newsletterMetadata('JID', i.id)
|
|
201
|
-
data[metadata.id] = metadata
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
return data
|
|
205
|
-
},
|
|
206
|
-
newsletterFetchAllParticipating: async () => {
|
|
207
|
-
const result = await newsletterWMexQuery(undefined, Types_1.QueryIds.SUBSCRIBED)
|
|
208
|
-
const child = JSON.parse(WABinary_1.getBinaryNodeChild(result, 'result')?.content?.toString())
|
|
209
|
-
const newsletters = child.data[Types_1.XWAPaths.SUBSCRIBED] || []
|
|
210
|
-
|
|
211
|
-
const data = {}
|
|
212
|
-
|
|
213
|
-
for (const { id } of newsletters) {
|
|
214
|
-
if (!WABinary_1.isJidNewsletter(id)) continue
|
|
215
|
-
const metadata = await newsletterMetadata('JID', id)
|
|
216
|
-
data[metadata.id] = metadata
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
return data
|
|
220
|
-
},
|
|
221
|
-
newsletterChangeOwner: async (jid, userLid) => {
|
|
222
|
-
await newsletterWMexQuery(jid, Types_1.QueryIds.CHANGE_OWNER, {
|
|
223
|
-
user_id: userLid
|
|
224
|
-
})
|
|
178
|
+
return result
|
|
225
179
|
},
|
|
226
|
-
|
|
227
|
-
await
|
|
228
|
-
|
|
180
|
+
subscribeNewsletterUpdates: async (jid) => {
|
|
181
|
+
const result = await query({
|
|
182
|
+
tag: 'iq',
|
|
183
|
+
attrs: {
|
|
184
|
+
id: generateMessageTag(),
|
|
185
|
+
type: 'set',
|
|
186
|
+
xmlns: 'newsletter',
|
|
187
|
+
to: jid
|
|
188
|
+
},
|
|
189
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
229
190
|
})
|
|
191
|
+
|
|
192
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates')
|
|
193
|
+
const duration = liveUpdatesNode?.attrs?.duration
|
|
194
|
+
|
|
195
|
+
return duration ? { duration: duration } : null
|
|
230
196
|
},
|
|
231
|
-
|
|
232
|
-
await
|
|
197
|
+
newsletterAdminCount: async (jid) => {
|
|
198
|
+
const response = await executeWMexQuery({ newsletter_id: jid }, QueryIds.ADMIN_COUNT, XWAPaths.ADMIN_COUNT)
|
|
199
|
+
return response.admin_count
|
|
233
200
|
},
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
await query({
|
|
237
|
-
tag: 'message',
|
|
238
|
-
attrs: { to: jid, ...(!code ? { edit: '7' } : {}), type: 'reaction', server_id: serverId, id: Utils_1.generateMessageID() },
|
|
239
|
-
content: [{
|
|
240
|
-
tag: 'reaction',
|
|
241
|
-
attrs: code ? { code } : {}
|
|
242
|
-
}]
|
|
243
|
-
})
|
|
201
|
+
newsletterChangeOwner: async (jid, newOwnerJid) => {
|
|
202
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: newOwnerJid }, QueryIds.CHANGE_OWNER, XWAPaths.CHANGE_OWNER)
|
|
244
203
|
},
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
{
|
|
248
|
-
tag: 'messages',
|
|
249
|
-
attrs: { type, ...(type === 'invite' ? { key } : { jid: key }), count: count.toString(), after: after?.toString() || '100' }
|
|
250
|
-
}
|
|
251
|
-
])
|
|
252
|
-
|
|
253
|
-
return await parseFetchedUpdates(result, 'messages')
|
|
204
|
+
newsletterDemote: async (jid, userJid) => {
|
|
205
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.DEMOTE)
|
|
254
206
|
},
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
{
|
|
258
|
-
tag: 'message_updates',
|
|
259
|
-
attrs: { count: count.toString(), after: after?.toString() || '100', since: since?.toString() || '0' }
|
|
260
|
-
}
|
|
261
|
-
])
|
|
262
|
-
|
|
263
|
-
return await parseFetchedUpdates(result, 'updates')
|
|
207
|
+
newsletterDelete: async (jid) => {
|
|
208
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.DELETE_V2)
|
|
264
209
|
}
|
|
265
210
|
}
|
|
266
211
|
}
|
|
267
212
|
|
|
268
|
-
const extractNewsletterMetadata = (node, isCreate) => {
|
|
269
|
-
const result = WABinary_1.getBinaryNodeChild(node, 'result')?.content?.toString()
|
|
270
|
-
const metadataPath = JSON.parse(result).data[isCreate ? Types_1.XWAPaths.CREATE : Types_1.XWAPaths.NEWSLETTER]
|
|
271
|
-
|
|
272
|
-
const metadata = {
|
|
273
|
-
id: metadataPath?.id,
|
|
274
|
-
state: metadataPath?.state?.type,
|
|
275
|
-
creation_time: +metadataPath?.thread_metadata?.creation_time,
|
|
276
|
-
name: metadataPath?.thread_metadata?.name?.text,
|
|
277
|
-
nameTime: +metadataPath?.thread_metadata?.name?.update_time,
|
|
278
|
-
description: metadataPath?.thread_metadata?.description?.text,
|
|
279
|
-
descriptionTime: +metadataPath?.thread_metadata?.description?.update_time,
|
|
280
|
-
invite: metadataPath?.thread_metadata?.invite,
|
|
281
|
-
handle: metadataPath?.thread_metadata?.handle,
|
|
282
|
-
picture: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.picture?.direct_path || ''),
|
|
283
|
-
preview: Utils_1.getUrlFromDirectPath(metadataPath?.thread_metadata?.preview?.direct_path || ''),
|
|
284
|
-
reaction_codes: metadataPath?.thread_metadata?.settings?.reaction_codes?.value,
|
|
285
|
-
subscribers: +metadataPath?.thread_metadata?.subscribers_count,
|
|
286
|
-
verification: metadataPath?.thread_metadata?.verification,
|
|
287
|
-
viewer_metadata: metadataPath?.viewer_metadata
|
|
288
|
-
}
|
|
289
|
-
return metadata
|
|
290
|
-
}
|
|
291
|
-
|
|
292
213
|
module.exports = {
|
|
293
214
|
makeNewsletterSocket,
|
|
294
|
-
|
|
215
|
+
parseNewsletterMetadata
|
|
295
216
|
}
|