@jkt48connect-corp/baileys 7.2.9 → 7.3.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.
Files changed (100) hide show
  1. package/WAProto/index.d.ts +48955 -0
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +284 -0
  4. package/lib/Defaults/index.js +5 -5
  5. package/lib/Signal/libsignal.d.ts +3 -0
  6. package/lib/Socket/Client/abstract-socket-client.d.ts +15 -0
  7. package/lib/Socket/Client/index.d.ts +2 -0
  8. package/lib/Socket/Client/index.js +2 -3
  9. package/lib/Socket/Client/mobile-socket-client.d.ts +12 -0
  10. package/lib/Socket/Client/types.d.ts +17 -0
  11. package/lib/Socket/Client/types.js +13 -0
  12. package/lib/Socket/Client/websocket.d.ts +12 -0
  13. package/lib/Socket/Client/{web-socket-client.js → websocket.js} +2 -2
  14. package/lib/Socket/business.d.ts +170 -0
  15. package/lib/Socket/chats.d.ts +81 -0
  16. package/lib/Socket/chats.js +51 -48
  17. package/lib/Socket/groups.d.ts +115 -0
  18. package/lib/Socket/groups.js +1 -0
  19. package/lib/Socket/index.d.ts +172 -0
  20. package/lib/Socket/messages-recv.d.ts +158 -0
  21. package/lib/Socket/messages-send.d.ts +155 -0
  22. package/lib/Socket/messages-send.js +105 -77
  23. package/lib/Socket/newsletter.d.ts +132 -0
  24. package/lib/Socket/registration.d.ts +264 -0
  25. package/lib/Socket/socket.d.ts +44 -0
  26. package/lib/Socket/socket.js +15 -8
  27. package/lib/Socket/usync.d.ts +37 -0
  28. package/lib/Socket/usync.js +70 -0
  29. package/lib/Store/index.d.ts +3 -0
  30. package/lib/Store/make-cache-manager-store.d.ts +14 -0
  31. package/lib/Store/make-in-memory-store.d.ts +118 -0
  32. package/lib/Store/make-in-memory-store.js +24 -13
  33. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  34. package/lib/Store/object-repository.d.ts +10 -0
  35. package/lib/Types/Auth.d.ts +109 -0
  36. package/lib/Types/Call.d.ts +13 -0
  37. package/lib/Types/Chat.d.ts +107 -0
  38. package/lib/Types/Contact.d.ts +19 -0
  39. package/lib/Types/Events.d.ts +172 -0
  40. package/lib/Types/GroupMetadata.d.ts +56 -0
  41. package/lib/Types/Label.d.ts +46 -0
  42. package/lib/Types/LabelAssociation.d.ts +29 -0
  43. package/lib/Types/Message.d.ts +433 -0
  44. package/lib/Types/Newsletter.d.ts +92 -0
  45. package/lib/Types/Product.d.ts +78 -0
  46. package/lib/Types/Signal.d.ts +57 -0
  47. package/lib/Types/Socket.d.ts +116 -0
  48. package/lib/Types/State.d.ts +27 -0
  49. package/lib/Types/USync.d.ts +25 -0
  50. package/lib/Types/USync.js +2 -0
  51. package/lib/Types/index.d.ts +66 -0
  52. package/lib/Utils/auth-utils.d.ts +18 -0
  53. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  54. package/lib/Utils/business.d.ts +22 -0
  55. package/lib/Utils/chat-utils.d.ts +70 -0
  56. package/lib/Utils/crypto.d.ts +40 -0
  57. package/lib/Utils/decode-wa-message.d.ts +36 -0
  58. package/lib/Utils/event-buffer.d.ts +35 -0
  59. package/lib/Utils/generics.d.ts +88 -0
  60. package/lib/Utils/generics.js +2 -2
  61. package/lib/Utils/history.d.ts +19 -0
  62. package/lib/Utils/index.d.ts +17 -0
  63. package/lib/Utils/link-preview.d.ts +21 -0
  64. package/lib/Utils/logger.d.ts +2 -0
  65. package/lib/Utils/lt-hash.d.ts +12 -0
  66. package/lib/Utils/make-mutex.d.ts +7 -0
  67. package/lib/Utils/messages-media.d.ts +113 -0
  68. package/lib/Utils/messages.d.ts +77 -0
  69. package/lib/Utils/messages.js +73 -12
  70. package/lib/Utils/messages.js.bak +1249 -0
  71. package/lib/Utils/noise-handler.d.ts +20 -0
  72. package/lib/Utils/process-message.d.ts +41 -0
  73. package/lib/Utils/signal.d.ts +33 -0
  74. package/lib/Utils/signal.js +11 -19
  75. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  76. package/lib/Utils/use-multi-file-auth-state.js +1 -7
  77. package/lib/Utils/validate-connection.d.ts +11 -0
  78. package/lib/Utils/validate-connection.js +23 -12
  79. package/lib/WABinary/constants.d.ts +27 -0
  80. package/lib/WABinary/decode.d.ts +6 -0
  81. package/lib/WABinary/encode.d.ts +2 -0
  82. package/lib/WABinary/generic-utils.d.ts +14 -0
  83. package/lib/WABinary/index.d.ts +5 -0
  84. package/lib/WABinary/jid-utils.d.ts +31 -0
  85. package/lib/WABinary/types.d.ts +18 -0
  86. package/lib/WAM/BinaryInfo.d.ts +8 -0
  87. package/lib/WAM/constants.d.ts +38 -0
  88. package/lib/WAM/encode.d.ts +2 -0
  89. package/lib/WAM/index.d.ts +3 -0
  90. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  91. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  92. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  93. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  94. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  95. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  96. package/lib/WAUSync/USyncUser.d.ts +10 -0
  97. package/lib/WAUSync/index.d.ts +3 -0
  98. package/lib/index.js +1 -3
  99. package/package.json +7 -4
  100. package/LICENSE +0 -21
