@sixcore/baileys 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 +606 -0
- package/WAProto/GenerateStatics.sh +4 -0
- package/WAProto/WAProto.proto +4357 -0
- package/WAProto/index.d.ts +50383 -0
- package/WAProto/index.js +155693 -0
- package/WASignalGroup/GroupProtocol.js +1697 -0
- package/WASignalGroup/ciphertext_message.js +16 -0
- package/WASignalGroup/generate-proto.sh +1 -0
- package/WASignalGroup/group.proto +42 -0
- package/WASignalGroup/group_cipher.js +120 -0
- package/WASignalGroup/group_session_builder.js +46 -0
- package/WASignalGroup/index.js +5 -0
- package/WASignalGroup/keyhelper.js +21 -0
- package/WASignalGroup/protobufs.js +3 -0
- package/WASignalGroup/queue_job.js +69 -0
- package/WASignalGroup/sender_chain_key.js +50 -0
- package/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/WASignalGroup/sender_key_message.js +92 -0
- package/WASignalGroup/sender_key_name.js +70 -0
- package/WASignalGroup/sender_key_record.js +56 -0
- package/WASignalGroup/sender_key_state.js +129 -0
- package/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +53 -0
- package/lib/Defaults/index.js +108 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Signal/libsignal.js +152 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +19 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/web-socket-client.d.ts +12 -0
- package/lib/Socket/Client/web-socket-client.js +62 -0
- package/lib/Socket/business.d.ts +170 -0
- package/lib/Socket/business.js +260 -0
- package/lib/Socket/chats.d.ts +81 -0
- package/lib/Socket/chats.js +950 -0
- package/lib/Socket/groups.d.ts +115 -0
- package/lib/Socket/groups.js +315 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/index.js +10 -0
- package/lib/Socket/messages-recv.d.ts +158 -0
- package/lib/Socket/messages-recv.js +972 -0
- package/lib/Socket/messages-send.d.ts +155 -0
- package/lib/Socket/messages-send.js +1087 -0
- package/lib/Socket/newsletter.d.ts +132 -0
- package/lib/Socket/newsletter.js +236 -0
- package/lib/Socket/registration.d.ts +264 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +44 -0
- package/lib/Socket/socket.js +643 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +70 -0
- package/lib/Store/index.d.ts +3 -0
- package/lib/Store/index.js +10 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +83 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-in-memory-store.js +431 -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 +109 -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 +107 -0
- package/lib/Types/Chat.js +4 -0
- package/lib/Types/Contact.d.ts +19 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +172 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +56 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +46 -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 +433 -0
- package/lib/Types/Message.js +9 -0
- package/lib/Types/Newsletter.d.ts +92 -0
- package/lib/Types/Newsletter.js +32 -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 +116 -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 +66 -0
- package/lib/Types/index.js +42 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/auth-utils.js +227 -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 +745 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/crypto.js +199 -0
- package/lib/Utils/decode-wa-message.d.ts +36 -0
- package/lib/Utils/decode-wa-message.js +234 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/event-buffer.js +517 -0
- package/lib/Utils/generics.d.ts +88 -0
- package/lib/Utils/generics.js +402 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +94 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/index.js +33 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +93 -0
- package/lib/Utils/logger.d.ts +2 -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 +113 -0
- package/lib/Utils/messages-media.js +643 -0
- package/lib/Utils/messages.d.ts +77 -0
- package/lib/Utils/messages.js +1221 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +160 -0
- package/lib/Utils/process-message.d.ts +41 -0
- package/lib/Utils/process-message.js +373 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-multi-file-auth-state.js +295 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +12 -0
- package/lib/Utils/use-single-file-auth-state.js +75 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +205 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/constants.js +40 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/decode.js +264 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/encode.js +252 -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 +31 -0
- package/lib/WABinary/jid-utils.js +62 -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 +10 -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.js +31 -0
- package/package.json +51 -0
- package/src/Defaults/baileys-version.json +3 -0
- package/src/Defaults/index.ts +133 -0
- package/src/Signal/Group/ciphertext-message.ts +9 -0
- package/src/Signal/Group/group-session-builder.ts +56 -0
- package/src/Signal/Group/group_cipher.ts +117 -0
- package/src/Signal/Group/index.ts +11 -0
- package/src/Signal/Group/keyhelper.ts +28 -0
- package/src/Signal/Group/sender-chain-key.ts +34 -0
- package/src/Signal/Group/sender-key-distribution-message.ts +95 -0
- package/src/Signal/Group/sender-key-message.ts +96 -0
- package/src/Signal/Group/sender-key-name.ts +66 -0
- package/src/Signal/Group/sender-key-record.ts +69 -0
- package/src/Signal/Group/sender-key-state.ts +134 -0
- package/src/Signal/Group/sender-message-key.ts +36 -0
- package/src/Signal/libsignal.ts +447 -0
- package/src/Signal/lid-mapping.ts +209 -0
- package/src/Socket/Client/index.ts +2 -0
- package/src/Socket/Client/types.ts +22 -0
- package/src/Socket/Client/websocket.ts +56 -0
- package/src/Socket/business.ts +421 -0
- package/src/Socket/chats.ts +1223 -0
- package/src/Socket/communities.ts +477 -0
- package/src/Socket/groups.ts +361 -0
- package/src/Socket/index.ts +22 -0
- package/src/Socket/messages-recv.ts +1563 -0
- package/src/Socket/messages-send.ts +1210 -0
- package/src/Socket/mex.ts +58 -0
- package/src/Socket/newsletter.ts +229 -0
- package/src/Socket/socket.ts +1072 -0
- package/src/Types/Auth.ts +115 -0
- package/src/Types/Bussines.ts +20 -0
- package/src/Types/Call.ts +14 -0
- package/src/Types/Chat.ts +138 -0
- package/src/Types/Contact.ts +24 -0
- package/src/Types/Events.ts +132 -0
- package/src/Types/GroupMetadata.ts +70 -0
- package/src/Types/Label.ts +48 -0
- package/src/Types/LabelAssociation.ts +35 -0
- package/src/Types/Message.ts +424 -0
- package/src/Types/Newsletter.ts +98 -0
- package/src/Types/Product.ts +85 -0
- package/src/Types/Signal.ts +76 -0
- package/src/Types/Socket.ts +150 -0
- package/src/Types/State.ts +43 -0
- package/src/Types/USync.ts +27 -0
- package/src/Types/globals.d.ts +8 -0
- package/src/Types/index.ts +67 -0
- package/src/Utils/auth-utils.ts +331 -0
- package/src/Utils/browser-utils.ts +31 -0
- package/src/Utils/business.ts +286 -0
- package/src/Utils/chat-utils.ts +933 -0
- package/src/Utils/crypto.ts +184 -0
- package/src/Utils/decode-wa-message.ts +355 -0
- package/src/Utils/event-buffer.ts +662 -0
- package/src/Utils/generics.ts +470 -0
- package/src/Utils/history.ts +114 -0
- package/src/Utils/index.ts +18 -0
- package/src/Utils/link-preview.ts +111 -0
- package/src/Utils/logger.ts +13 -0
- package/src/Utils/lt-hash.ts +65 -0
- package/src/Utils/make-mutex.ts +45 -0
- package/src/Utils/message-retry-manager.ts +229 -0
- package/src/Utils/messages-media.ts +820 -0
- package/src/Utils/messages.ts +1137 -0
- package/src/Utils/noise-handler.ts +192 -0
- package/src/Utils/pre-key-manager.ts +126 -0
- package/src/Utils/process-message.ts +622 -0
- package/src/Utils/signal.ts +214 -0
- package/src/Utils/use-multi-file-auth-state.ts +136 -0
- package/src/Utils/validate-connection.ts +253 -0
- package/src/WABinary/constants.ts +1305 -0
- package/src/WABinary/decode.ts +281 -0
- package/src/WABinary/encode.ts +253 -0
- package/src/WABinary/generic-utils.ts +127 -0
- package/src/WABinary/index.ts +5 -0
- package/src/WABinary/jid-utils.ts +128 -0
- package/src/WABinary/types.ts +17 -0
- package/src/WAM/BinaryInfo.ts +12 -0
- package/src/WAM/constants.ts +22889 -0
- package/src/WAM/encode.ts +169 -0
- package/src/WAM/index.ts +3 -0
- package/src/WAUSync/Protocols/USyncContactProtocol.ts +32 -0
- package/src/WAUSync/Protocols/USyncDeviceProtocol.ts +78 -0
- package/src/WAUSync/Protocols/USyncDisappearingModeProtocol.ts +35 -0
- package/src/WAUSync/Protocols/USyncStatusProtocol.ts +44 -0
- package/src/WAUSync/Protocols/UsyncBotProfileProtocol.ts +76 -0
- package/src/WAUSync/Protocols/UsyncLIDProtocol.ts +33 -0
- package/src/WAUSync/Protocols/index.ts +4 -0
- package/src/WAUSync/USyncQuery.ts +133 -0
- package/src/WAUSync/USyncUser.ts +32 -0
- package/src/WAUSync/index.ts +3 -0
- package/src/index.ts +13 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Boom } from '@hapi/boom'
|
|
2
|
+
import type { BinaryNode } from '../WABinary'
|
|
3
|
+
import { getBinaryNodeChild, S_WHATSAPP_NET } from '../WABinary'
|
|
4
|
+
|
|
5
|
+
const wMexQuery = (
|
|
6
|
+
variables: Record<string, unknown>,
|
|
7
|
+
queryId: string,
|
|
8
|
+
query: (node: BinaryNode) => Promise<BinaryNode>,
|
|
9
|
+
generateMessageTag: () => string
|
|
10
|
+
) => {
|
|
11
|
+
return query({
|
|
12
|
+
tag: 'iq',
|
|
13
|
+
attrs: {
|
|
14
|
+
id: generateMessageTag(),
|
|
15
|
+
type: 'get',
|
|
16
|
+
to: S_WHATSAPP_NET,
|
|
17
|
+
xmlns: 'w:mex'
|
|
18
|
+
},
|
|
19
|
+
content: [
|
|
20
|
+
{
|
|
21
|
+
tag: 'query',
|
|
22
|
+
attrs: { query_id: queryId },
|
|
23
|
+
content: Buffer.from(JSON.stringify({ variables }), 'utf-8')
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const executeWMexQuery = async <T>(
|
|
30
|
+
variables: Record<string, unknown>,
|
|
31
|
+
queryId: string,
|
|
32
|
+
dataPath: string,
|
|
33
|
+
query: (node: BinaryNode) => Promise<BinaryNode>,
|
|
34
|
+
generateMessageTag: () => string
|
|
35
|
+
): Promise<T> => {
|
|
36
|
+
const result = await wMexQuery(variables, queryId, query, generateMessageTag)
|
|
37
|
+
const child = getBinaryNodeChild(result, 'result')
|
|
38
|
+
if (child?.content) {
|
|
39
|
+
const data = JSON.parse(child.content.toString())
|
|
40
|
+
|
|
41
|
+
if (data.errors && data.errors.length > 0) {
|
|
42
|
+
const errorMessages = data.errors.map((err: Error) => err.message || 'Unknown error').join(', ')
|
|
43
|
+
const firstError = data.errors[0]
|
|
44
|
+
const errorCode = firstError.extensions?.error_code || 400
|
|
45
|
+
throw new Boom(`GraphQL server error: ${errorMessages}`, { statusCode: errorCode, data: firstError })
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const response = dataPath ? data?.data?.[dataPath] : data?.data
|
|
49
|
+
if (typeof response !== 'undefined') {
|
|
50
|
+
return response as T
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const action = (dataPath || '').startsWith('xwa2_')
|
|
55
|
+
? dataPath.substring(5).replace(/_/g, ' ')
|
|
56
|
+
: dataPath?.replace(/_/g, ' ')
|
|
57
|
+
throw new Boom(`Failed to ${action}, unexpected response structure.`, { statusCode: 400, data: result })
|
|
58
|
+
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import type { NewsletterCreateResponse, SocketConfig, WAMediaUpload } from '../Types'
|
|
2
|
+
import type { NewsletterMetadata, NewsletterUpdate } from '../Types'
|
|
3
|
+
import { QueryIds, XWAPaths } from '../Types'
|
|
4
|
+
import { generateProfilePicture } from '../Utils/messages-media'
|
|
5
|
+
import { getBinaryNodeChild } from '../WABinary'
|
|
6
|
+
import { makeGroupsSocket } from './groups'
|
|
7
|
+
import { executeWMexQuery as genericExecuteWMexQuery } from './mex'
|
|
8
|
+
|
|
9
|
+
const parseNewsletterCreateResponse = (response: NewsletterCreateResponse): NewsletterMetadata => {
|
|
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
|
+
|
|
28
|
+
const parseNewsletterMetadata = (result: unknown): NewsletterMetadata | null => {
|
|
29
|
+
if (typeof result !== 'object' || result === null) {
|
|
30
|
+
return null
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if ('id' in result && typeof result.id === 'string') {
|
|
34
|
+
return result as NewsletterMetadata
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if ('result' in result && typeof result.result === 'object' && result.result !== null && 'id' in result.result) {
|
|
38
|
+
return result.result as NewsletterMetadata
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export const makeNewsletterSocket = (config: SocketConfig) => {
|
|
45
|
+
const sock = makeGroupsSocket(config)
|
|
46
|
+
const { query, generateMessageTag } = sock
|
|
47
|
+
|
|
48
|
+
const executeWMexQuery = <T>(variables: Record<string, unknown>, queryId: string, dataPath: string): Promise<T> => {
|
|
49
|
+
return genericExecuteWMexQuery<T>(variables, queryId, dataPath, query, generateMessageTag)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const newsletterUpdate = async (jid: string, updates: NewsletterUpdate) => {
|
|
53
|
+
const variables = {
|
|
54
|
+
newsletter_id: jid,
|
|
55
|
+
updates: {
|
|
56
|
+
...updates,
|
|
57
|
+
settings: null
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return executeWMexQuery(variables, QueryIds.UPDATE_METADATA, 'xwa2_newsletter_update')
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return {
|
|
64
|
+
...sock,
|
|
65
|
+
newsletterCreate: async (name: string, description?: string): Promise<NewsletterMetadata> => {
|
|
66
|
+
const variables = {
|
|
67
|
+
input: {
|
|
68
|
+
name,
|
|
69
|
+
description: description ?? null
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const rawResponse = await executeWMexQuery<NewsletterCreateResponse>(
|
|
73
|
+
variables,
|
|
74
|
+
QueryIds.CREATE,
|
|
75
|
+
XWAPaths.xwa2_newsletter_create
|
|
76
|
+
)
|
|
77
|
+
return parseNewsletterCreateResponse(rawResponse)
|
|
78
|
+
},
|
|
79
|
+
|
|
80
|
+
newsletterUpdate,
|
|
81
|
+
|
|
82
|
+
newsletterSubscribers: async (jid: string) => {
|
|
83
|
+
return executeWMexQuery<{ subscribers: number }>(
|
|
84
|
+
{ newsletter_id: jid },
|
|
85
|
+
QueryIds.SUBSCRIBERS,
|
|
86
|
+
XWAPaths.xwa2_newsletter_subscribers
|
|
87
|
+
)
|
|
88
|
+
},
|
|
89
|
+
|
|
90
|
+
newsletterMetadata: async (type: 'invite' | 'jid', key: string) => {
|
|
91
|
+
const variables = {
|
|
92
|
+
fetch_creation_time: true,
|
|
93
|
+
fetch_full_image: true,
|
|
94
|
+
fetch_viewer_metadata: true,
|
|
95
|
+
input: {
|
|
96
|
+
key,
|
|
97
|
+
type: type.toUpperCase()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const result = await executeWMexQuery<unknown>(variables, QueryIds.METADATA, XWAPaths.xwa2_newsletter_metadata)
|
|
101
|
+
return parseNewsletterMetadata(result)
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
newsletterFollow: (jid: string) => {
|
|
105
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.FOLLOW, XWAPaths.xwa2_newsletter_follow)
|
|
106
|
+
},
|
|
107
|
+
|
|
108
|
+
newsletterUnfollow: (jid: string) => {
|
|
109
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNFOLLOW, XWAPaths.xwa2_newsletter_unfollow)
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
newsletterMute: (jid: string) => {
|
|
113
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.MUTE, XWAPaths.xwa2_newsletter_mute_v2)
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
newsletterUnmute: (jid: string) => {
|
|
117
|
+
return executeWMexQuery({ newsletter_id: jid }, QueryIds.UNMUTE, XWAPaths.xwa2_newsletter_unmute_v2)
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
newsletterUpdateName: async (jid: string, name: string) => {
|
|
121
|
+
return await newsletterUpdate(jid, { name })
|
|
122
|
+
},
|
|
123
|
+
|
|
124
|
+
newsletterUpdateDescription: async (jid: string, description: string) => {
|
|
125
|
+
return await newsletterUpdate(jid, { description })
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
newsletterUpdatePicture: async (jid: string, content: WAMediaUpload) => {
|
|
129
|
+
const { img } = await generateProfilePicture(content)
|
|
130
|
+
return await newsletterUpdate(jid, { picture: img.toString('base64') })
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
newsletterRemovePicture: async (jid: string) => {
|
|
134
|
+
return await newsletterUpdate(jid, { picture: '' })
|
|
135
|
+
},
|
|
136
|
+
|
|
137
|
+
newsletterReactMessage: async (jid: string, serverId: string, reaction?: string) => {
|
|
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
|
+
|
|
156
|
+
newsletterFetchMessages: async (jid: string, count: number, since: number, after: number) => {
|
|
157
|
+
const messageUpdateAttrs: { count: string; since?: string; after?: string } = {
|
|
158
|
+
count: count.toString()
|
|
159
|
+
}
|
|
160
|
+
if (typeof since === 'number') {
|
|
161
|
+
messageUpdateAttrs.since = since.toString()
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
if (after) {
|
|
165
|
+
messageUpdateAttrs.after = after.toString()
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
const result = await query({
|
|
169
|
+
tag: 'iq',
|
|
170
|
+
attrs: {
|
|
171
|
+
id: generateMessageTag(),
|
|
172
|
+
type: 'get',
|
|
173
|
+
xmlns: 'newsletter',
|
|
174
|
+
to: jid
|
|
175
|
+
},
|
|
176
|
+
content: [
|
|
177
|
+
{
|
|
178
|
+
tag: 'message_updates',
|
|
179
|
+
attrs: messageUpdateAttrs
|
|
180
|
+
}
|
|
181
|
+
]
|
|
182
|
+
})
|
|
183
|
+
return result
|
|
184
|
+
},
|
|
185
|
+
|
|
186
|
+
subscribeNewsletterUpdates: async (jid: string): Promise<{ duration: string } | null> => {
|
|
187
|
+
const result = await query({
|
|
188
|
+
tag: 'iq',
|
|
189
|
+
attrs: {
|
|
190
|
+
id: generateMessageTag(),
|
|
191
|
+
type: 'set',
|
|
192
|
+
xmlns: 'newsletter',
|
|
193
|
+
to: jid
|
|
194
|
+
},
|
|
195
|
+
content: [{ tag: 'live_updates', attrs: {}, content: [] }]
|
|
196
|
+
})
|
|
197
|
+
const liveUpdatesNode = getBinaryNodeChild(result, 'live_updates')
|
|
198
|
+
const duration = liveUpdatesNode?.attrs?.duration
|
|
199
|
+
return duration ? { duration: duration } : null
|
|
200
|
+
},
|
|
201
|
+
|
|
202
|
+
newsletterAdminCount: async (jid: string): Promise<number> => {
|
|
203
|
+
const response = await executeWMexQuery<{ admin_count: number }>(
|
|
204
|
+
{ newsletter_id: jid },
|
|
205
|
+
QueryIds.ADMIN_COUNT,
|
|
206
|
+
XWAPaths.xwa2_newsletter_admin_count
|
|
207
|
+
)
|
|
208
|
+
return response.admin_count
|
|
209
|
+
},
|
|
210
|
+
|
|
211
|
+
newsletterChangeOwner: async (jid: string, newOwnerJid: string) => {
|
|
212
|
+
await executeWMexQuery(
|
|
213
|
+
{ newsletter_id: jid, user_id: newOwnerJid },
|
|
214
|
+
QueryIds.CHANGE_OWNER,
|
|
215
|
+
XWAPaths.xwa2_newsletter_change_owner
|
|
216
|
+
)
|
|
217
|
+
},
|
|
218
|
+
|
|
219
|
+
newsletterDemote: async (jid: string, userJid: string) => {
|
|
220
|
+
await executeWMexQuery({ newsletter_id: jid, user_id: userJid }, QueryIds.DEMOTE, XWAPaths.xwa2_newsletter_demote)
|
|
221
|
+
},
|
|
222
|
+
|
|
223
|
+
newsletterDelete: async (jid: string) => {
|
|
224
|
+
await executeWMexQuery({ newsletter_id: jid }, QueryIds.DELETE, XWAPaths.xwa2_newsletter_delete_v2)
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
export type NewsletterSocket = ReturnType<typeof makeNewsletterSocket>
|