supunmd-bail 2.0.1
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/WAProto/GenerateStatics.sh +3 -0
- package/WAProto/WAProto.proto +5519 -0
- package/WAProto/fix-imports.js +29 -0
- package/WAProto/index.d.ts +11969 -0
- package/WAProto/index.js +84368 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +3 -0
- package/lib/Defaults/index.d.ts +62 -0
- package/lib/Defaults/index.js +115 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +10 -0
- package/lib/Signal/Group/ciphertext-message.js +12 -0
- package/lib/Signal/Group/group-session-builder.d.ts +15 -0
- package/lib/Signal/Group/group-session-builder.js +30 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/group_cipher.js +82 -0
- package/lib/Signal/Group/index.d.ts +12 -0
- package/lib/Signal/Group/index.js +12 -0
- package/lib/Signal/Group/keyhelper.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.js +18 -0
- package/lib/Signal/Group/queue-job.d.ts +2 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +14 -0
- package/lib/Signal/Group/sender-chain-key.js +26 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +17 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +63 -0
- package/lib/Signal/Group/sender-key-message.d.ts +19 -0
- package/lib/Signal/Group/sender-key-message.js +66 -0
- package/lib/Signal/Group/sender-key-name.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.js +48 -0
- package/lib/Signal/Group/sender-key-record.d.ts +31 -0
- package/lib/Signal/Group/sender-key-record.js +41 -0
- package/lib/Signal/Group/sender-key-state.d.ts +39 -0
- package/lib/Signal/Group/sender-key-state.js +84 -0
- package/lib/Signal/Group/sender-message-key.d.ts +12 -0
- package/lib/Signal/Group/sender-message-key.js +26 -0
- package/lib/Signal/libsignal.d.ts +5 -0
- package/lib/Signal/libsignal.js +342 -0
- package/lib/Signal/lid-mapping.d.ts +23 -0
- package/lib/Signal/lid-mapping.js +171 -0
- package/lib/Socket/Client/index.d.ts +3 -0
- package/lib/Socket/Client/index.js +3 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/types.js +11 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/Client/websocket.js +50 -0
- package/lib/Socket/business.d.ts +188 -0
- package/lib/Socket/business.js +376 -0
- package/lib/Socket/chats.d.ts +98 -0
- package/lib/Socket/chats.js +962 -0
- package/lib/Socket/communities.d.ts +244 -0
- package/lib/Socket/communities.js +431 -0
- package/lib/Socket/groups.d.ts +137 -0
- package/lib/Socket/groups.js +327 -0
- package/lib/Socket/index.d.ts +231 -0
- package/lib/Socket/index.js +18 -0
- package/lib/Socket/messages-recv.d.ts +173 -0
- package/lib/Socket/messages-recv.js +1228 -0
- package/lib/Socket/messages-send.d.ts +169 -0
- package/lib/Socket/messages-send.js +1070 -0
- package/lib/Socket/mex.d.ts +3 -0
- package/lib/Socket/mex.js +42 -0
- package/lib/Socket/newsletter.d.ts +147 -0
- package/lib/Socket/newsletter.js +181 -0
- package/lib/Socket/socket.d.ts +51 -0
- package/lib/Socket/socket.js +883 -0
- package/lib/Socket/usync.d.ts +37 -0
- package/lib/Socket/usync.js +63 -0
- package/lib/Types/Auth.d.ts +111 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Bussines.d.ts +25 -0
- package/lib/Types/Bussines.js +2 -0
- package/lib/Types/Call.d.ts +14 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.d.ts +123 -0
- package/lib/Types/Chat.js +8 -0
- package/lib/Types/Contact.d.ts +24 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.d.ts +202 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.d.ts +67 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.d.ts +47 -0
- package/lib/Types/Label.js +25 -0
- package/lib/Types/LabelAssociation.d.ts +30 -0
- package/lib/Types/LabelAssociation.js +7 -0
- package/lib/Types/Message.d.ts +303 -0
- package/lib/Types/Message.js +11 -0
- package/lib/Types/Newsletter.d.ts +135 -0
- package/lib/Types/Newsletter.js +31 -0
- package/lib/Types/Product.d.ts +79 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/Signal.d.ts +76 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.d.ts +133 -0
- package/lib/Types/Socket.js +3 -0
- package/lib/Types/State.d.ts +39 -0
- package/lib/Types/State.js +13 -0
- package/lib/Types/USync.d.ts +26 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.d.ts +65 -0
- package/lib/Types/index.js +26 -0
- package/lib/Utils/auth-utils.d.ts +19 -0
- package/lib/Utils/auth-utils.js +257 -0
- package/lib/Utils/baileys-event-stream.d.ts +17 -0
- package/lib/Utils/baileys-event-stream.js +56 -0
- package/lib/Utils/browser-utils.d.ts +4 -0
- package/lib/Utils/browser-utils.js +28 -0
- package/lib/Utils/business.d.ts +23 -0
- package/lib/Utils/business.js +231 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/chat-utils.js +763 -0
- package/lib/Utils/crypto.d.ts +41 -0
- package/lib/Utils/crypto.js +142 -0
- package/lib/Utils/decode-wa-message.d.ts +48 -0
- package/lib/Utils/decode-wa-message.js +279 -0
- package/lib/Utils/event-buffer.d.ts +34 -0
- package/lib/Utils/event-buffer.js +548 -0
- package/lib/Utils/generics.d.ts +90 -0
- package/lib/Utils/generics.js +381 -0
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/history.js +84 -0
- package/lib/Utils/index.d.ts +20 -0
- package/lib/Utils/index.js +20 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/link-preview.js +85 -0
- package/lib/Utils/logger.d.ts +12 -0
- package/lib/Utils/logger.js +3 -0
- package/lib/Utils/lt-hash.d.ts +13 -0
- package/lib/Utils/lt-hash.js +48 -0
- package/lib/Utils/make-mutex.d.ts +8 -0
- package/lib/Utils/make-mutex.js +40 -0
- package/lib/Utils/message-retry-manager.d.ts +82 -0
- package/lib/Utils/message-retry-manager.js +149 -0
- package/lib/Utils/messages-media.d.ts +114 -0
- package/lib/Utils/messages-media.js +663 -0
- package/lib/Utils/messages.d.ts +76 -0
- package/lib/Utils/messages.js +908 -0
- package/lib/Utils/noise-handler.d.ts +20 -0
- package/lib/Utils/noise-handler.js +147 -0
- package/lib/Utils/pre-key-manager.d.ts +28 -0
- package/lib/Utils/pre-key-manager.js +106 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/process-message.js +413 -0
- package/lib/Utils/signal.d.ts +34 -0
- package/lib/Utils/signal.js +159 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-multi-file-auth-state.js +121 -0
- package/lib/Utils/validate-connection.d.ts +11 -0
- package/lib/Utils/validate-connection.js +195 -0
- package/lib/WABinary/constants.d.ts +28 -0
- package/lib/WABinary/constants.js +1301 -0
- package/lib/WABinary/decode.d.ts +7 -0
- package/lib/WABinary/decode.js +238 -0
- package/lib/WABinary/encode.d.ts +3 -0
- package/lib/WABinary/encode.js +216 -0
- package/lib/WABinary/generic-utils.d.ts +15 -0
- package/lib/WABinary/generic-utils.js +191 -0
- package/lib/WABinary/index.d.ts +6 -0
- package/lib/WABinary/index.js +6 -0
- package/lib/WABinary/jid-utils.d.ts +48 -0
- package/lib/WABinary/jid-utils.js +96 -0
- package/lib/WABinary/types.d.ts +19 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.d.ts +9 -0
- package/lib/WAM/BinaryInfo.js +10 -0
- package/lib/WAM/constants.d.ts +40 -0
- package/lib/WAM/constants.js +22853 -0
- package/lib/WAM/encode.d.ts +3 -0
- package/lib/WAM/encode.js +150 -0
- package/lib/WAM/index.d.ts +4 -0
- package/lib/WAM/index.js +4 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +29 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +23 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +54 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +27 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +13 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +38 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +26 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +51 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +10 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +29 -0
- package/lib/WAUSync/Protocols/index.d.ts +5 -0
- package/lib/WAUSync/Protocols/index.js +5 -0
- package/lib/WAUSync/USyncQuery.d.ts +29 -0
- package/lib/WAUSync/USyncQuery.js +94 -0
- package/lib/WAUSync/USyncUser.d.ts +13 -0
- package/lib/WAUSync/USyncUser.js +23 -0
- package/lib/WAUSync/index.d.ts +4 -0
- package/lib/WAUSync/index.js +4 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +36 -0
- package/lib/supun +1 -0
- package/package.json +104 -0
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { type GroupMetadata, type ParticipantAction, type SocketConfig, type WAMessageKey } from '../Types/index.js';
|
|
3
|
+
import { type BinaryNode } from '../WABinary/index.js';
|
|
4
|
+
export declare const makeCommunitiesSocket: (config: SocketConfig) => {
|
|
5
|
+
communityMetadata: (jid: string) => Promise<GroupMetadata>;
|
|
6
|
+
communityCreate: (subject: string, body: string) => Promise<GroupMetadata | null>;
|
|
7
|
+
communityCreateGroup: (subject: string, participants: string[], parentCommunityJid: string) => Promise<GroupMetadata | null>;
|
|
8
|
+
communityLeave: (id: string) => Promise<void>;
|
|
9
|
+
communityUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
10
|
+
communityLinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>;
|
|
11
|
+
communityUnlinkGroup: (groupJid: string, parentCommunityJid: string) => Promise<void>;
|
|
12
|
+
communityFetchLinkedGroups: (jid: string) => Promise<{
|
|
13
|
+
communityJid: string;
|
|
14
|
+
isCommunity: boolean;
|
|
15
|
+
linkedGroups: {
|
|
16
|
+
id: string | undefined;
|
|
17
|
+
subject: string;
|
|
18
|
+
creation: number | undefined;
|
|
19
|
+
owner: string | undefined;
|
|
20
|
+
size: number | undefined;
|
|
21
|
+
}[];
|
|
22
|
+
}>;
|
|
23
|
+
communityRequestParticipantsList: (jid: string) => Promise<{
|
|
24
|
+
[key: string]: string;
|
|
25
|
+
}[]>;
|
|
26
|
+
communityRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
|
27
|
+
status: string;
|
|
28
|
+
jid: string | undefined;
|
|
29
|
+
}[]>;
|
|
30
|
+
communityParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
|
|
31
|
+
status: string;
|
|
32
|
+
jid: string | undefined;
|
|
33
|
+
content: BinaryNode;
|
|
34
|
+
}[]>;
|
|
35
|
+
communityUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
36
|
+
communityInviteCode: (jid: string) => Promise<string | undefined>;
|
|
37
|
+
communityRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
38
|
+
communityAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
39
|
+
/**
|
|
40
|
+
* revoke a v4 invite for someone
|
|
41
|
+
* @param communityJid community jid
|
|
42
|
+
* @param invitedJid jid of person you invited
|
|
43
|
+
* @returns true if successful
|
|
44
|
+
*/
|
|
45
|
+
communityRevokeInviteV4: (communityJid: string, invitedJid: string) => Promise<boolean>;
|
|
46
|
+
/**
|
|
47
|
+
* accept a CommunityInviteMessage
|
|
48
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
49
|
+
* @param inviteMessage the message to accept
|
|
50
|
+
*/
|
|
51
|
+
communityAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
52
|
+
communityGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
53
|
+
communityToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
54
|
+
communitySettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
55
|
+
communityMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
|
56
|
+
communityJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
57
|
+
communityFetchAllParticipating: () => Promise<{
|
|
58
|
+
[_: string]: GroupMetadata;
|
|
59
|
+
}>;
|
|
60
|
+
logger: import("../Utils/logger.js").ILogger;
|
|
61
|
+
getOrderDetails: (orderId: string, tokenBase64: string) => Promise<import("../Types/index.js").OrderDetails>;
|
|
62
|
+
getCatalog: ({ jid, limit, cursor }: import("../Types/index.js").GetCatalogOptions) => Promise<{
|
|
63
|
+
products: import("../Types/index.js").Product[];
|
|
64
|
+
nextPageCursor: string | undefined;
|
|
65
|
+
}>;
|
|
66
|
+
getCollections: (jid?: string, limit?: number) => Promise<{
|
|
67
|
+
collections: import("../Types/index.js").CatalogCollection[];
|
|
68
|
+
}>;
|
|
69
|
+
productCreate: (create: import("../Types/index.js").ProductCreate) => Promise<import("../Types/index.js").Product>;
|
|
70
|
+
productDelete: (productIds: string[]) => Promise<{
|
|
71
|
+
deleted: number;
|
|
72
|
+
}>;
|
|
73
|
+
productUpdate: (productId: string, update: import("../Types/index.js").ProductUpdate) => Promise<import("../Types/index.js").Product>;
|
|
74
|
+
updateBussinesProfile: (args: import("../Types/Bussines.js").UpdateBussinesProfileProps) => Promise<any>;
|
|
75
|
+
updateCoverPhoto: (photo: import("../Types/index.js").WAMediaUpload) => Promise<number>;
|
|
76
|
+
removeCoverPhoto: (id: string) => Promise<any>;
|
|
77
|
+
sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
|
|
78
|
+
sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
|
|
79
|
+
rejectCall: (callId: string, callFrom: string) => Promise<void>;
|
|
80
|
+
fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
|
|
81
|
+
requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
|
|
82
|
+
messageRetryManager: import("../Utils/index.js").MessageRetryManager | null;
|
|
83
|
+
getPrivacyTokens: (jids: string[]) => Promise<any>;
|
|
84
|
+
assertSessions: (jids: string[]) => Promise<boolean>;
|
|
85
|
+
relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types/index.js").MessageRelayOptions) => Promise<string>;
|
|
86
|
+
sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types/index.js").MessageReceiptType) => Promise<void>;
|
|
87
|
+
sendReceipts: (keys: WAMessageKey[], type: import("../Types/index.js").MessageReceiptType) => Promise<void>;
|
|
88
|
+
readMessages: (keys: WAMessageKey[]) => Promise<void>;
|
|
89
|
+
refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types/index.js").MediaConnInfo>;
|
|
90
|
+
waUploadToServer: import("../Types/index.js").WAMediaUploadFunction;
|
|
91
|
+
fetchPrivacySettings: (force?: boolean) => Promise<{
|
|
92
|
+
[_: string]: string;
|
|
93
|
+
}>;
|
|
94
|
+
sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
|
|
95
|
+
createParticipantNodes: (recipientJids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"], dsmMessage?: proto.IMessage) => Promise<{
|
|
96
|
+
nodes: BinaryNode[];
|
|
97
|
+
shouldIncludeDeviceIdentity: boolean;
|
|
98
|
+
}>;
|
|
99
|
+
getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<(import("../WABinary/index.js").JidWithDevice & {
|
|
100
|
+
jid: string;
|
|
101
|
+
})[]>;
|
|
102
|
+
updateMediaMessage: (message: import("../Types/index.js").WAMessage) => Promise<import("../Types/index.js").WAMessage>;
|
|
103
|
+
sendMessage: (jid: string, content: import("../Types/index.js").AnyMessageContent, options?: import("../Types/index.js").MiscMessageGenerationOptions) => Promise<import("../Types/index.js").WAMessage | undefined>;
|
|
104
|
+
newsletterCreate: (name: string, description?: string) => Promise<import("../Types/index.js").NewsletterMetadata>;
|
|
105
|
+
newsletterUpdate: (jid: string, updates: import("../Types/index.js").NewsletterUpdate) => Promise<unknown>;
|
|
106
|
+
newsletterSubscribers: (jid: string) => Promise<{
|
|
107
|
+
subscribers: number;
|
|
108
|
+
}>;
|
|
109
|
+
newsletterMetadata: (type: "invite" | "jid", key: string) => Promise<import("../Types/index.js").NewsletterMetadata | null>;
|
|
110
|
+
newsletterFollow: (jid: string) => Promise<unknown>;
|
|
111
|
+
newsletterUnfollow: (jid: string) => Promise<unknown>;
|
|
112
|
+
newsletterMute: (jid: string) => Promise<unknown>;
|
|
113
|
+
newsletterUnmute: (jid: string) => Promise<unknown>;
|
|
114
|
+
newsletterUpdateName: (jid: string, name: string) => Promise<unknown>;
|
|
115
|
+
newsletterUpdateDescription: (jid: string, description: string) => Promise<unknown>;
|
|
116
|
+
newsletterUpdatePicture: (jid: string, content: import("../Types/index.js").WAMediaUpload) => Promise<unknown>;
|
|
117
|
+
newsletterRemovePicture: (jid: string) => Promise<unknown>;
|
|
118
|
+
newsletterReactMessage: (jid: string, serverId: string, reaction?: string) => Promise<void>;
|
|
119
|
+
newsletterFetchMessages: (jid: string, count: number, since: number, after: number) => Promise<any>;
|
|
120
|
+
subscribeNewsletterUpdates: (jid: string) => Promise<{
|
|
121
|
+
duration: string;
|
|
122
|
+
} | null>;
|
|
123
|
+
newsletterAdminCount: (jid: string) => Promise<number>;
|
|
124
|
+
newsletterChangeOwner: (jid: string, newOwnerJid: string) => Promise<void>;
|
|
125
|
+
newsletterDemote: (jid: string, userJid: string) => Promise<void>;
|
|
126
|
+
newsletterDelete: (jid: string) => Promise<void>;
|
|
127
|
+
groupMetadata: (jid: string) => Promise<GroupMetadata>;
|
|
128
|
+
groupCreate: (subject: string, participants: string[]) => Promise<GroupMetadata>;
|
|
129
|
+
groupLeave: (id: string) => Promise<void>;
|
|
130
|
+
groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
|
|
131
|
+
groupRequestParticipantsList: (jid: string) => Promise<{
|
|
132
|
+
[key: string]: string;
|
|
133
|
+
}[]>;
|
|
134
|
+
groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
|
|
135
|
+
status: string;
|
|
136
|
+
jid: string | undefined;
|
|
137
|
+
}[]>;
|
|
138
|
+
groupParticipantsUpdate: (jid: string, participants: string[], action: ParticipantAction) => Promise<{
|
|
139
|
+
status: string;
|
|
140
|
+
jid: string | undefined;
|
|
141
|
+
content: BinaryNode;
|
|
142
|
+
}[]>;
|
|
143
|
+
groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
|
|
144
|
+
groupInviteCode: (jid: string) => Promise<string | undefined>;
|
|
145
|
+
groupRevokeInvite: (jid: string) => Promise<string | undefined>;
|
|
146
|
+
groupAcceptInvite: (code: string) => Promise<string | undefined>;
|
|
147
|
+
groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
|
|
148
|
+
groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
|
|
149
|
+
groupGetInviteInfo: (code: string) => Promise<GroupMetadata>;
|
|
150
|
+
groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
|
|
151
|
+
groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
|
|
152
|
+
groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
|
|
153
|
+
groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
|
|
154
|
+
groupFetchAllParticipating: () => Promise<{
|
|
155
|
+
[_: string]: GroupMetadata;
|
|
156
|
+
}>;
|
|
157
|
+
createCallLink: (type: "audio" | "video", event?: {
|
|
158
|
+
startTime: number;
|
|
159
|
+
}, timeoutMs?: number) => Promise<string | undefined>;
|
|
160
|
+
getBotListV2: () => Promise<import("../Types/index.js").BotListInfo[]>;
|
|
161
|
+
processingMutex: {
|
|
162
|
+
mutex<T>(code: () => Promise<T> | T): Promise<T>;
|
|
163
|
+
};
|
|
164
|
+
upsertMessage: (msg: import("../Types/index.js").WAMessage, type: import("../Types/index.js").MessageUpsertType) => Promise<void>;
|
|
165
|
+
appPatch: (patchCreate: import("../Types/index.js").WAPatchCreate) => Promise<void>;
|
|
166
|
+
sendPresenceUpdate: (type: import("../Types/index.js").WAPresence, toJid?: string) => Promise<void>;
|
|
167
|
+
presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
|
|
168
|
+
profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
|
|
169
|
+
fetchBlocklist: () => Promise<(string | undefined)[]>;
|
|
170
|
+
fetchStatus: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
|
|
171
|
+
fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index.js").USyncQueryResultList[] | undefined>;
|
|
172
|
+
updateProfilePicture: (jid: string, content: import("../Types/index.js").WAMediaUpload, dimensions?: {
|
|
173
|
+
width: number;
|
|
174
|
+
height: number;
|
|
175
|
+
}) => Promise<void>;
|
|
176
|
+
removeProfilePicture: (jid: string) => Promise<void>;
|
|
177
|
+
updateProfileStatus: (status: string) => Promise<void>;
|
|
178
|
+
updateProfileName: (name: string) => Promise<void>;
|
|
179
|
+
updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
|
|
180
|
+
updateDisableLinkPreviewsPrivacy: (isPreviewsDisabled: boolean) => Promise<void>;
|
|
181
|
+
updateCallPrivacy: (value: import("../Types/index.js").WAPrivacyCallValue) => Promise<void>;
|
|
182
|
+
updateMessagesPrivacy: (value: import("../Types/index.js").WAPrivacyMessagesValue) => Promise<void>;
|
|
183
|
+
updateLastSeenPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
|
|
184
|
+
updateOnlinePrivacy: (value: import("../Types/index.js").WAPrivacyOnlineValue) => Promise<void>;
|
|
185
|
+
updateProfilePicturePrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
|
|
186
|
+
updateStatusPrivacy: (value: import("../Types/index.js").WAPrivacyValue) => Promise<void>;
|
|
187
|
+
updateReadReceiptsPrivacy: (value: import("../Types/index.js").WAReadReceiptsValue) => Promise<void>;
|
|
188
|
+
updateGroupsAddPrivacy: (value: import("../Types/index.js").WAPrivacyGroupAddValue) => Promise<void>;
|
|
189
|
+
updateDefaultDisappearingMode: (duration: number) => Promise<void>;
|
|
190
|
+
getBusinessProfile: (jid: string) => Promise<import("../Types/index.js").WABusinessProfile | void>;
|
|
191
|
+
resyncAppState: (collections: readonly ("critical_unblock_low" | "regular_high" | "regular_low" | "critical_block" | "regular")[], isInitialSync: boolean) => Promise<void>;
|
|
192
|
+
chatModify: (mod: import("../Types/index.js").ChatModification, jid: string) => Promise<void>;
|
|
193
|
+
cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
|
|
194
|
+
addOrEditContact: (jid: string, contact: proto.SyncActionValue.IContactAction) => Promise<void>;
|
|
195
|
+
removeContact: (jid: string) => Promise<void>;
|
|
196
|
+
addLabel: (jid: string, labels: import("../Types/Label.js").LabelActionBody) => Promise<void>;
|
|
197
|
+
addChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
198
|
+
removeChatLabel: (jid: string, labelId: string) => Promise<void>;
|
|
199
|
+
addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
200
|
+
removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
|
|
201
|
+
star: (jid: string, messages: {
|
|
202
|
+
id: string;
|
|
203
|
+
fromMe?: boolean;
|
|
204
|
+
}[], star: boolean) => Promise<void>;
|
|
205
|
+
addOrEditQuickReply: (quickReply: import("../Types/Bussines.js").QuickReplyAction) => Promise<void>;
|
|
206
|
+
removeQuickReply: (timestamp: string) => Promise<void>;
|
|
207
|
+
type: "md";
|
|
208
|
+
ws: import("./Client/websocket.js").WebSocketClient;
|
|
209
|
+
ev: import("../Types/index.js").BaileysEventEmitter & {
|
|
210
|
+
process(handler: (events: Partial<import("../Types/index.js").BaileysEventMap>) => void | Promise<void>): () => void;
|
|
211
|
+
buffer(): void;
|
|
212
|
+
createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): (...args: A) => Promise<T>;
|
|
213
|
+
flush(): boolean;
|
|
214
|
+
isBuffering(): boolean;
|
|
215
|
+
};
|
|
216
|
+
authState: {
|
|
217
|
+
creds: import("../Types/index.js").AuthenticationCreds;
|
|
218
|
+
keys: import("../Types/index.js").SignalKeyStoreWithTransaction;
|
|
219
|
+
};
|
|
220
|
+
signalRepository: import("../Types/index.js").SignalRepositoryWithLIDStore;
|
|
221
|
+
user: import("../Types/index.js").Contact | undefined;
|
|
222
|
+
generateMessageTag: () => string;
|
|
223
|
+
query: (node: BinaryNode, timeoutMs?: number) => Promise<any>;
|
|
224
|
+
waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T | undefined>;
|
|
225
|
+
waitForSocketOpen: () => Promise<void>;
|
|
226
|
+
sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
|
|
227
|
+
sendNode: (frame: BinaryNode) => Promise<void>;
|
|
228
|
+
logout: (msg?: string) => Promise<void>;
|
|
229
|
+
end: (error: Error | undefined) => void;
|
|
230
|
+
onUnexpectedError: (err: Error | import("@hapi/boom").Boom, msg: string) => void;
|
|
231
|
+
uploadPreKeys: (count?: number, retryCount?: number) => Promise<void>;
|
|
232
|
+
uploadPreKeysToServerIfRequired: () => Promise<void>;
|
|
233
|
+
requestPairingCode: (phoneNumber: string, customPairingCode?: string) => Promise<string>;
|
|
234
|
+
wamBuffer: import("../index.js").BinaryInfo;
|
|
235
|
+
waitForConnectionUpdate: (check: (u: Partial<import("../Types/index.js").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
|
|
236
|
+
sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
|
|
237
|
+
executeUSyncQuery: (usyncQuery: import("../index.js").USyncQuery) => Promise<import("../index.js").USyncQueryResult | undefined>;
|
|
238
|
+
onWhatsApp: (...phoneNumber: string[]) => Promise<{
|
|
239
|
+
jid: string;
|
|
240
|
+
exists: boolean;
|
|
241
|
+
}[] | undefined>;
|
|
242
|
+
};
|
|
243
|
+
export declare const extractCommunityMetadata: (result: BinaryNode) => GroupMetadata;
|
|
244
|
+
//# sourceMappingURL=communities.d.ts.map
|
|
@@ -0,0 +1,431 @@
|
|
|
1
|
+
import { proto } from '../../WAProto/index.js';
|
|
2
|
+
import { WAMessageStubType } from '../Types/index.js';
|
|
3
|
+
import { generateMessageID, generateMessageIDV2, unixTimestampSeconds } from '../Utils/index.js';
|
|
4
|
+
import logger from '../Utils/logger.js';
|
|
5
|
+
import { getBinaryNodeChild, getBinaryNodeChildren, getBinaryNodeChildString, jidEncode, jidNormalizedUser } from '../WABinary/index.js';
|
|
6
|
+
import { makeBusinessSocket } from './business.js';
|
|
7
|
+
export const makeCommunitiesSocket = (config) => {
|
|
8
|
+
const sock = makeBusinessSocket(config);
|
|
9
|
+
const { authState, ev, query, upsertMessage } = sock;
|
|
10
|
+
const communityQuery = async (jid, type, content) => query({
|
|
11
|
+
tag: 'iq',
|
|
12
|
+
attrs: {
|
|
13
|
+
type,
|
|
14
|
+
xmlns: 'w:g2',
|
|
15
|
+
to: jid
|
|
16
|
+
},
|
|
17
|
+
content
|
|
18
|
+
});
|
|
19
|
+
const communityMetadata = async (jid) => {
|
|
20
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'query', attrs: { request: 'interactive' } }]);
|
|
21
|
+
return extractCommunityMetadata(result);
|
|
22
|
+
};
|
|
23
|
+
const communityFetchAllParticipating = async () => {
|
|
24
|
+
const result = await query({
|
|
25
|
+
tag: 'iq',
|
|
26
|
+
attrs: {
|
|
27
|
+
to: '@g.us',
|
|
28
|
+
xmlns: 'w:g2',
|
|
29
|
+
type: 'get'
|
|
30
|
+
},
|
|
31
|
+
content: [
|
|
32
|
+
{
|
|
33
|
+
tag: 'participating',
|
|
34
|
+
attrs: {},
|
|
35
|
+
content: [
|
|
36
|
+
{ tag: 'participants', attrs: {} },
|
|
37
|
+
{ tag: 'description', attrs: {} }
|
|
38
|
+
]
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
});
|
|
42
|
+
const data = {};
|
|
43
|
+
const communitiesChild = getBinaryNodeChild(result, 'communities');
|
|
44
|
+
if (communitiesChild) {
|
|
45
|
+
const communities = getBinaryNodeChildren(communitiesChild, 'community');
|
|
46
|
+
for (const communityNode of communities) {
|
|
47
|
+
const meta = extractCommunityMetadata({
|
|
48
|
+
tag: 'result',
|
|
49
|
+
attrs: {},
|
|
50
|
+
content: [communityNode]
|
|
51
|
+
});
|
|
52
|
+
data[meta.id] = meta;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
sock.ev.emit('groups.update', Object.values(data));
|
|
56
|
+
return data;
|
|
57
|
+
};
|
|
58
|
+
async function parseGroupResult(node) {
|
|
59
|
+
logger.info({ node }, 'parseGroupResult');
|
|
60
|
+
const groupNode = getBinaryNodeChild(node, 'group');
|
|
61
|
+
if (groupNode) {
|
|
62
|
+
try {
|
|
63
|
+
logger.info({ groupNode }, 'groupNode');
|
|
64
|
+
const metadata = await sock.groupMetadata(`${groupNode.attrs.id}@g.us`);
|
|
65
|
+
return metadata ? metadata : Optional.empty();
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
console.error('Error parsing group metadata:', error);
|
|
69
|
+
return Optional.empty();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Optional.empty();
|
|
73
|
+
}
|
|
74
|
+
const Optional = {
|
|
75
|
+
empty: () => null,
|
|
76
|
+
of: (value) => (value !== null ? { value } : null)
|
|
77
|
+
};
|
|
78
|
+
sock.ws.on('CB:ib,,dirty', async (node) => {
|
|
79
|
+
const { attrs } = getBinaryNodeChild(node, 'dirty');
|
|
80
|
+
if (attrs.type !== 'communities') {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
await communityFetchAllParticipating();
|
|
84
|
+
await sock.cleanDirtyBits('groups');
|
|
85
|
+
});
|
|
86
|
+
return {
|
|
87
|
+
...sock,
|
|
88
|
+
communityMetadata,
|
|
89
|
+
communityCreate: async (subject, body) => {
|
|
90
|
+
const descriptionId = generateMessageID().substring(0, 12);
|
|
91
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
92
|
+
{
|
|
93
|
+
tag: 'create',
|
|
94
|
+
attrs: { subject },
|
|
95
|
+
content: [
|
|
96
|
+
{
|
|
97
|
+
tag: 'description',
|
|
98
|
+
attrs: { id: descriptionId },
|
|
99
|
+
content: [
|
|
100
|
+
{
|
|
101
|
+
tag: 'body',
|
|
102
|
+
attrs: {},
|
|
103
|
+
content: Buffer.from(body || '', 'utf-8')
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
{
|
|
108
|
+
tag: 'parent',
|
|
109
|
+
attrs: { default_membership_approval_mode: 'request_required' }
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
tag: 'allow_non_admin_sub_group_creation',
|
|
113
|
+
attrs: {}
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
tag: 'create_general_chat',
|
|
117
|
+
attrs: {}
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
]);
|
|
122
|
+
return await parseGroupResult(result);
|
|
123
|
+
},
|
|
124
|
+
communityCreateGroup: async (subject, participants, parentCommunityJid) => {
|
|
125
|
+
const key = generateMessageIDV2();
|
|
126
|
+
const result = await communityQuery('@g.us', 'set', [
|
|
127
|
+
{
|
|
128
|
+
tag: 'create',
|
|
129
|
+
attrs: {
|
|
130
|
+
subject,
|
|
131
|
+
key
|
|
132
|
+
},
|
|
133
|
+
content: [
|
|
134
|
+
...participants.map(jid => ({
|
|
135
|
+
tag: 'participant',
|
|
136
|
+
attrs: { jid }
|
|
137
|
+
})),
|
|
138
|
+
{ tag: 'linked_parent', attrs: { jid: parentCommunityJid } }
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
]);
|
|
142
|
+
return await parseGroupResult(result);
|
|
143
|
+
},
|
|
144
|
+
communityLeave: async (id) => {
|
|
145
|
+
await communityQuery('@g.us', 'set', [
|
|
146
|
+
{
|
|
147
|
+
tag: 'leave',
|
|
148
|
+
attrs: {},
|
|
149
|
+
content: [{ tag: 'community', attrs: { id } }]
|
|
150
|
+
}
|
|
151
|
+
]);
|
|
152
|
+
},
|
|
153
|
+
communityUpdateSubject: async (jid, subject) => {
|
|
154
|
+
await communityQuery(jid, 'set', [
|
|
155
|
+
{
|
|
156
|
+
tag: 'subject',
|
|
157
|
+
attrs: {},
|
|
158
|
+
content: Buffer.from(subject, 'utf-8')
|
|
159
|
+
}
|
|
160
|
+
]);
|
|
161
|
+
},
|
|
162
|
+
communityLinkGroup: async (groupJid, parentCommunityJid) => {
|
|
163
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
164
|
+
{
|
|
165
|
+
tag: 'links',
|
|
166
|
+
attrs: {},
|
|
167
|
+
content: [
|
|
168
|
+
{
|
|
169
|
+
tag: 'link',
|
|
170
|
+
attrs: { link_type: 'sub_group' },
|
|
171
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
172
|
+
}
|
|
173
|
+
]
|
|
174
|
+
}
|
|
175
|
+
]);
|
|
176
|
+
},
|
|
177
|
+
communityUnlinkGroup: async (groupJid, parentCommunityJid) => {
|
|
178
|
+
await communityQuery(parentCommunityJid, 'set', [
|
|
179
|
+
{
|
|
180
|
+
tag: 'unlink',
|
|
181
|
+
attrs: { unlink_type: 'sub_group' },
|
|
182
|
+
content: [{ tag: 'group', attrs: { jid: groupJid } }]
|
|
183
|
+
}
|
|
184
|
+
]);
|
|
185
|
+
},
|
|
186
|
+
communityFetchLinkedGroups: async (jid) => {
|
|
187
|
+
let communityJid = jid;
|
|
188
|
+
let isCommunity = false;
|
|
189
|
+
// Try to determine if it is a subgroup or a community
|
|
190
|
+
const metadata = await sock.groupMetadata(jid);
|
|
191
|
+
if (metadata.linkedParent) {
|
|
192
|
+
// It is a subgroup, get the community jid
|
|
193
|
+
communityJid = metadata.linkedParent;
|
|
194
|
+
}
|
|
195
|
+
else {
|
|
196
|
+
// It is a community
|
|
197
|
+
isCommunity = true;
|
|
198
|
+
}
|
|
199
|
+
// Fetch all subgroups of the community
|
|
200
|
+
const result = await communityQuery(communityJid, 'get', [{ tag: 'sub_groups', attrs: {} }]);
|
|
201
|
+
const linkedGroupsData = [];
|
|
202
|
+
const subGroupsNode = getBinaryNodeChild(result, 'sub_groups');
|
|
203
|
+
if (subGroupsNode) {
|
|
204
|
+
const groupNodes = getBinaryNodeChildren(subGroupsNode, 'group');
|
|
205
|
+
for (const groupNode of groupNodes) {
|
|
206
|
+
linkedGroupsData.push({
|
|
207
|
+
id: groupNode.attrs.id ? jidEncode(groupNode.attrs.id, 'g.us') : undefined,
|
|
208
|
+
subject: groupNode.attrs.subject || '',
|
|
209
|
+
creation: groupNode.attrs.creation ? Number(groupNode.attrs.creation) : undefined,
|
|
210
|
+
owner: groupNode.attrs.creator ? jidNormalizedUser(groupNode.attrs.creator) : undefined,
|
|
211
|
+
size: groupNode.attrs.size ? Number(groupNode.attrs.size) : undefined
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
communityJid,
|
|
217
|
+
isCommunity,
|
|
218
|
+
linkedGroups: linkedGroupsData
|
|
219
|
+
};
|
|
220
|
+
},
|
|
221
|
+
communityRequestParticipantsList: async (jid) => {
|
|
222
|
+
const result = await communityQuery(jid, 'get', [
|
|
223
|
+
{
|
|
224
|
+
tag: 'membership_approval_requests',
|
|
225
|
+
attrs: {}
|
|
226
|
+
}
|
|
227
|
+
]);
|
|
228
|
+
const node = getBinaryNodeChild(result, 'membership_approval_requests');
|
|
229
|
+
const participants = getBinaryNodeChildren(node, 'membership_approval_request');
|
|
230
|
+
return participants.map(v => v.attrs);
|
|
231
|
+
},
|
|
232
|
+
communityRequestParticipantsUpdate: async (jid, participants, action) => {
|
|
233
|
+
const result = await communityQuery(jid, 'set', [
|
|
234
|
+
{
|
|
235
|
+
tag: 'membership_requests_action',
|
|
236
|
+
attrs: {},
|
|
237
|
+
content: [
|
|
238
|
+
{
|
|
239
|
+
tag: action,
|
|
240
|
+
attrs: {},
|
|
241
|
+
content: participants.map(jid => ({
|
|
242
|
+
tag: 'participant',
|
|
243
|
+
attrs: { jid }
|
|
244
|
+
}))
|
|
245
|
+
}
|
|
246
|
+
]
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
const node = getBinaryNodeChild(result, 'membership_requests_action');
|
|
250
|
+
const nodeAction = getBinaryNodeChild(node, action);
|
|
251
|
+
const participantsAffected = getBinaryNodeChildren(nodeAction, 'participant');
|
|
252
|
+
return participantsAffected.map(p => {
|
|
253
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid };
|
|
254
|
+
});
|
|
255
|
+
},
|
|
256
|
+
communityParticipantsUpdate: async (jid, participants, action) => {
|
|
257
|
+
const result = await communityQuery(jid, 'set', [
|
|
258
|
+
{
|
|
259
|
+
tag: action,
|
|
260
|
+
attrs: {},
|
|
261
|
+
content: participants.map(jid => ({
|
|
262
|
+
tag: 'participant',
|
|
263
|
+
attrs: { jid }
|
|
264
|
+
}))
|
|
265
|
+
}
|
|
266
|
+
]);
|
|
267
|
+
const node = getBinaryNodeChild(result, action);
|
|
268
|
+
const participantsAffected = getBinaryNodeChildren(node, 'participant');
|
|
269
|
+
return participantsAffected.map(p => {
|
|
270
|
+
return { status: p.attrs.error || '200', jid: p.attrs.jid, content: p };
|
|
271
|
+
});
|
|
272
|
+
},
|
|
273
|
+
communityUpdateDescription: async (jid, description) => {
|
|
274
|
+
const metadata = await communityMetadata(jid);
|
|
275
|
+
const prev = metadata.descId ?? null;
|
|
276
|
+
await communityQuery(jid, 'set', [
|
|
277
|
+
{
|
|
278
|
+
tag: 'description',
|
|
279
|
+
attrs: {
|
|
280
|
+
...(description ? { id: generateMessageID() } : { delete: 'true' }),
|
|
281
|
+
...(prev ? { prev } : {})
|
|
282
|
+
},
|
|
283
|
+
content: description ? [{ tag: 'body', attrs: {}, content: Buffer.from(description, 'utf-8') }] : undefined
|
|
284
|
+
}
|
|
285
|
+
]);
|
|
286
|
+
},
|
|
287
|
+
communityInviteCode: async (jid) => {
|
|
288
|
+
const result = await communityQuery(jid, 'get', [{ tag: 'invite', attrs: {} }]);
|
|
289
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
290
|
+
return inviteNode?.attrs.code;
|
|
291
|
+
},
|
|
292
|
+
communityRevokeInvite: async (jid) => {
|
|
293
|
+
const result = await communityQuery(jid, 'set', [{ tag: 'invite', attrs: {} }]);
|
|
294
|
+
const inviteNode = getBinaryNodeChild(result, 'invite');
|
|
295
|
+
return inviteNode?.attrs.code;
|
|
296
|
+
},
|
|
297
|
+
communityAcceptInvite: async (code) => {
|
|
298
|
+
const results = await communityQuery('@g.us', 'set', [{ tag: 'invite', attrs: { code } }]);
|
|
299
|
+
const result = getBinaryNodeChild(results, 'community');
|
|
300
|
+
return result?.attrs.jid;
|
|
301
|
+
},
|
|
302
|
+
/**
|
|
303
|
+
* revoke a v4 invite for someone
|
|
304
|
+
* @param communityJid community jid
|
|
305
|
+
* @param invitedJid jid of person you invited
|
|
306
|
+
* @returns true if successful
|
|
307
|
+
*/
|
|
308
|
+
communityRevokeInviteV4: async (communityJid, invitedJid) => {
|
|
309
|
+
const result = await communityQuery(communityJid, 'set', [
|
|
310
|
+
{ tag: 'revoke', attrs: {}, content: [{ tag: 'participant', attrs: { jid: invitedJid } }] }
|
|
311
|
+
]);
|
|
312
|
+
return !!result;
|
|
313
|
+
},
|
|
314
|
+
/**
|
|
315
|
+
* accept a CommunityInviteMessage
|
|
316
|
+
* @param key the key of the invite message, or optionally only provide the jid of the person who sent the invite
|
|
317
|
+
* @param inviteMessage the message to accept
|
|
318
|
+
*/
|
|
319
|
+
communityAcceptInviteV4: ev.createBufferedFunction(async (key, inviteMessage) => {
|
|
320
|
+
key = typeof key === 'string' ? { remoteJid: key } : key;
|
|
321
|
+
const results = await communityQuery(inviteMessage.groupJid, 'set', [
|
|
322
|
+
{
|
|
323
|
+
tag: 'accept',
|
|
324
|
+
attrs: {
|
|
325
|
+
code: inviteMessage.inviteCode,
|
|
326
|
+
expiration: inviteMessage.inviteExpiration.toString(),
|
|
327
|
+
admin: key.remoteJid
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
]);
|
|
331
|
+
// if we have the full message key
|
|
332
|
+
// update the invite message to be expired
|
|
333
|
+
if (key.id) {
|
|
334
|
+
// create new invite message that is expired
|
|
335
|
+
inviteMessage = proto.Message.GroupInviteMessage.fromObject(inviteMessage);
|
|
336
|
+
inviteMessage.inviteExpiration = 0;
|
|
337
|
+
inviteMessage.inviteCode = '';
|
|
338
|
+
ev.emit('messages.update', [
|
|
339
|
+
{
|
|
340
|
+
key,
|
|
341
|
+
update: {
|
|
342
|
+
message: {
|
|
343
|
+
groupInviteMessage: inviteMessage
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
]);
|
|
348
|
+
}
|
|
349
|
+
// generate the community add message
|
|
350
|
+
await upsertMessage({
|
|
351
|
+
key: {
|
|
352
|
+
remoteJid: inviteMessage.groupJid,
|
|
353
|
+
id: generateMessageIDV2(sock.user?.id),
|
|
354
|
+
fromMe: false,
|
|
355
|
+
participant: key.remoteJid // TODO: investigate if this makes any sense at all
|
|
356
|
+
},
|
|
357
|
+
messageStubType: WAMessageStubType.GROUP_PARTICIPANT_ADD,
|
|
358
|
+
messageStubParameters: [JSON.stringify(authState.creds.me)],
|
|
359
|
+
participant: key.remoteJid,
|
|
360
|
+
messageTimestamp: unixTimestampSeconds()
|
|
361
|
+
}, 'notify');
|
|
362
|
+
return results.attrs.from;
|
|
363
|
+
}),
|
|
364
|
+
communityGetInviteInfo: async (code) => {
|
|
365
|
+
const results = await communityQuery('@g.us', 'get', [{ tag: 'invite', attrs: { code } }]);
|
|
366
|
+
return extractCommunityMetadata(results);
|
|
367
|
+
},
|
|
368
|
+
communityToggleEphemeral: async (jid, ephemeralExpiration) => {
|
|
369
|
+
const content = ephemeralExpiration
|
|
370
|
+
? { tag: 'ephemeral', attrs: { expiration: ephemeralExpiration.toString() } }
|
|
371
|
+
: { tag: 'not_ephemeral', attrs: {} };
|
|
372
|
+
await communityQuery(jid, 'set', [content]);
|
|
373
|
+
},
|
|
374
|
+
communitySettingUpdate: async (jid, setting) => {
|
|
375
|
+
await communityQuery(jid, 'set', [{ tag: setting, attrs: {} }]);
|
|
376
|
+
},
|
|
377
|
+
communityMemberAddMode: async (jid, mode) => {
|
|
378
|
+
await communityQuery(jid, 'set', [{ tag: 'member_add_mode', attrs: {}, content: mode }]);
|
|
379
|
+
},
|
|
380
|
+
communityJoinApprovalMode: async (jid, mode) => {
|
|
381
|
+
await communityQuery(jid, 'set', [
|
|
382
|
+
{ tag: 'membership_approval_mode', attrs: {}, content: [{ tag: 'community_join', attrs: { state: mode } }] }
|
|
383
|
+
]);
|
|
384
|
+
},
|
|
385
|
+
communityFetchAllParticipating
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
export const extractCommunityMetadata = (result) => {
|
|
389
|
+
const community = getBinaryNodeChild(result, 'community');
|
|
390
|
+
const descChild = getBinaryNodeChild(community, 'description');
|
|
391
|
+
let desc;
|
|
392
|
+
let descId;
|
|
393
|
+
if (descChild) {
|
|
394
|
+
desc = getBinaryNodeChildString(descChild, 'body');
|
|
395
|
+
descId = descChild.attrs.id;
|
|
396
|
+
}
|
|
397
|
+
const communityId = community.attrs.id?.includes('@')
|
|
398
|
+
? community.attrs.id
|
|
399
|
+
: jidEncode(community.attrs.id || '', 'g.us');
|
|
400
|
+
const eph = getBinaryNodeChild(community, 'ephemeral')?.attrs.expiration;
|
|
401
|
+
const memberAddMode = getBinaryNodeChildString(community, 'member_add_mode') === 'all_member_add';
|
|
402
|
+
const metadata = {
|
|
403
|
+
id: communityId,
|
|
404
|
+
subject: community.attrs.subject || '',
|
|
405
|
+
subjectOwner: community.attrs.s_o,
|
|
406
|
+
subjectTime: Number(community.attrs.s_t || 0),
|
|
407
|
+
size: getBinaryNodeChildren(community, 'participant').length,
|
|
408
|
+
creation: Number(community.attrs.creation || 0),
|
|
409
|
+
owner: community.attrs.creator ? jidNormalizedUser(community.attrs.creator) : undefined,
|
|
410
|
+
desc,
|
|
411
|
+
descId,
|
|
412
|
+
linkedParent: getBinaryNodeChild(community, 'linked_parent')?.attrs.jid || undefined,
|
|
413
|
+
restrict: !!getBinaryNodeChild(community, 'locked'),
|
|
414
|
+
announce: !!getBinaryNodeChild(community, 'announcement'),
|
|
415
|
+
isCommunity: !!getBinaryNodeChild(community, 'parent'),
|
|
416
|
+
isCommunityAnnounce: !!getBinaryNodeChild(community, 'default_sub_community'),
|
|
417
|
+
joinApprovalMode: !!getBinaryNodeChild(community, 'membership_approval_mode'),
|
|
418
|
+
memberAddMode,
|
|
419
|
+
participants: getBinaryNodeChildren(community, 'participant').map(({ attrs }) => {
|
|
420
|
+
return {
|
|
421
|
+
// TODO: IMPLEMENT THE PN/LID FIELDS HERE!!
|
|
422
|
+
id: attrs.jid,
|
|
423
|
+
admin: (attrs.type || null)
|
|
424
|
+
};
|
|
425
|
+
}),
|
|
426
|
+
ephemeralDuration: eph ? +eph : undefined,
|
|
427
|
+
addressingMode: getBinaryNodeChildString(community, 'addressing_mode')
|
|
428
|
+
};
|
|
429
|
+
return metadata;
|
|
430
|
+
};
|
|
431
|
+
//# sourceMappingURL=communities.js.map
|