@@ -0,0 +1,158 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto';
3
+ import { MessageReceiptType, MessageRelayOptions, SocketConfig, WAMessageKey } from '../Types';
4
+ import { BinaryNode } from '../WABinary';
5
+ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
6
+ sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
7
+ sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
8
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
9
+ id: any;
10
+ to: string;
11
+ }>;
12
+ rejectCall: (callId: string, callFrom: string) => Promise<void>;
13
+ fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number) => Promise<string>;
14
+ requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
15
+ getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
16
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
17
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
18
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
19
+ sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
20
+ getButtonArgs: (message: proto.IMessage) => BinaryNode["attrs"];
21
+ readMessages: (keys: WAMessageKey[]) => Promise<void>;
22
+ refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
23
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
24
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
25
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode["attrs"]) => Promise<{
26
+ nodes: BinaryNode[];
27
+ shouldIncludeDeviceIdentity: boolean;
28
+ }>;
29
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
30
+ fetchPrivacySettings: (force?: boolean) => Promise<{
31
+ [_: string]: string;
32
+ }>;
33
+ updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
34
+ sendStatusMentions: (content: import("../Types").AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
35
+ sendAlbumMessage: (jid: string, medias: import("../Types").Media[], options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
36
+ sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
37
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
38
+ duration: string;
39
+ }>;
40
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
41
+ newsletterUpdateDescription: (jid: string, description?: string) => Promise<void>;
42
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
43
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
44
+ newsletterRemovePicture: (jid: string) => Promise<void>;
45
+ newsletterUnfollow: (jid: string) => Promise<void>;
46
+ newsletterFollow: (jid: string) => Promise<void>;
47
+ newsletterUnmute: (jid: string) => Promise<void>;
48
+ newsletterMute: (jid: string) => Promise<void>;
49
+ newsletterAction: (jid: string, type: "follow" | "unfollow" | "mute" | "unmute") => Promise<void>;
50
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
51
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole) => Promise<import("../Types").NewsletterMetadata>;
52
+ newsletterAdminCount: (jid: string) => Promise<number>;
53
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
54
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
55
+ newsletterDelete: (jid: string) => Promise<void>;
56
+ newsletterReactMessage: (jid: string, serverId: string, code?: string) => Promise<void>;
57
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
58
+ newsletterFetchUpdates: (jid: string, count: number, after?: number, since?: number) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
59
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
60
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
61
+ groupLeave: (id: string) => Promise<void>;
62
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
63
+ groupRequestParticipantsList: (jid: string) => Promise<{
64
+ [key: string]: string;
65
+ }[]>;
66
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "approve" | "reject") => Promise<{
67
+ status: string;
68
+ jid: string;
69
+ }[]>;
70
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
71
+ status: string;
72
+ jid: string;
73
+ content: BinaryNode;
74
+ }[]>;
75
+ groupUpdateDescription: (jid: string, description?: string) => Promise<void>;
76
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
77
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
78
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
79
+ groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
80
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
81
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
82
+ groupSettingUpdate: (jid: string, setting: "announcement" | "not_announcement" | "locked" | "unlocked") => Promise<void>;
83
+ groupMemberAddMode: (jid: string, mode: "admin_add" | "all_member_add") => Promise<void>;
84
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
85
+ groupFetchAllParticipating: () => Promise<{
86
+ [_: string]: import("../Types").GroupMetadata;
87
+ }>;
88
+ processingMutex: {
89
+ mutex<T>(code: () => Promise<T> | T): Promise<T>;
90
+ };
91
+ upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
92
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
93
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string) => Promise<void>;
94
+ presenceSubscribe: (toJid: string, tcToken?: Buffer) => Promise<void>;
95
+ profilePictureUrl: (jid: string, type?: "preview" | "image", timeoutMs?: number) => Promise<string | undefined>;
96
+ onWhatsApp: (...jids: string[]) => Promise<{
97
+ exists: boolean;
98
+ jid: string;
99
+ }[]>;
100
+ fetchBlocklist: () => Promise<string[]>;
101
+ fetchStatus: (jid: string) => Promise<{
102
+ status: string | undefined;
103
+ setAt: Date;
104
+ } | undefined>;
105
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
106
+ removeProfilePicture: (jid: string) => Promise<void>;
107
+ updateProfileStatus: (status: string) => Promise<void>;
108
+ updateProfileName: (name: string) => Promise<void>;
109
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
110
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
111
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
112
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
113
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
114
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
115
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
116
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
117
+ getBusinessProfile: (jid: string) => Promise<import("../Types").WABusinessProfile | void>;
118
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
119
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
120
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: number | string) => Promise<void>;
121
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
122
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
123
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
124
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
125
+ star: (jid: string, messages: {
126
+ id: string;
127
+ fromMe?: boolean;
128
+ }[], star: boolean) => Promise<void>;
129
+ type: "md";
130
+ ws: any;
131
+ ev: import("../Types").BaileysEventEmitter & {
132
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): (() => void);
133
+ buffer(): void;
134
+ createBufferedFunction<A extends any[], T>(work: (...args: A) => Promise<T>): ((...args: A) => Promise<T>);
135
+ flush(force?: boolean): boolean;
136
+ isBuffering(): boolean;
137
+ };
138
+ authState: {
139
+ creds: import("../Types").AuthenticationCreds;
140
+ keys: import("../Types").SignalKeyStoreWithTransaction;
141
+ };
142
+ signalRepository: import("../Types").SignalRepository;
143
+ user: import("../Types").Contact | undefined;
144
+ generateMessageTag: () => string;
145
+ query: (node: BinaryNode, timeoutMs?: number) => Promise<BinaryNode>;
146
+ waitForMessage: <T>(msgId: string, timeoutMs?: number | undefined) => Promise<T>;
147
+ waitForSocketOpen: () => Promise<void>;
148
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
149
+ sendNode: (frame: BinaryNode) => Promise<void>;
150
+ logout: (msg?: string) => Promise<void>;
151
+ end: (error: Error | undefined) => void;
152
+ onUnexpectedError: (err: Error | Boom, msg: string) => void;
153
+ uploadPreKeys: (count?: number) => Promise<void>;
154
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
155
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
156
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
157
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
158
+ };
@@ -0,0 +1,155 @@
1
+ /// <reference types="node" />
2
+ import { Boom } from '@hapi/boom';
3
+ import { proto } from '../../WAProto';
4
+ import { AnyMessageContent, Media, MediaConnInfo, MessageReceiptType, MessageRelayOptions, MiscMessageGenerationOptions, QueryIds, SocketConfig, WAMessageKey } from '../Types';
5
+ import { BinaryNode, JidWithDevice } from '../WABinary';
6
+ import { USyncQuery } from '../WAUSync';
7
+ export declare const makeMessagesSocket: (config: SocketConfig) => {
8
+ getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
9
+ assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
10
+ relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, cachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
11
+ sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
12
+ sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
13
+ getButtonArgs: (message: proto.IMessage) => BinaryNode['attrs'];
14
+ readMessages: (keys: WAMessageKey[]) => Promise<void>;
15
+ refreshMediaConn: (forceGet?: boolean) => Promise<MediaConnInfo>;
16
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<JidWithDevice[]>;
17
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
18
+ createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: BinaryNode['attrs']) => Promise<{
19
+ nodes: BinaryNode[];
20
+ shouldIncludeDeviceIdentity: boolean;
21
+ }>;
22
+ profilePictureUrl: (jid: string, type?: 'preview' | 'image', timeoutMs?: number) => Promise<string | null | undefined>;
23
+ waUploadToServer: import("../Types").WAMediaUploadFunction;
24
+ fetchPrivacySettings: (force?: boolean) => Promise<{
25
+ [_: string]: string;
26
+ }>;
27
+ updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
28
+ sendStatusMentions: (content: AnyMessageContent, jids?: string[]) => Promise<proto.WebMessageInfo>;
29
+ sendAlbumMessage: (jid: string, medias: Media[], options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo>;
30
+ sendMessage: (jid: string, content: AnyMessageContent, options?: MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
31
+ newsletterQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
32
+ newsletterWMexQuery: (jid: string | undefined, queryId: QueryIds, content?: object | undefined) => Promise<BinaryNode>;
33
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
34
+ duration: string;
35
+ }>;
36
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
37
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
38
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
39
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
40
+ newsletterRemovePicture: (jid: string) => Promise<void>;
41
+ newsletterUnfollow: (jid: string) => Promise<void>;
42
+ newsletterFollow: (jid: string) => Promise<void>;
43
+ newsletterUnmute: (jid: string) => Promise<void>;
44
+ newsletterMute: (jid: string) => Promise<void>;
45
+ newsletterAction: (jid: string, type: "mute" | "follow" | "unfollow" | "unmute") => Promise<void>;
46
+ newsletterCreate: (name: string, description: string) => Promise<import("../Types").NewsletterMetadata>;
47
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
48
+ newsletterAdminCount: (jid: string) => Promise<number>;
49
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
50
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
51
+ newsletterDelete: (jid: string) => Promise<void>;
52
+ newsletterReactMessage: (jid: string, serverId: string, code?: string | undefined) => Promise<void>;
53
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
54
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
55
+ groupQuery: (jid: string, type: "get" | "set", content: BinaryNode[]) => Promise<BinaryNode>;
56
+ groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
57
+ groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
58
+ groupLeave: (id: string) => Promise<void>;
59
+ groupUpdateSubject: (jid: string, subject: string) => Promise<void>;
60
+ groupRequestParticipantsList: (jid: string) => Promise<{
61
+ [key: string]: string;
62
+ }[]>;
63
+ groupRequestParticipantsUpdate: (jid: string, participants: string[], action: "reject" | "approve") => Promise<{
64
+ status: string;
65
+ jid: string;
66
+ }[]>;
67
+ groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
68
+ status: string;
69
+ jid: string;
70
+ content: BinaryNode;
71
+ }[]>;
72
+ groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
73
+ groupInviteCode: (jid: string) => Promise<string | undefined>;
74
+ groupRevokeInvite: (jid: string) => Promise<string | undefined>;
75
+ groupAcceptInvite: (code: string) => Promise<string | undefined>;
76
+ groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
77
+ groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
78
+ groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
79
+ groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
80
+ groupMemberAddMode: (jid: string, mode: "all_member_add" | "admin_add") => Promise<void>;
81
+ groupJoinApprovalMode: (jid: string, mode: "on" | "off") => Promise<void>;
82
+ groupFetchAllParticipating: () => Promise<{
83
+ [_: string]: import("../Types").GroupMetadata;
84
+ }>;
85
+ interactiveQuery: (userNodes: BinaryNode[], queryNode: BinaryNode) => Promise<BinaryNode[]>;
86
+ processingMutex: {
87
+ mutex<T>(code: () => T | Promise<T>): Promise<T>;
88
+ };
89
+ upsertMessage: (msg: proto.IWebMessageInfo, type: import("../Types").MessageUpsertType) => Promise<void>;
90
+ appPatch: (patchCreate: import("../Types").WAPatchCreate) => Promise<void>;
91
+ fetchUserLid: (jid: string) => Promise<string | undefined>;
92
+ sendPresenceUpdate: (type: import("../Types").WAPresence, toJid?: string | undefined) => Promise<void>;
93
+ presenceSubscribe: (toJid: string, tcToken?: Buffer | undefined) => Promise<void>;
94
+ onWhatsApp: (...jids: string[]) => Promise<{
95
+ jid: string;
96
+ exists: unknown;
97
+ }[] | undefined>;
98
+ fetchBlocklist: () => Promise<string[]>;
99
+ fetchStatus: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
100
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../WAUSync").USyncQueryResultList[] | undefined>;
101
+ updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
102
+ removeProfilePicture: (jid: string) => Promise<void>;
103
+ updateProfileStatus: (status: string) => Promise<void>;
104
+ updateProfileName: (name: string) => Promise<void>;
105
+ updateBlockStatus: (jid: string, action: "block" | "unblock") => Promise<void>;
106
+ updateLastSeenPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
107
+ updateOnlinePrivacy: (value: import("../Types").WAPrivacyOnlineValue) => Promise<void>;
108
+ updateProfilePicturePrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
109
+ updateStatusPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
110
+ updateReadReceiptsPrivacy: (value: import("../Types").WAReadReceiptsValue) => Promise<void>;
111
+ updateGroupsAddPrivacy: (value: import("../Types").WAPrivacyValue) => Promise<void>;
112
+ updateDefaultDisappearingMode: (duration: number) => Promise<void>;
113
+ getBusinessProfile: (jid: string) => Promise<void | import("../Types").WABusinessProfile>;
114
+ resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
115
+ chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
116
+ cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
117
+ addChatLabel: (jid: string, labelId: string) => Promise<void>;
118
+ removeChatLabel: (jid: string, labelId: string) => Promise<void>;
119
+ addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
120
+ removeMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
121
+ star: (jid: string, messages: {
122
+ id: string;
123
+ fromMe?: boolean | undefined;
124
+ }[], star: boolean) => Promise<void>;
125
+ executeUSyncQuery: (usyncQuery: USyncQuery) => Promise<import("../WAUSync").USyncQueryResult | undefined>;
126
+ type: "md";
127
+ ws: any;
128
+ ev: import("../Types").BaileysEventEmitter & {
129
+ process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
130
+ buffer(): void;
131
+ createBufferedFunction<A extends any[], T_1>(work: (...args: A) => Promise<T_1>): (...args: A) => Promise<T_1>;
132
+ flush(force?: boolean | undefined): boolean;
133
+ isBuffering(): boolean;
134
+ };
135
+ authState: {
136
+ creds: import("../Types").AuthenticationCreds;
137
+ keys: import("../Types").SignalKeyStoreWithTransaction;
138
+ };
139
+ signalRepository: import("../Types").SignalRepository;
140
+ user: import("../Types").Contact | undefined;
141
+ generateMessageTag: () => string;
142
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
143
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
144
+ waitForSocketOpen: () => Promise<void>;
145
+ sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
146
+ sendNode: (frame: BinaryNode) => Promise<void>;
147
+ logout: (msg?: string | undefined) => Promise<void>;
148
+ end: (error: Error | undefined) => void;
149
+ onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
150
+ uploadPreKeys: (count?: number) => Promise<void>;
151
+ uploadPreKeysToServerIfRequired: () => Promise<void>;
152
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
153
+ waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number | undefined) => Promise<void>;
154
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
155
+ };
@@ -8,17 +8,19 @@ const boom_1 = require("@hapi/boom");
8
8
  const node_cache_1 = __importDefault(require("node-cache"));
