@neelegirl/baileys 1.5.5 → 1.5.7
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 +183 -10
- package/WAProto/WAProto.proto +5007 -0
- package/WAProto/index.d.ts +57712 -0
- package/WAProto/index.js +178969 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +68 -0
- package/lib/Defaults/index.js +137 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/WASignalGroup/GroupProtocol.js +1909 -0
- package/lib/Signal/WASignalGroup/ciphertext_message.js +16 -0
- package/lib/Signal/WASignalGroup/generate-proto.sh +1 -0
- package/lib/Signal/WASignalGroup/group.proto +42 -0
- package/lib/Signal/WASignalGroup/group_cipher.js +120 -0
- package/lib/Signal/WASignalGroup/group_session_builder.js +46 -0
- package/lib/Signal/WASignalGroup/index.js +6 -0
- package/lib/Signal/WASignalGroup/keyhelper.js +21 -0
- package/lib/Signal/WASignalGroup/protobufs.js +3 -0
- package/lib/Signal/WASignalGroup/queue_job.js +69 -0
- package/lib/Signal/WASignalGroup/readme.md +6 -0
- package/lib/Signal/WASignalGroup/sender_chain_key.js +50 -0
- package/lib/Signal/WASignalGroup/sender_key_distribution_message.js +78 -0
- package/lib/Signal/WASignalGroup/sender_key_message.js +92 -0
- package/lib/Signal/WASignalGroup/sender_key_name.js +70 -0
- package/lib/Signal/WASignalGroup/sender_key_record.js +56 -0
- package/lib/Signal/WASignalGroup/sender_key_state.js +129 -0
- package/lib/Signal/WASignalGroup/sender_message_key.js +39 -0
- package/lib/Signal/libsignal.d.ts +4 -0
- package/lib/Signal/libsignal.js +162 -0
- package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/index.js +22 -0
- package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
- package/lib/Socket/Client/mobile-socket-client.js +65 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +18 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +62 -0
- package/lib/Socket/business.d.ts +187 -0
- package/lib/Socket/business.js +268 -0
- package/lib/Socket/chats.d.ts +98 -0
- package/lib/Socket/chats.js +1113 -0
- package/lib/Socket/communities.d.ts +223 -0
- package/lib/Socket/communities.js +433 -0
- package/lib/Socket/groups.d.ts +131 -0
- package/lib/Socket/groups.js +352 -0
- package/lib/Socket/index.d.ts +191 -0
- package/lib/Socket/index.js +23 -0
- package/lib/Socket/messages-recv.d.ts +177 -0
- package/lib/Socket/messages-recv.js +1764 -0
- package/lib/Socket/messages-send.d.ts +168 -0
- package/lib/Socket/messages-send.js +1303 -0
- package/lib/Socket/mex.d.ts +2 -0
- package/lib/Socket/mex.js +47 -0
- package/lib/Socket/newsletter.d.ts +147 -0
- package/lib/Socket/newsletter.js +286 -0
- package/lib/Socket/registration.d.ts +266 -0
- package/lib/Socket/registration.js +166 -0
- package/lib/Socket/socket.d.ts +45 -0
- package/lib/Socket/socket.js +766 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +83 -0
- package/lib/Store/index.d.ts +4 -0
- package/lib/Store/index.js +24 -0
- package/lib/Store/make-cache-manager-store.d.ts +14 -0
- package/lib/Store/make-cache-manager-store.js +90 -0
- package/lib/Store/make-in-memory-store.d.ts +123 -0
- package/lib/Store/make-in-memory-store.js +429 -0
- package/lib/Store/make-ordered-dictionary.d.ts +12 -0
- package/lib/Store/make-ordered-dictionary.js +86 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Store/object-repository.js +31 -0
- package/lib/Types/Auth.d.ts +120 -0
- package/lib/Types/Auth.js +3 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.js +3 -0
- package/lib/Types/Chat.d.ts +138 -0
- package/lib/Types/Chat.js +9 -0
- package/lib/Types/Contact.d.ts +20 -0
- package/lib/Types/Contact.js +3 -0
- package/lib/Types/Events.d.ts +229 -0
- package/lib/Types/Events.js +3 -0
- package/lib/Types/GroupMetadata.d.ts +66 -0
- package/lib/Types/GroupMetadata.js +3 -0
- package/lib/Types/Label.d.ts +48 -0
- package/lib/Types/Label.js +31 -0
- package/lib/Types/LabelAssociation.d.ts +35 -0
- package/lib/Types/LabelAssociation.js +13 -0
- package/lib/Types/Message.d.ts +473 -0
- package/lib/Types/Message.js +13 -0
- package/lib/Types/MexUpdates.d.ts +9 -0
- package/lib/Types/MexUpdates.js +18 -0
- package/lib/Types/Newsletter.d.ts +109 -0
- package/lib/Types/Newsletter.js +40 -0
- package/lib/Types/Product.d.ts +92 -0
- package/lib/Types/Product.js +3 -0
- package/lib/Types/Signal.d.ts +68 -0
- package/lib/Types/Signal.js +3 -0
- package/lib/Types/Socket.d.ts +122 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +41 -0
- package/lib/Types/State.js +14 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +3 -0
- package/lib/Types/index.d.ts +79 -0
- package/lib/Types/index.js +48 -0
- package/lib/Utils/auth-utils.d.ts +21 -0
- package/lib/Utils/auth-utils.js +205 -0
- package/lib/Utils/baileys-event-stream.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.js +70 -0
- package/lib/Utils/business.d.ts +29 -0
- package/lib/Utils/business.js +255 -0
- package/lib/Utils/chat-utils.d.ts +82 -0
- package/lib/Utils/chat-utils.js +781 -0
- package/lib/Utils/check-npm-version.d.ts +15 -0
- package/lib/Utils/check-npm-version.js +52 -0
- package/lib/Utils/crypto.d.ts +56 -0
- package/lib/Utils/crypto.js +179 -0
- package/lib/Utils/decode-wa-message.d.ts +41 -0
- package/lib/Utils/decode-wa-message.js +253 -0
- package/lib/Utils/event-buffer.d.ts +39 -0
- package/lib/Utils/event-buffer.js +565 -0
- package/lib/Utils/generics.d.ts +129 -0
- package/lib/Utils/generics.js +618 -0
- package/lib/Utils/history.d.ts +23 -0
- package/lib/Utils/history.js +110 -0
- package/lib/Utils/index.d.ts +19 -0
- package/lib/Utils/index.js +41 -0
- package/lib/Utils/link-preview.d.ts +23 -0
- package/lib/Utils/link-preview.js +120 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +7 -0
- package/lib/Utils/lt-hash.d.ts +14 -0
- package/lib/Utils/lt-hash.js +58 -0
- package/lib/Utils/make-mutex.d.ts +9 -0
- package/lib/Utils/make-mutex.js +49 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.js +177 -0
- package/lib/Utils/messages-media.d.ts +129 -0
- package/lib/Utils/messages-media.js +806 -0
- package/lib/Utils/messages.d.ts +103 -0
- package/lib/Utils/messages.js +1579 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +155 -0
- package/lib/Utils/process-message.d.ts +49 -0
- package/lib/Utils/process-message.js +428 -0
- package/lib/Utils/signal.d.ts +42 -0
- package/lib/Utils/signal.js +166 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +84 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +18 -0
- package/lib/Utils/use-multi-file-auth-state.js +238 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +80 -0
- package/lib/Utils/validate-connection.d.ts +13 -0
- package/lib/Utils/validate-connection.js +187 -0
- package/lib/WABinary/constants.d.ts +30 -0
- package/lib/WABinary/constants.js +1316 -0
- package/lib/WABinary/decode.d.ts +9 -0
- package/lib/WABinary/decode.js +288 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +265 -0
- package/lib/WABinary/generic-utils.d.ts +28 -0
- package/lib/WABinary/generic-utils.js +142 -0
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/index.js +25 -0
- package/lib/WABinary/jid-utils.d.ts +53 -0
- package/lib/WABinary/jid-utils.js +92 -0
- package/lib/WABinary/types.d.ts +22 -0
- package/lib/WABinary/types.js +3 -0
- package/lib/WAM/BinaryInfo.d.ts +16 -0
- package/lib/WAM/BinaryInfo.js +17 -0
- package/lib/WAM/constants.d.ts +47 -0
- package/lib/WAM/constants.js +15371 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +165 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAM/index.js +23 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.d.ts +28 -0
- package/lib/WAUSync/Protocols/USyncBotProfileProtocol.js +69 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +36 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +62 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +35 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncLIDProtocol.js +30 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +14 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +46 -0
- package/lib/WAUSync/Protocols/index.d.ts +6 -0
- package/lib/WAUSync/Protocols/index.js +26 -0
- package/lib/WAUSync/USyncQuery.d.ts +31 -0
- package/lib/WAUSync/USyncQuery.js +92 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/USyncUser.js +30 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/WAUSync/index.js +23 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +33 -0
- package/package.json +88 -10
- package/index.js +0 -38
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { proto } from '../../WAProto'
|
|
2
|
+
import { GroupMetadata, ParticipantAction, SocketConfig, ContactAction } from '../Types'
|
|
3
|
+
import { BinaryNode } from '../WABinary'
|
|
4
|
+
|
|
5
|
+
export declare const makeGroupsSocket: (config: SocketConfig) => {
|
|
6
|
+
groupQuery: (jid: string, type: string, content: BinaryNode) => Promise<BinaryNode>
|
|
7
|
+
groupMetadata: (jid: string) => Promise<GroupMetadata>
|
|
8
|
+
groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>
|
|
9
|
+
groupLeave: (id: string) => Promise<void>
|
|
10
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>
|
|
11
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
12
|
+
[key: string]: string
|
|
13
|
+
}[]>
|
|
14
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: 'approve' | 'reject') => Promise<{
|
|
15
|
+
status: string
|
|
16
|
+
jid: string
|
|
17
|
+
}[]>
|
|
18
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
|
|
19
|
+
status: string
|
|
20
|
+
jid: string
|
|
21
|
+
content: BinaryNode
|
|
22
|
+
}[]>
|
|
23
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>
|
|
24
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>
|
|
25
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>
|
|
26
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>
|
|
27
|
+
/**
|
|
28
|
+
* revoke a v4 invite for someone
|
|
29
|
+
* @param groupJid group jid
|
|
30
|
+
* @param invitedJid jid of person you invited
|
|
31
|
+
* @returns true if successful
|
|
32
|
+
*/
|
|
33
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>
|
|
34
|
+
/**
|
|
35
|
+
* accept a GroupInviteMessage
|
|
36
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
37
|
+
* @param inviteMessage the message to accept
|
|
38
|
+
*/
|
|
39
|
+
groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>
|
|
40
|
+
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>
|
|
41
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>
|
|
42
|
+
groupSettingUpdate: (jid: string, setting: 'announcement' | 'not_announcement' | 'locked' | 'unlocked') => Promise<void>
|
|
43
|
+
groupMemberAddMode: (jid: string, mode: 'admin_add' | 'all_member_add') => Promise<void>
|
|
44
|
+
groupJoinApprovalMode: (jid: string, mode: 'on' | 'off') => Promise<void>
|
|
45
|
+
groupFetchAllParticipating: () => Promise<{
|
|
46
|
+
[_: string]: GroupMetadata
|
|
47
|
+
}>
|
|
48
|
+
processingMutex: {
|
|
49
|
+
mutex<T>(code: () => T | Promise<T>): Promise<T>
|
|
50
|
+
}
|
|
51
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
52
|
+
[_: string]: string
|
|
53
|
+
}>
|
|
54
|
+
upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>
|
|
55
|
+
appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>
|
|
56
|
+
sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>
|
|
57
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>
|
|
58
|
+
getLidUser: (jid: string) => Promise<{
|
|
59
|
+
lid: string
|
|
60
|
+
id: string
|
|
61
|
+
}[] | undefined>
|
|
62
|
+
onWhatsApp: (...jids: string[]) => Promise<{
|
|
63
|
+
jid: string
|
|
64
|
+
exists: unknown
|
|
65
|
+
}[] | undefined>
|
|
66
|
+
fetchBlocklist: () => Promise<string[]>
|
|
67
|
+
fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
|
|
68
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>
|
|
69
|
+
updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>
|
|
70
|
+
removeProfilePicture: (jid: string) => Promise<void>
|
|
71
|
+
updateProfileStatus: (status: string) => Promise<void>
|
|
72
|
+
updateProfileName: (name: string) => Promise<void>
|
|
73
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>
|
|
74
|
+
updateCallPrivacy: (value: import("../Types").WAPrivacyCallValue) => Promise<void>
|
|
75
|
+
updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
76
|
+
updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>
|
|
77
|
+
updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
78
|
+
updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>
|
|
79
|
+
updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>
|
|
80
|
+
updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyGroupAddValue) => Promise<void>
|
|
81
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>
|
|
82
|
+
updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>
|
|
83
|
+
getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>
|
|
84
|
+
resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>
|
|
85
|
+
chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>
|
|
86
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>
|
|
87
|
+
addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>
|
|
88
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>
|
|
89
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>
|
|
90
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
|
|
91
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>
|
|
92
|
+
clearMessage: (jid: string, key: import("../Types").WAProto.IMessageKey, timeStamp: number | import("long").Long) => Promise<void>
|
|
93
|
+
star: (jid: string, messages: {
|
|
94
|
+
id: string
|
|
95
|
+
fromMe?: boolean | undefined
|
|
96
|
+
}[], star: boolean) => Promise<void>
|
|
97
|
+
addOrEditContact: (jid: string, contact: ContactAction) => Promise<void>
|
|
98
|
+
removeContact: (jid: string) => Promise<void>
|
|
99
|
+
executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>
|
|
100
|
+
type: "md"
|
|
101
|
+
ws: import("./Client").WebSocketClient
|
|
102
|
+
ev: import("../Types").BaileysEventEmitter & {
|
|
103
|
+
process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void
|
|
104
|
+
buffer(): void
|
|
105
|
+
createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>
|
|
106
|
+
flush(force?: boolean | undefined): boolean
|
|
107
|
+
isBuffering(): boolean
|
|
108
|
+
}
|
|
109
|
+
authState: {
|
|
110
|
+
creds: import("../Types").AuthenticationCreds
|
|
111
|
+
keys: import("../Types").SignalKeyStoreWithTransaction
|
|
112
|
+
}
|
|
113
|
+
signalRepository: import("../Types").SignalRepository
|
|
114
|
+
user: import("../Types").Contact | undefined
|
|
115
|
+
generateMessageTag: () => string
|
|
116
|
+
query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>
|
|
117
|
+
waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>
|
|
118
|
+
waitForSocketOpen: () => Promise<void>
|
|
119
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>
|
|
120
|
+
sendNode: (frame: BinaryNode) => Promise<void>
|
|
121
|
+
logout: (msg?: string | undefined) => Promise<void>
|
|
122
|
+
end: (error: Error | undefined) => void
|
|
123
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void
|
|
124
|
+
uploadPreKeys: (count?: number) => Promise<void>
|
|
125
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>
|
|
126
|
+
requestPairingCode: (phoneNumber: string, code?: string) => Promise<string>
|
|
127
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>
|
|
128
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export declare const extractGroupMetadata: (result: BinaryNode) => GroupMetadata
|
|
@@ -0,0 +1,352 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true })
|
|
3
|
+
|
|
4
|
+
const WAProto_1 = require("../../WAProto")
|
|
5
|
+
const Types_1 = require("../Types")
|
|
6
|
+
const Utils_1 = require("../Utils")
|
|
7
|
+
const WABinary_1 = require("../WABinary")
|
|
8
|
+
const chats_1 = require("./chats")
|
|
9
|
+
|
|
10
|
+
const makeGroupsSocket = (config) => {
|
|
11
|
+
const Neele = chats_1.makeChatsSocket(config)
|
|
12
|
+
const { authState, ev, query, upsertMessage } = Neele
|
|
13
|
+
|
|
14
|
+
const groupQuery = async (jid, type, content) => (query({
|
|
15
|
+
tag: 'iq',
|
|
16
|
+
attrs: {
|
|
17
|
+
type,
|
|
18
|
+
xmlns: 'w:g2',
|
|
19
|
+
to: jid,
|
|
20
|
+
},
|
|
21
|
+
content
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
const groupMetadata = async (jid) => {
|
|
25
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }])
|
|
26
|
+
return extractGroupMetadata(result)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const groupFetchAllParticipating = async () => {
|
|
30
|
+
const result = await query({
|
|
31
|
+
tag: 'iq',
|
|
32
|
+
attrs: {
|
|
33
|
+
to: '@g.us',
|
|
34
|
+
xmlns: 'w:g2',
|
|
35
|
+
type: 'get',
|
|
36
|
+
},
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
tag: 'participating',
|
|
40
|
+
attrs: {},
|
|
41
|
+
content: [
|
|
42
|
+
{ tag: 'participants', attrs: {} },
|
|
43
|
+
{ tag: 'description', attrs: {} }
|
|
44
|
+
]
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
const data = {}
|
|
50
|
+
const groupsChild = WABinary_1.getBinaryNodeChild(result, 'groups')
|
|
51
|
+
|
|
52
|
+
if (groupsChild) {
|
|
53
|
+
const groups = WABinary_1.getBinaryNodeChildren(groupsChild, 'group')
|
|
54
|
+
for (const groupNode of groups) {
|
|
55
|
+
const meta = extractGroupMetadata({
|
|
56
|
+
tag: 'result',
|
|
57
|
+
attrs: {},
|
|
58
|
+
content: [groupNode]
|
|
59
|
+
})
|
|
60
|
+
data[meta.id] = meta
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
Neele.ev.emit('groups.update', Object.values(data))
|
|
65
|
+
return data
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Neele.ws.on('CB:ib,,dirty', async (node) => {
|
|
69
|
+
const { attrs } = WABinary_1.getBinaryNodeChild(node, 'dirty')
|
|
70
|
+
if (attrs.type !== 'groups') {
|
|
71
|
+
return
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
await groupFetchAllParticipating()
|
|
75
|
+
await Neele.cleanDirtyBits('groups')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
...Neele,
|
|
80
|
+
groupQuery,
|
|
81
|
+
groupMetadata,
|
|
82
|
+
groupCreate: async (subject, participants) => {
|
|
83
|
+
const key = Utils_1.generateMessageID()
|
|
84
|
+
|
|
85
|
+
const result = await groupQuery('@g.us', 'set', [
|
|
86
|
+
{
|
|
87
|
+
tag: 'create',
|
|
88
|
+
attrs: {
|
|
89
|
+
subject,
|
|
90
|
+
key
|
|
91
|
+
},
|
|
92
|
+
content: participants.map(jid => ({
|
|
93
|
+
tag: 'participant',
|
|
94
|
+
attrs: { jid }
|
|
95
|
+
}))
|
|
96
|
+
}
|
|
97
|
+
])
|
|
98
|
+
|
|
99
|
+
return extractGroupMetadata(result)
|
|
100
|
+
},
|
|
101
|
+
groupLeave: async (id) => {
|
|
102
|
+
await groupQuery('@g.us', 'set', [
|
|
103
|
+
{
|
|
104
|
+
tag: 'leave',
|
|
105
|
+
attrs: {},
|
|
106
|
+
content: [
|
|
107
|
+
{ tag: 'group', attrs: { id } }
|
|
108
|
+
]
|
|
109
|
+
}
|
|
110
|
+
])
|
|
111
|
+
},
|
|
112
|
+
groupUpdateSubject: async (jid, subject) => {
|
|
113
|
+
await groupQuery(jid, 'set', [
|
|
114
|
+
{
|
|
115
|
+
tag: 'subject',
|
|
116
|
+
attrs: {},
|
|
117
|
+
content: Buffer.from(subject, 'utf-8')
|
|
118
|
+
}
|
|
119
|
+
])
|
|
120
|
+
},
|
|
121
|
+
groupRequestParticipantsList: async (jid) => {
|
|
122
|
+
const result = await groupQuery(jid, 'get', [
|
|
123
|
+
{
|
|
124
|
+
tag: 'membership_approval_requests',
|
|
125
|
+
attrs: {}
|
|
126
|
+
}
|
|
127
|
+
])
|
|
128
|
+
|
|
129
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_approval_requests')
|
|
130
|
+
const participants = WABinary_1.getBinaryNodeChildren(node, 'membership_approval_request')
|
|
131
|
+
|
|
132
|
+
return participants.map(v => v.attrs)
|
|
133
|
+
},
|
|
134
|
+
groupRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
135
|
+
const result = await groupQuery(jid, 'set', [{
|
|
136
|
+
tag: 'membership_requests_action',
|
|
137
|
+
attrs: {},
|
|
138
|
+
content: [
|
|
139
|
+
{
|
|
140
|
+
tag: action,
|
|
141
|
+
attrs: {},
|
|
142
|
+
content: participants.map(jid => ({
|
|
143
|
+
tag: 'participant',
|
|
144
|
+
attrs: { jid }
|
|
145
|
+
}))
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
}])
|
|
149
|
+
|
|
150
|
+
const node = WABinary_1.getBinaryNodeChild(result, 'membership_requests_action')
|
|
151
|
+
const nodeAction = WABinary_1.getBinaryNodeChild(node, action)
|
|
152
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(nodeAction, 'participant')
|
|
153
|
+
|
|
154
|
+
return participantsAffected.map(p => {
|
|
155
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid }
|
|
156
|
+
})
|
|
157
|
+
},
|
|
158
|
+
groupParticipantsUpdate: async (jid, participants, action) => {
|
|
159
|
+
const result = await groupQuery(jid, 'set', [
|
|
160
|
+
{
|
|
161
|
+
tag: action,
|
|
162
|
+
attrs: {},
|
|
163
|
+
content: participants.map(jid => ({
|
|
164
|
+
tag: 'participant',
|
|
165
|
+
attrs: { jid }
|
|
166
|
+
}))
|
|
167
|
+
}
|
|
168
|
+
])
|
|
169
|
+
const node = WABinary_1.getBinaryNodeChild(result, action)
|
|
170
|
+
const participantsAffected = WABinary_1.getBinaryNodeChildren(node, 'participant')
|
|
171
|
+
|
|
172
|
+
return participantsAffected.map(p => {
|
|
173
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p }
|
|
174
|
+
})
|
|
175
|
+
},
|
|
176
|
+
groupUpdateDescription: async (jid, description) => {
|
|
177
|
+
const metadata = await groupMetadata(jid)
|
|
178
|
+
const prev = metadata.descId ? metadata.descId : null
|
|
179
|
+
|
|
180
|
+
await groupQuery(jid, 'set', [
|
|
181
|
+
{
|
|
182
|
+
tag: 'description',
|
|
183
|
+
attrs: {
|
|
184
|
+
...(description ? { id: Utils_1.generateMessageID() } : { delete: 'true' }),
|
|
185
|
+
...(prev ? { prev } : {})
|
|
186
|
+
},
|
|
187
|
+
content: description ? [
|
|
188
|
+
{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }
|
|
189
|
+
] : undefined
|
|
190
|
+
}
|
|
191
|
+
])
|
|
192
|
+
},
|
|
193
|
+
groupInviteCode: async (jid) => {
|
|
194
|
+
const result = await groupQuery(jid, 'get', [{ tag: 'invite', attrs: {} }])
|
|
195
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
|
|
196
|
+
|
|
197
|
+
return inviteNode?.attrs?.code
|
|
198
|
+
},
|
|
199
|
+
groupRevokeInvite: async (jid) => {
|
|
200
|
+
const result = await groupQuery(jid, 'set', [{ tag: 'invite', attrs: {} }])
|
|
201
|
+
const inviteNode = WABinary_1.getBinaryNodeChild(result, 'invite')
|
|
202
|
+
|
|
203
|
+
return inviteNode?.attrs?.code
|
|
204
|
+
},
|
|
205
|
+
groupAcceptInvite: async (code) => {
|
|
206
|
+
const results = await groupQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }])
|
|
207
|
+
const result = WABinary_1.getBinaryNodeChild(results, 'group')
|
|
208
|
+
|
|
209
|
+
return result?.attrs?.jid
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* revoke a v4 invite for someone
|
|
213
|
+
* @param groupJid group jid
|
|
214
|
+
* @param invitedJid jid of person you invited
|
|
215
|
+
* @returns true if successful
|
|
216
|
+
*/
|
|
217
|
+
groupRevokeInviteV4: async (groupJid, invitedJid) => {
|
|
218
|
+
const result = await groupQuery(groupJid, 'set', [{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }])
|
|
219
|
+
|
|
220
|
+
return !!result
|
|
221
|
+
},
|
|
222
|
+
/**
|
|
223
|
+
* accept a GroupInviteMessage
|
|
224
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
225
|
+
* @param inviteMessage the message to accept
|
|
226
|
+
*/
|
|
227
|
+
groupAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
228
|
+
key = typeof key === 'string' ? { remoteJid: key } : key
|
|
229
|
+
const results = await groupQuery(inviteMessage.groupJid, 'set', [{
|
|
230
|
+
tag: 'accept',
|
|
231
|
+
attrs: {
|
|
232
|
+
code: inviteMessage.inviteCode,
|
|
233
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
234
|
+
admin: key.remoteJid
|
|
235
|
+
}
|
|
236
|
+
}])
|
|
237
|
+
|
|
238
|
+
// if we have the full message key
|
|
239
|
+
// update the invite message to be expired
|
|
240
|
+
if (key.id) {
|
|
241
|
+
// create new invite message that is expired
|
|
242
|
+
inviteMessage = WAProto_1.proto.Message.GroupInviteMessage.fromObject(inviteMessage)
|
|
243
|
+
inviteMessage.inviteExpiration = 0
|
|
244
|
+
inviteMessage.inviteCode = ''
|
|
245
|
+
ev.emit('messages.update', [
|
|
246
|
+
{
|
|
247
|
+
key,
|
|
248
|
+
update: {
|
|
249
|
+
message: {
|
|
250
|
+
groupInviteMessage: inviteMessage
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
])
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// generate the group add message
|
|
258
|
+
await upsertMessage({
|
|
259
|
+
key: {
|
|
260
|
+
remoteJid: inviteMessage.groupJid,
|
|
261
|
+
id: Utils_1.generateMessageID(authState.creds.me?.id),
|
|
262
|
+
fromMe: false,
|
|
263
|
+
participant: key.remoteJid,
|
|
264
|
+
},
|
|
265
|
+
messageStubType: Types_1.WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
266
|
+
messageStubParameters: [
|
|
267
|
+
authState.creds.me.id
|
|
268
|
+
],
|
|
269
|
+
participant: key.remoteJid,
|
|
270
|
+
messageTimestamp: Utils_1.unixTimestampSeconds()
|
|
271
|
+
}, 'notify')
|
|
272
|
+
|
|
273
|
+
return results.attrs.from
|
|
274
|
+
}),
|
|
275
|
+
groupGetInviteInfo: async (code) => {
|
|
276
|
+
const results = await groupQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }])
|
|
277
|
+
|
|
278
|
+
return extractGroupMetadata(results)
|
|
279
|
+
},
|
|
280
|
+
groupToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
281
|
+
const content = ephemeralExpiration ?
|
|
282
|
+
{ tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } } :
|
|
283
|
+
{ tag: 'not_ephemeral', attrs: {} }
|
|
284
|
+
await groupQuery(jid, 'set', [content])
|
|
285
|
+
},
|
|
286
|
+
groupSettingUpdate: async (jid, setting) => {
|
|
287
|
+
await groupQuery(jid, 'set', [{ tag: setting, attrs: {} }])
|
|
288
|
+
},
|
|
289
|
+
groupMemberAddMode: async (jid, mode) => {
|
|
290
|
+
await groupQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }])
|
|
291
|
+
},
|
|
292
|
+
groupJoinApprovalMode: async (jid, mode) => {
|
|
293
|
+
await groupQuery(jid, 'set', [{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'group_join', attrs: { state: mode } }] }])
|
|
294
|
+
},
|
|
295
|
+
groupFetchAllParticipating
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
const extractGroupMetadata = (result) => {
|
|
300
|
+
const group = WABinary_1.getBinaryNodeChild(result, 'group')
|
|
301
|
+
const descChild = WABinary_1.getBinaryNodeChild(group, 'description')
|
|
302
|
+
|
|
303
|
+
let desc
|
|
304
|
+
let descId
|
|
305
|
+
|
|
306
|
+
if (descChild) {
|
|
307
|
+
desc = WABinary_1.getBinaryNodeChildString(descChild, 'body')
|
|
308
|
+
descId = descChild.attrs.id
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const mode = group.attrs.addressing_mode
|
|
312
|
+
const groupId = group.attrs.id.includes('@') ? group.attrs.id : WABinary_1.jidEncode(group.attrs.id, 'g.us')
|
|
313
|
+
const eph = WABinary_1.getBinaryNodeChild(group, 'ephemeral')?.attrs.expiration
|
|
314
|
+
const memberAddMode = WABinary_1.getBinaryNodeChildString(group, 'member_add_mode') === 'all_member_add'
|
|
315
|
+
|
|
316
|
+
const metadata = {
|
|
317
|
+
id: groupId,
|
|
318
|
+
addressingMode: mode,
|
|
319
|
+
subject: group.attrs.subject,
|
|
320
|
+
subjectOwner: mode === 'lid' ? group.attrs.s_o_pn : group.attrs.s_o,
|
|
321
|
+
subjectTime: +group.attrs.s_t,
|
|
322
|
+
size: group.attrs?.size ? +group.attrs.size : WABinary_1.getBinaryNodeChildren(group, 'participant').length,
|
|
323
|
+
creation: +group.attrs.creation,
|
|
324
|
+
owner: group.attrs.creator ? WABinary_1.jidNormalizedUser(mode === 'lid' ? group.attrs.creator_pn : group.attrs.creator) : undefined,
|
|
325
|
+
ownerCountry: group.attrs.creator_country_code,
|
|
326
|
+
desc,
|
|
327
|
+
descId,
|
|
328
|
+
linkedParent: WABinary_1.getBinaryNodeChild(group, 'linked_parent')?.attrs.jid || undefined,
|
|
329
|
+
restrict: !!WABinary_1.getBinaryNodeChild(group, 'locked'),
|
|
330
|
+
announce: !!WABinary_1.getBinaryNodeChild(group, 'announcement'),
|
|
331
|
+
isCommunity: !!WABinary_1.getBinaryNodeChild(group, 'parent'),
|
|
332
|
+
isCommunityAnnounce: !!WABinary_1.getBinaryNodeChild(group, 'default_sub_group'),
|
|
333
|
+
joinApprovalMode: !!WABinary_1.getBinaryNodeChild(group, 'membership_approval_mode'),
|
|
334
|
+
memberAddMode,
|
|
335
|
+
participants: WABinary_1.getBinaryNodeChildren(group, 'participant').map(({ attrs }) => {
|
|
336
|
+
return {
|
|
337
|
+
id: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
|
|
338
|
+
jid: (0, WABinary_1.isJidUser)(attrs.jid) ? attrs.jid : (0, WABinary_1.jidNormalizedUser)(attrs.phone_number),
|
|
339
|
+
lid: (0, WABinary_1.isLidUser)(attrs.jid) ? attrs.jid : attrs.lid,
|
|
340
|
+
admin: (attrs.type || null)
|
|
341
|
+
};
|
|
342
|
+
}),
|
|
343
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return metadata
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
module.exports = {
|
|
350
|
+
makeGroupsSocket,
|
|
351
|
+
extractGroupMetadata
|
|
352
|
+
}
|