9
9
  const WAProto_1 = require("../../WAProto");
10
10
  const Defaults_1 = require("../Defaults");
11
+ const Types_1 = require("../Types");
11
12
  const Utils_1 = require("../Utils");
12
13
  const link_preview_1 = require("../Utils/link-preview");
13
14
  const WABinary_1 = require("../WABinary");
15
+ const WAUSync_1 = require("../WAUSync");
14
16
  const newsletter_1 = require("./newsletter");
15
17
  var ListType = WAProto_1.proto.Message.ListMessage.ListType;
16
18
  const makeMessagesSocket = (config) => {
17
19
  const { logger, linkPreviewImageThumbnailWidth, generateHighQualityLinkPreview, options: axiosOptions, patchMessageBeforeSending, } = config;
18
20
  const sock = (0, newsletter_1.makeNewsletterSocket)(config);
19
- const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupToggleEphemeral } = sock;
21
+ const { ev, authState, processingMutex, signalRepository, upsertMessage, query, fetchPrivacySettings, generateMessageTag, sendNode, groupMetadata, groupQuery, newsletterWMexQuery, groupToggleEphemeral } = sock;
20
22
  const userDevicesCache = config.userDevicesCache || new node_cache_1.default({
21
- stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES, // 5 minutes
23
+ stdTTL: Defaults_1.DEFAULT_CACHE_TTLS.USER_DEVICES,
22
24
  useClones: false
23
25
  });
24
26
  let mediaConn;
@@ -109,6 +111,43 @@ const makeMessagesSocket = (config) => {
109
111
  const readType = privacySettings.readreceipts === 'all' ? 'read' : 'read-self';
110
112
  await sendReceipts(keys, readType);
111
113
  };
114
+ const profilePictureUrl = async (jid, type = 'preview', timeoutMs) => {
115
+ var _a, _b, _c, _d;
116
+ jid = (0, WABinary_1.jidNormalizedUser)(jid);
117
+ if ((0, WABinary_1.isJidNewsLetter)(jid)) {
118
+ const node = await newsletterWMexQuery(undefined, Types_1.QueryIds.METADATA, {
119
+ input: {
120
+ key: jid,
121
+ type: "JID",
122
+ 'view_role': 'GUEST'
123
+ },
124
+ 'fetch_viewer_metadata': true,
125
+ 'fetch_full_image': true,
126
+ 'fetch_creation_time': true
127
+ });
128
+ const result = (_b = (_a = (0, WABinary_1.getBinaryNodeChild)(node, 'result')) === null || _a === void 0 ? void 0 : _a.content) === null || _b === void 0 ? void 0 : _b.toString();
129
+ const metadataPath = JSON.parse(result).data[Types_1.XWAPaths.NEWSLETTER];
130
+ const pictype = type === 'image' ? 'picture' : 'preview';
131
+ const directPath = (_c = metadataPath === null || metadataPath === void 0 ? void 0 : metadataPath.thread_metadata[pictype]) === null || _c === void 0 ? void 0 : _c.direct_path;
132
+ return directPath ? (0, Utils_1.getUrlFromDirectPath)(directPath) : null;
133
+ }
134
+ else {
135
+ const result = await query({
136
+ tag: 'iq',
137
+ attrs: {
138
+ target: jid,
139
+ to: WABinary_1.S_WHATSAPP_NET,
140
+ type: 'get',
141
+ xmlns: 'w:profile:picture'
142
+ },
143
+ content: [
144
+ { tag: 'picture', attrs: { type, query: 'url' } }
145
+ ]
146
+ }, timeoutMs);
147
+ const child = (0, WABinary_1.getBinaryNodeChild)(result, 'picture');
148
+ return (_d = child === null || child === void 0 ? void 0 : child.attrs) === null || _d === void 0 ? void 0 : _d.url;
149
+ }
150
+ };
112
151
  /** Fetch all the devices we've to send a message to */
113
152
  const getUSyncDevices = async (jids, useCache, ignoreZeroDevices) => {
114
153
  var _a;
@@ -116,66 +155,46 @@ const makeMessagesSocket = (config) => {
116
155
  if (!useCache) {
117
156
  logger.debug('not using cache for devices');
118
157
  }
119
- const users = [];
158
+ const toFetch = [];
120
159
  jids = Array.from(new Set(jids));
121
160
  for (let jid of jids) {
122
161
  const user = (_a = (0, WABinary_1.jidDecode)(jid)) === null || _a === void 0 ? void 0 : _a.user;
123
162
  jid = (0, WABinary_1.jidNormalizedUser)(jid);
124
- const devices = userDevicesCache.get(user);
125
- if (devices && useCache) {
126
- deviceResults.push(...devices);
127
- logger.trace({ user }, 'using cache for devices');
163
+ if (useCache) {
164
+ const devices = userDevicesCache.get(user);
165
+ if (devices) {
166
+ deviceResults.push(...devices);
167
+ logger.trace({ user }, 'using cache for devices');
168
+ }
169
+ else {
170
+ toFetch.push(jid);
171
+ }
128
172
  }
129
173
  else {
130
- users.push({ tag: 'user', attrs: { jid } });
174
+ toFetch.push(jid);
131
175
  }
132
176
  }
133
- if (!users.length) {
177
+ if (!toFetch.length) {
134
178
  return deviceResults;
135
179
  }
136
- const iq = {
137
- tag: 'iq',
138
- attrs: {
139
- to: WABinary_1.S_WHATSAPP_NET,
140
- type: 'get',
141
- xmlns: 'usync',
142
- },
143
- content: [
144
- {
145
- tag: 'usync',
146
- attrs: {
147
- sid: generateMessageTag(),
148
- mode: 'query',
149
- last: 'true',
150
- index: '0',
151
- context: 'message',
152
- },
153
- content: [
154
- {
155
- tag: 'query',
156
- attrs: {},
157
- content: [
158
- {
159
- tag: 'devices',
160
- attrs: { version: '2' }
161
- }
162
- ]
163
- },
164
- { tag: 'list', attrs: {}, content: users }
165
- ]
166
- },
167
- ],
168
- };
169
- const result = await query(iq);
170
- const extracted = (0, Utils_1.extractDeviceJids)(result, authState.creds.me.id, ignoreZeroDevices);
171
- const deviceMap = {};
172
- for (const item of extracted) {
173
- deviceMap[item.user] = deviceMap[item.user] || [];
174
- deviceMap[item.user].push(item);
175
- deviceResults.push(item);
176
- }
177
- for (const key in deviceMap) {
178
- userDevicesCache.set(key, deviceMap[key]);
180
+ const query = new WAUSync_1.USyncQuery()
181
+ .withContext('message')
182
+ .withDeviceProtocol();
183
+ for (const jid of toFetch) {
184
+ query.withUser(new WAUSync_1.USyncUser().withId(jid));
185
+ }
186
+ const result = await sock.executeUSyncQuery(query);
187
+ if (result) {
188
+ const extracted = (0, Utils_1.extractDeviceJids)(result === null || result === void 0 ? void 0 : result.list, authState.creds.me.id, ignoreZeroDevices);
189
+ const deviceMap = {};
190
+ for (const item of extracted) {
191
+ deviceMap[item.user] = deviceMap[item.user] || [];
192
+ deviceMap[item.user].push(item);
193
+ deviceResults.push(item);
194
+ }
195
+ for (const key in deviceMap) {
196
+ userDevicesCache.set(key, deviceMap[key]);
197
+ }
179
198
  }
180
199
  return deviceResults;
181
200
  };
@@ -487,7 +506,7 @@ const makeMessagesSocket = (config) => {
487
506
  content: [{
488
507
  tag: 'native_flow',
489
508
  attrs: {
490
- name: 'quick_reply',
509
+ name: 'quick_reply'
491
510
  }
492
511
  }]
493
512
  }]
@@ -513,16 +532,14 @@ const makeMessagesSocket = (config) => {
513
532
  stanza.content.push(botNode);
514
533
  }
515
534
  }
516
- const Msg = (0, Utils_1.normalizeMessageContent)(message) || null;
517
- const buttonType = getButtonType(Msg);
518
- if (buttonType) {
535
+ if (message && message.listMessage) {
519
536
  stanza.content.push({
520
537
  tag: 'biz',
521
538
  attrs: {},
522
539
  content: [
523
540
  {
524
- tag: buttonType,
525
- attrs: getButtonArgs(message),
541
+ tag: 'list',
542
+ attrs: getButtonArgs(message)
526
543
  }
527
544
  ]
528
545
  });
@@ -536,7 +553,8 @@ const makeMessagesSocket = (config) => {
536
553
  const filterNativeNode = (nodeContent) => {
537
554
  if (Array.isArray(nodeContent)) {
538
555
  return nodeContent.filter((item) => {
539
- if (item.tag === 'biz' && (item.content && item.content.filter((tag) => { tag.tag === 'interactive' && tag.attrs.type === 'native_flow' && tag.attrs.v === '1'; }))) {
556
+ var _a, _b, _c, _d, _e, _f, _g, _h;
557
+ if (item.tag === 'biz' && ((_a = item === null || item === void 0 ? void 0 : item.content[0]) === null || _a === void 0 ? void 0 : _a.tag) === 'interactive' && ((_c = (_b = item === null || item === void 0 ? void 0 : item.content[0]) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.type) === 'native_flow' && ((_e = (_d = item === null || item === void 0 ? void 0 : item.content[0]) === null || _d === void 0 ? void 0 : _d.content[0]) === null || _e === void 0 ? void 0 : _e.tag) === 'native_flow' && ((_h = (_g = (_f = item === null || item === void 0 ? void 0 : item.content[0]) === null || _f === void 0 ? void 0 : _f.content[0]) === null || _g === void 0 ? void 0 : _g.attrs) === null || _h === void 0 ? void 0 : _h.name) === 'quick_reply') {
540
558
  return false;
541
559
  }
542
560
  return true;
@@ -635,14 +653,6 @@ const makeMessagesSocket = (config) => {
635
653
  return 'url';
636
654
  }
637
655
  };
638
- const getButtonType = (message) => {
639
- if (message.listMessage) {
640
- return 'list';
641
- }
642
- else if (message.listResponseMessage) {
643
- return 'list_response';
644
- }
645
- };
646
656
  const getButtonArgs = (message) => {
647
657
  if (message.templateMessage) {
648
658
  // TODO: Add attributes
@@ -700,6 +710,7 @@ const makeMessagesSocket = (config) => {
700
710
  getUSyncDevices,
701
711
  sendPeerDataOperationMessage,
702
712
  createParticipantNodes,
713
+ profilePictureUrl,
703
714
  waUploadToServer,
704
715
  fetchPrivacySettings,
705
716
  updateMediaMessage: async (message) => {
@@ -855,10 +866,10 @@ const makeMessagesSocket = (config) => {
855
866
  }
856
867
  }, { userJid, ...options });
857
868
  await relayMessage(jid, album.message, { messageId: album.key.id });
869
+ let mediaHandle;
870
+ let msg;
858
871
  for (const i in medias) {
859
872
  const media = medias[i];
860
- let mediaHandle;
861
- let msg;
862
873
  if (media.image) {
863
874
  msg = await (0, Utils_1.generateWAMessage)(jid, {
864
875
  image: media.image,
@@ -889,19 +900,21 @@ const makeMessagesSocket = (config) => {
889
900
  ...options,
890
901
  });
891
902
  }
892
- msg.message.messageContextInfo = {
893
- messageAssociation: {
894
- associationType: 1,
895
- parentMessageKey: album.key
896
- }
897
- };
903
+ if (msg) {
904
+ msg.message.messageContextInfo = {
905
+ messageAssociation: {
906
+ associationType: 1,
907
+ parentMessageKey: album.key
908
+ }
909
+ };
910
+ }
898
911
  await relayMessage(jid, msg.message, { messageId: msg.key.id });
899
912
  await (0, Utils_1.delay)(time);
900
913
  }
901
914
  return album;
902
915
  },
903
916
  sendMessage: async (jid, content, options = {}) => {
904
- var _a, _b;
917
+ var _a, _b, _c;
905
918
  const userJid = authState.creds.me.id;
906
919
  if (typeof content === 'object' &&
907
920
  'disappearingMessagesInChat' in content &&
@@ -915,9 +928,24 @@ const makeMessagesSocket = (config) => {
915
928
  }
916
929
  else {
917
930
  let mediaHandle;
931
+ const { server } = (0, WABinary_1.jidDecode)(jid);
932
+ const isGroup = server === 'g.us';
933
+ let eph;
934
+ if (isGroup) {
935
+ const disappearingNode = await groupQuery(jid, 'get', [
936
+ {
937
+ tag: 'query',
938
+ attrs: { request: 'interactive' }
939
+ }
940
+ ]);
941
+ const group = (0, WABinary_1.getBinaryNodeChild)(disappearingNode, 'group');
942
+ const expiration = (0, WABinary_1.getBinaryNodeChild)(group, 'ephemeral');
943
+ eph = (_a = expiration === null || expiration === void 0 ? void 0 : expiration.attrs) === null || _a === void 0 ? void 0 : _a.expiration;
944
+ }
918
945
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
919
946
  logger,
920
947
  userJid,
948
+ ephemeralExpiration: (options.ephemeralExpiration && options.ephemeralExpiration > 0) ? options.ephemeralExpiration : eph,
921
949
  getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
922
950
  thumbnailWidth: linkPreviewImageThumbnailWidth,
923
951
  fetchOpts: {
@@ -949,7 +977,7 @@ const makeMessagesSocket = (config) => {
949
977
  // required for delete
950
978
  if (isDeleteMsg) {
951
979
  // if the chat is a group, and I am not the author, then delete the message as an admin
952
- if (((0, WABinary_1.isJidGroup)((_a = content.delete) === null || _a === void 0 ? void 0 : _a.remoteJid) && !((_b = content.delete) === null || _b === void 0 ? void 0 : _b.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
980
+ if (((0, WABinary_1.isJidGroup)((_b = content.delete) === null || _b === void 0 ? void 0 : _b.remoteJid) && !((_c = content.delete) === null || _c === void 0 ? void 0 : _c.fromMe)) || (0, WABinary_1.isJidNewsLetter)(jid)) {
953
981
  additionalAttributes.edit = '8';
954
982
  }
955
983
  else {