@genuxofficial/baileys 1.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +5 -1
  2. package/WAProto/WAProto.proto +1385 -96
  3. package/WAProto/index.d.ts +19244 -2787
  4. package/WAProto/index.js +138202 -74217
  5. package/engine-requirements.js +10 -0
  6. package/lib/Defaults/baileys-version.json +1 -1
  7. package/lib/Defaults/index.js +1 -0
  8. package/lib/Socket/business.d.ts +47 -17
  9. package/lib/Socket/chats.d.ts +10 -9
  10. package/lib/Socket/chats.js +36 -16
  11. package/lib/Socket/groups.d.ts +12 -11
  12. package/lib/Socket/groups.js +16 -3
  13. package/lib/Socket/index.d.ts +52 -22
  14. package/lib/Socket/messages-recv.d.ts +46 -15
  15. package/lib/Socket/messages-recv.js +158 -23
  16. package/lib/Socket/messages-send.d.ts +39 -11
  17. package/lib/Socket/messages-send.js +188 -22
  18. package/lib/Socket/newsletter.d.ts +137 -0
  19. package/lib/Socket/newsletter.js +256 -0
  20. package/lib/Socket/socket.d.ts +4 -4
  21. package/lib/Socket/socket.js +25 -12
  22. package/lib/Socket/usync.d.ts +5 -5
  23. package/lib/Store/index.d.ts +1 -2
  24. package/lib/Store/index.js +1 -3
  25. package/lib/Store/make-in-memory-store.js +14 -5
  26. package/lib/Types/Chat.d.ts +6 -5
  27. package/lib/Types/Events.d.ts +27 -0
  28. package/lib/Types/GroupMetadata.d.ts +6 -0
  29. package/lib/Types/Label.d.ts +0 -11
  30. package/lib/Types/Message.d.ts +150 -12
  31. package/lib/Types/Message.js +0 -2
  32. package/lib/Types/Newsletter.d.ts +79 -0
  33. package/lib/Types/Newsletter.js +18 -0
  34. package/lib/Types/Socket.d.ts +8 -3
  35. package/lib/Types/index.d.ts +1 -0
  36. package/lib/Types/index.js +1 -0
  37. package/lib/Utils/auth-utils.d.ts +1 -1
  38. package/lib/Utils/auth-utils.js +3 -4
  39. package/lib/Utils/business.js +15 -3
  40. package/lib/Utils/chat-utils.js +0 -16
  41. package/lib/Utils/crypto.js +6 -4
  42. package/lib/Utils/decode-wa-message.d.ts +5 -3
  43. package/lib/Utils/decode-wa-message.js +158 -31
  44. package/lib/Utils/event-buffer.js +1 -3
  45. package/lib/Utils/generics.d.ts +3 -2
  46. package/lib/Utils/generics.js +16 -36
  47. package/lib/Utils/history.d.ts +2 -2
  48. package/lib/Utils/link-preview.d.ts +1 -1
  49. package/lib/Utils/link-preview.js +1 -24
  50. package/lib/Utils/make-mutex.js +0 -1
  51. package/lib/Utils/messages-media.d.ts +14 -5
  52. package/lib/Utils/messages-media.js +130 -69
  53. package/lib/Utils/messages.d.ts +1 -1
  54. package/lib/Utils/messages.js +309 -57
  55. package/lib/Utils/noise-handler.d.ts +1 -1
  56. package/lib/Utils/process-message.js +0 -1
  57. package/lib/Utils/use-multi-file-auth-state.js +44 -13
  58. package/lib/Utils/validate-connection.js +1 -3
  59. package/lib/WABinary/decode.js +3 -2
  60. package/lib/WABinary/encode.js +13 -5
  61. package/lib/WABinary/generic-utils.d.ts +3 -5
  62. package/lib/WABinary/generic-utils.js +34 -19
  63. package/lib/WABinary/jid-utils.d.ts +12 -3
  64. package/lib/WABinary/jid-utils.js +29 -4
  65. package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +21 -12
  66. package/lib/WAUSync/Protocols/USyncStatusProtocol.js +3 -3
  67. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  68. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +53 -0
  69. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  70. package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
  71. package/lib/WAUSync/USyncQuery.d.ts +2 -0
  72. package/lib/WAUSync/USyncQuery.js +10 -0
  73. package/lib/WAUSync/USyncUser.d.ts +2 -0
  74. package/lib/WAUSync/USyncUser.js +4 -0
  75. package/lib/index.d.ts +2 -1
  76. package/lib/index.js +3 -1
  77. package/package.json +20 -12
  78. package/WAProto/GenerateStatics.sh +0 -4
  79. package/lib/Store/make-cache-manager-store.d.ts +0 -14
  80. package/lib/Store/make-cache-manager-store.js +0 -83
@@ -17,32 +17,61 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
17
17
  deleted: number;
18
18
  }>;
19
19
  productUpdate: (productId: string, update: import("../Types").ProductUpdate) => Promise<import("../Types").Product>;
20
- sendMessageAck: ({ tag, attrs, content }: import("..").BinaryNode, errorCode?: number | undefined) => Promise<void>;
21
- sendRetryRequest: (node: import("..").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
20
+ sendMessageAck: ({ tag, attrs, content }: import("../index").BinaryNode, errorCode?: number | undefined) => Promise<void>;
21
+ sendRetryRequest: (node: import("../index").BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
22
22
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
23
- fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAProto.IMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
24
- requestPlaceholderResend: (messageKey: import("../Types").WAProto.IMessageKey) => Promise<string | undefined>;
25
- getPrivacyTokens: (jids: string[]) => Promise<import("..").BinaryNode>;
23
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
24
+ callId: string;
25
+ toJid: string;
26
+ isVideo: boolean;
27
+ }>;
28
+ fetchMessageHistory: (count: number, oldestMsgKey: import("../Types").WAMessageKey, oldestMsgTimestamp: number | import("long").Long) => Promise<string>;
29
+ requestPlaceholderResend: (messageKey: import("../Types").WAMessageKey) => Promise<string | undefined>;
30
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
26
31
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
27
32
  relayMessage: (jid: string, message: import("../Types").WAProto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: import("../Types").MessageRelayOptions) => Promise<string>;
28
33
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: import("../Types").MessageReceiptType) => Promise<void>;
29
- sendReceipts: (keys: import("../Types").WAProto.IMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
30
- readMessages: (keys: import("../Types").WAProto.IMessageKey[]) => Promise<void>;
34
+ sendReceipts: (keys: import("../Types").WAMessageKey[], type: import("../Types").MessageReceiptType) => Promise<void>;
35
+ getButtonArgs: (message: import("../Types").WAProto.IMessage) => {
36
+ [key: string]: string;
37
+ };
38
+ readMessages: (keys: import("../Types").WAMessageKey[]) => Promise<void>;
31
39
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
32
40
  waUploadToServer: import("../Types").WAMediaUploadFunction;
33
41
  fetchPrivacySettings: (force?: boolean) => Promise<{
34
42
  [_: string]: string;
35
43
  }>;
36
- sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
44
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../index").JidWithDevice[]>;
37
45
  createParticipantNodes: (jids: string[], message: import("../Types").WAProto.IMessage, extraAttrs?: {
38
46
  [key: string]: string;
39
47
  } | undefined) => Promise<{
40
- nodes: import("..").BinaryNode[];
48
+ nodes: import("../index").BinaryNode[];
41
49
  shouldIncludeDeviceIdentity: boolean;
42
50
  }>;
43
- getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("..").JidWithDevice[]>;
51
+ sendPeerDataOperationMessage: (pdoMessage: import("../Types").WAProto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
44
52
  updateMediaMessage: (message: import("../Types").WAProto.IWebMessageInfo) => Promise<import("../Types").WAProto.IWebMessageInfo>;
45
53
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<import("../Types").WAProto.WebMessageInfo | undefined>;
54
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
55
+ duration: string;
56
+ }>;
57
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
58
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
59
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
60
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
61
+ newsletterRemovePicture: (jid: string) => Promise<void>;
62
+ newsletterUnfollow: (jid: string) => Promise<void>;
63
+ newsletterFollow: (jid: string) => Promise<void>;
64
+ newsletterUnmute: (jid: string) => Promise<void>;
65
+ newsletterMute: (jid: string) => Promise<void>;
66
+ newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
67
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
68
+ newsletterAdminCount: (jid: string) => Promise<number>;
69
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
70
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
71
+ newsletterDelete: (jid: string) => Promise<void>;
72
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
73
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
74
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
46
75
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
47
76
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
48
77
  groupLeave: (id: string) => Promise<void>;
@@ -57,14 +86,14 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
57
86
  groupParticipantsUpdate: (jid: string, participants: string[], action: import("../Types").ParticipantAction) => Promise<{
58
87
  status: string;
59
88
  jid: string;
60
- content: import("..").BinaryNode;
89
+ content: import("../index").BinaryNode;
61
90
  }[]>;
62
91
  groupUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
63
92
  groupInviteCode: (jid: string) => Promise<string | undefined>;
64
93
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
65
94
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
66
95
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
67
- groupAcceptInviteV4: (key: string | import("../Types").WAProto.IMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<string>;
96
+ groupAcceptInviteV4: (key: string | import("../Types").WAMessageKey, inviteMessage: import("../Types").WAProto.Message.IGroupInviteMessage) => Promise<any>;
68
97
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
69
98
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
70
99
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -73,6 +102,7 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
73
102
  groupFetchAllParticipating: () => Promise<{
74
103
  [_: string]: import("../Types").GroupMetadata;
75
104
  }>;
105
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
76
106
  processingMutex: {
77
107
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
78
108
  };
@@ -84,10 +114,11 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
84
114
  onWhatsApp: (...jids: string[]) => Promise<{
85
115
  jid: string;
86
116
  exists: unknown;
117
+ lid: unknown;
87
118
  }[] | undefined>;
88
119
  fetchBlocklist: () => Promise<string[]>;
89
- fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
90
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
120
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
121
+ fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
91
122
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
92
123
  removeProfilePicture: (jid: string) => Promise<void>;
93
124
  updateProfileStatus: (status: string) => Promise<void>;
@@ -106,7 +137,6 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
106
137
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
107
138
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
108
139
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
109
- addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
110
140
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
111
141
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
112
142
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -115,9 +145,9 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
115
145
  id: string;
116
146
  fromMe?: boolean | undefined;
117
147
  }[], star: boolean) => Promise<void>;
118
- executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
148
+ executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
119
149
  type: "md";
120
- ws: import("./Client").WebSocketClient;
150
+ ws: import("./Client/websocket").WebSocketClient;
121
151
  ev: import("../Types").BaileysEventEmitter & {
122
152
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
123
153
  buffer(): void;
@@ -132,18 +162,18 @@ declare const makeWASocket: (config: UserFacingSocketConfig) => {
132
162
  signalRepository: import("../Types").SignalRepository;
133
163
  user: import("../Types").Contact | undefined;
134
164
  generateMessageTag: () => string;
135
- query: (node: import("..").BinaryNode, timeoutMs?: number | undefined) => Promise<import("..").BinaryNode>;
136
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
165
+ query: (node: import("../index").BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
166
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
137
167
  waitForSocketOpen: () => Promise<void>;
138
168
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
139
- sendNode: (frame: import("..").BinaryNode) => Promise<void>;
169
+ sendNode: (frame: import("../index").BinaryNode) => Promise<void>;
140
170
  logout: (msg?: string | undefined) => Promise<void>;
141
171
  end: (error: Error | undefined) => void;
142
172
  onUnexpectedError: (err: Error | import("@hapi/boom").Boom<any>, msg: string) => void;
143
173
  uploadPreKeys: (count?: number) => Promise<void>;
144
174
  uploadPreKeysToServerIfRequired: () => Promise<void>;
145
- requestPairingCode: (phoneNumber: string) => Promise<string>;
175
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
146
176
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
147
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<import("..").BinaryNode>;
177
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
148
178
  };
149
179
  export default makeWASocket;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  /// <reference types="node" />
3
+ import Long = require('long');
3
4
  import { Boom } from '@hapi/boom';
4
5
  import { proto } from '../../WAProto';
5
6
  import { MessageReceiptType, MessageRelayOptions, SocketConfig, WAMessageKey } from '../Types';
@@ -8,29 +9,58 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
8
9
  sendMessageAck: ({ tag, attrs, content }: BinaryNode, errorCode?: number) => Promise<void>;
9
10
  sendRetryRequest: (node: BinaryNode, forceIncludeKeys?: boolean) => Promise<void>;
10
11
  rejectCall: (callId: string, callFrom: string) => Promise<void>;
12
+ offerCall: (toJid: string, isVideo?: boolean) => Promise<{
13
+ callId: string;
14
+ toJid: string;
15
+ isVideo: boolean;
16
+ }>;
11
17
  fetchMessageHistory: (count: number, oldestMsgKey: WAMessageKey, oldestMsgTimestamp: number | Long) => Promise<string>;
12
18
  requestPlaceholderResend: (messageKey: WAMessageKey) => Promise<string | undefined>;
13
- getPrivacyTokens: (jids: string[]) => Promise<BinaryNode>;
19
+ getPrivacyTokens: (jids: string[]) => Promise<any>;
14
20
  assertSessions: (jids: string[], force: boolean) => Promise<boolean>;
15
21
  relayMessage: (jid: string, message: proto.IMessage, { messageId: msgId, participant, additionalAttributes, additionalNodes, useUserDevicesCache, useCachedGroupMetadata, statusJidList }: MessageRelayOptions) => Promise<string>;
16
22
  sendReceipt: (jid: string, participant: string | undefined, messageIds: string[], type: MessageReceiptType) => Promise<void>;
17
- sendReceipts: (keys: proto.IMessageKey[], type: MessageReceiptType) => Promise<void>;
18
- readMessages: (keys: proto.IMessageKey[]) => Promise<void>;
23
+ sendReceipts: (keys: WAMessageKey[], type: MessageReceiptType) => Promise<void>;
24
+ getButtonArgs: (message: proto.IMessage) => {
25
+ [key: string]: string;
26
+ };
27
+ readMessages: (keys: WAMessageKey[]) => Promise<void>;
19
28
  refreshMediaConn: (forceGet?: boolean) => Promise<import("../Types").MediaConnInfo>;
20
29
  waUploadToServer: import("../Types").WAMediaUploadFunction;
21
30
  fetchPrivacySettings: (force?: boolean) => Promise<{
22
31
  [_: string]: string;
23
32
  }>;
24
- sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
33
+ getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
25
34
  createParticipantNodes: (jids: string[], message: proto.IMessage, extraAttrs?: {
26
35
  [key: string]: string;
27
36
  } | undefined) => Promise<{
28
37
  nodes: BinaryNode[];
29
38
  shouldIncludeDeviceIdentity: boolean;
30
39
  }>;
31
- getUSyncDevices: (jids: string[], useCache: boolean, ignoreZeroDevices: boolean) => Promise<import("../WABinary").JidWithDevice[]>;
40
+ sendPeerDataOperationMessage: (pdoMessage: proto.Message.IPeerDataOperationRequestMessage) => Promise<string>;
32
41
  updateMediaMessage: (message: proto.IWebMessageInfo) => Promise<proto.IWebMessageInfo>;
33
42
  sendMessage: (jid: string, content: import("../Types").AnyMessageContent, options?: import("../Types").MiscMessageGenerationOptions) => Promise<proto.WebMessageInfo | undefined>;
43
+ subscribeNewsletterUpdates: (jid: string) => Promise<{
44
+ duration: string;
45
+ }>;
46
+ newsletterReactionMode: (jid: string, mode: import("../Types").NewsletterReactionMode) => Promise<void>;
47
+ newsletterUpdateDescription: (jid: string, description?: string | undefined) => Promise<void>;
48
+ newsletterUpdateName: (jid: string, name: string) => Promise<void>;
49
+ newsletterUpdatePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
50
+ newsletterRemovePicture: (jid: string) => Promise<void>;
51
+ newsletterUnfollow: (jid: string) => Promise<void>;
52
+ newsletterFollow: (jid: string) => Promise<void>;
53
+ newsletterUnmute: (jid: string) => Promise<void>;
54
+ newsletterMute: (jid: string) => Promise<void>;
55
+ newsletterCreate: (name: string, description?: string | undefined, picture?: import("../Types").WAMediaUpload | undefined) => Promise<import("../Types").NewsletterMetadata>;
56
+ newsletterMetadata: (type: "invite" | "jid", key: string, role?: import("../Types").NewsletterViewRole | undefined) => Promise<import("../Types").NewsletterMetadata>;
57
+ newsletterAdminCount: (jid: string) => Promise<number>;
58
+ newsletterChangeOwner: (jid: string, user: string) => Promise<void>;
59
+ newsletterDemote: (jid: string, user: string) => Promise<void>;
60
+ newsletterDelete: (jid: string) => Promise<void>;
61
+ newsletterReactMessage: (jid: string, server_id: string, code?: string | undefined) => Promise<void>;
62
+ newsletterFetchMessages: (type: "invite" | "jid", key: string, count: number, after?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
63
+ newsletterFetchUpdates: (jid: string, count: number, after?: number | undefined, since?: number | undefined) => Promise<import("../Types").NewsletterFetchedUpdate[]>;
34
64
  groupMetadata: (jid: string) => Promise<import("../Types").GroupMetadata>;
35
65
  groupCreate: (subject: string, participants: string[]) => Promise<import("../Types").GroupMetadata>;
36
66
  groupLeave: (id: string) => Promise<void>;
@@ -52,7 +82,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
52
82
  groupRevokeInvite: (jid: string) => Promise<string | undefined>;
53
83
  groupAcceptInvite: (code: string) => Promise<string | undefined>;
54
84
  groupRevokeInviteV4: (groupJid: string, invitedJid: string) => Promise<boolean>;
55
- groupAcceptInviteV4: (key: string | proto.IMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<string>;
85
+ groupAcceptInviteV4: (key: string | WAMessageKey, inviteMessage: proto.Message.IGroupInviteMessage) => Promise<any>;
56
86
  groupGetInviteInfo: (code: string) => Promise<import("../Types").GroupMetadata>;
57
87
  groupToggleEphemeral: (jid: string, ephemeralExpiration: number) => Promise<void>;
58
88
  groupSettingUpdate: (jid: string, setting: "announcement" | "locked" | "not_announcement" | "unlocked") => Promise<void>;
@@ -61,6 +91,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
61
91
  groupFetchAllParticipating: () => Promise<{
62
92
  [_: string]: import("../Types").GroupMetadata;
63
93
  }>;
94
+ getBotListV2: () => Promise<import("../Types").BotListInfo[]>;
64
95
  processingMutex: {
65
96
  mutex<T>(code: () => T | Promise<T>): Promise<T>;
66
97
  };
@@ -72,10 +103,11 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
72
103
  onWhatsApp: (...jids: string[]) => Promise<{
73
104
  jid: string;
74
105
  exists: unknown;
106
+ lid: unknown;
75
107
  }[] | undefined>;
76
108
  fetchBlocklist: () => Promise<string[]>;
77
- fetchStatus: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
78
- fetchDisappearingDuration: (...jids: string[]) => Promise<import("..").USyncQueryResultList[] | undefined>;
109
+ fetchDisappearingDuration: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
110
+ fetchStatus: (...jids: string[]) => Promise<import("../index").USyncQueryResultList[] | undefined>;
79
111
  updateProfilePicture: (jid: string, content: import("../Types").WAMediaUpload) => Promise<void>;
80
112
  removeProfilePicture: (jid: string) => Promise<void>;
81
113
  updateProfileStatus: (status: string) => Promise<void>;
@@ -94,7 +126,6 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
94
126
  resyncAppState: (collections: readonly ("critical_block" | "critical_unblock_low" | "regular_high" | "regular_low" | "regular")[], isInitialSync: boolean) => Promise<void>;
95
127
  chatModify: (mod: import("../Types").ChatModification, jid: string) => Promise<void>;
96
128
  cleanDirtyBits: (type: "account_sync" | "groups", fromTimestamp?: string | number | undefined) => Promise<void>;
97
- addLabel: (jid: string, labels: import("../Types/Label").LabelActionBody) => Promise<void>;
98
129
  addChatLabel: (jid: string, labelId: string) => Promise<void>;
99
130
  removeChatLabel: (jid: string, labelId: string) => Promise<void>;
100
131
  addMessageLabel: (jid: string, messageId: string, labelId: string) => Promise<void>;
@@ -103,9 +134,9 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
103
134
  id: string;
104
135
  fromMe?: boolean | undefined;
105
136
  }[], star: boolean) => Promise<void>;
106
- executeUSyncQuery: (usyncQuery: import("..").USyncQuery) => Promise<import("..").USyncQueryResult | undefined>;
137
+ executeUSyncQuery: (usyncQuery: import("../index").USyncQuery) => Promise<import("../index").USyncQueryResult | undefined>;
107
138
  type: "md";
108
- ws: import("./Client").WebSocketClient;
139
+ ws: import("./Client/websocket").WebSocketClient;
109
140
  ev: import("../Types").BaileysEventEmitter & {
110
141
  process(handler: (events: Partial<import("../Types").BaileysEventMap>) => void | Promise<void>): () => void;
111
142
  buffer(): void;
@@ -120,8 +151,8 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
120
151
  signalRepository: import("../Types").SignalRepository;
121
152
  user: import("../Types").Contact | undefined;
122
153
  generateMessageTag: () => string;
123
- query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<BinaryNode>;
124
- waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<T_2>;
154
+ query: (node: BinaryNode, timeoutMs?: number | undefined) => Promise<any>;
155
+ waitForMessage: <T_2>(msgId: string, timeoutMs?: number | undefined) => Promise<any>;
125
156
  waitForSocketOpen: () => Promise<void>;
126
157
  sendRawMessage: (data: Uint8Array | Buffer) => Promise<void>;
127
158
  sendNode: (frame: BinaryNode) => Promise<void>;
@@ -130,7 +161,7 @@ export declare const makeMessagesRecvSocket: (config: SocketConfig) => {
130
161
  onUnexpectedError: (err: Error | Boom<any>, msg: string) => void;
131
162
  uploadPreKeys: (count?: number) => Promise<void>;
132
163
  uploadPreKeysToServerIfRequired: () => Promise<void>;
133
- requestPairingCode: (phoneNumber: string) => Promise<string>;
164
+ requestPairingCode: (phoneNumber: string, pairCode: string) => Promise<string>;
134
165
  waitForConnectionUpdate: (check: (u: Partial<import("../Types").ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number | undefined) => Promise<void>;
135
- sendWAMBuffer: (wamBuffer: Buffer) => Promise<BinaryNode>;
166
+ sendWAMBuffer: (wamBuffer: Buffer) => Promise<any>;
136
167
  };
@@ -4,9 +4,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.makeMessagesRecvSocket = void 0;
7
- const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
8
7
  const boom_1 = require("@hapi/boom");
9
8
  const crypto_1 = require("crypto");
9
+ const node_cache_1 = __importDefault(require("@cacheable/node-cache"));
10
10
  const WAProto_1 = require("../../WAProto");
11
11
  const Defaults_1 = require("../Defaults");
12
12
  const Types_1 = require("../Types");
@@ -16,9 +16,9 @@ const WABinary_1 = require("../WABinary");
16
16
  const groups_1 = require("./groups");
17
17
  const messages_send_1 = require("./messages-send");
18
18
  const makeMessagesRecvSocket = (config) => {
19
- const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, shouldIgnoreJid } = config;
19
+ const { logger, retryRequestDelayMs, maxMsgRetryCount, getMessage, ignoreMsgLoading, shouldIgnoreJid } = config;
20
20
  const sock = (0, messages_send_1.makeMessagesSocket)(config);
21
- const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, sendPeerDataOperationMessage, } = sock;
21
+ const { ev, authState, ws, processingMutex, signalRepository, query, upsertMessage, resyncAppState, onUnexpectedError, assertSessions, sendNode, relayMessage, sendReceipt, uploadPreKeys, createParticipantNodes, getUSyncDevices, sendPeerDataOperationMessage, } = sock;
22
22
  /** this mutex ensures that each retryRequest will wait for the previous one to finish */
23
23
  const retryMutex = (0, make_mutex_1.makeMutex)();
24
24
  const msgRetryCache = config.msgRetryCounterCache || new node_cache_1.default({
@@ -61,6 +61,64 @@ const makeMessagesRecvSocket = (config) => {
61
61
  logger.debug({ recv: { tag, attrs }, sent: stanza.attrs }, 'sent ack');
62
62
  await sendNode(stanza);
63
63
  };
64
+ const offerCall = async (toJid, isVideo = false) => {
65
+ const callId = (0, crypto_1.randomBytes)(16).toString('hex').toUpperCase().substring(0, 64);
66
+ const offerContent = [];
67
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '16000' }, content: undefined });
68
+ offerContent.push({ tag: 'audio', attrs: { enc: 'opus', rate: '8000' }, content: undefined });
69
+ if (isVideo) {
70
+ offerContent.push({
71
+ tag: 'video',
72
+ attrs: {
73
+ orientation: '0',
74
+ 'screen_width': '1920',
75
+ 'screen_height': '1080',
76
+ 'device_orientation': '0',
77
+ enc: 'vp8',
78
+ dec: 'vp8',
79
+ }
80
+ });
81
+ }
82
+ offerContent.push({ tag: 'net', attrs: { medium: '3' }, content: undefined });
83
+ offerContent.push({ tag: 'capability', attrs: { ver: '1' }, content: new Uint8Array([1, 4, 255, 131, 207, 4]) });
84
+ offerContent.push({ tag: 'encopt', attrs: { keygen: '2' }, content: undefined });
85
+ const encKey = (0, crypto_1.randomBytes)(32);
86
+ const devices = (await getUSyncDevices([toJid], true, false)).map(({ user, device }) => (0, WABinary_1.jidEncode)(user, 's.whatsapp.net', device));
87
+ await assertSessions(devices, true);
88
+ const { nodes: destinations, shouldIncludeDeviceIdentity } = await createParticipantNodes(devices, {
89
+ call: {
90
+ callKey: encKey
91
+ }
92
+ });
93
+ offerContent.push({ tag: 'destination', attrs: {}, content: destinations });
94
+ if (shouldIncludeDeviceIdentity) {
95
+ offerContent.push({
96
+ tag: 'device-identity',
97
+ attrs: {},
98
+ content: (0, Utils_1.encodeSignedDeviceIdentity)(authState.creds.account, true)
99
+ });
100
+ }
101
+ const stanza = ({
102
+ tag: 'call',
103
+ attrs: {
104
+ to: toJid,
105
+ },
106
+ content: [{
107
+ tag: 'offer',
108
+ attrs: {
109
+ 'call-id': callId,
110
+ 'call-creator': authState.creds.me.id,
111
+ },
112
+ content: offerContent,
113
+ }],
114
+ });
115
+ await query(stanza);
116
+ return {
117
+ callId,
118
+ toJid,
119
+ isVideo,
120
+ };
121
+ };
64
122
  const rejectCall = async (callId, callFrom) => {
65
123
  const stanza = ({
66
124
  tag: 'call',
@@ -126,7 +184,8 @@ const makeMessagesRecvSocket = (config) => {
126
184
  ]
127
185
  };
128
186
  if (node.attrs.recipient) {
129
- receipt.attrs.recipient = node.attrs.recipient;
187
+ //Fixes problem with retry that is never done when it is @bot
188
+ receipt.attrs.recipient = (0, WABinary_1.getBotJid)(node.attrs.recipient);
130
189
  }
131
190
  if (node.attrs.participant) {
132
191
  receipt.attrs.participant = node.attrs.participant;
@@ -272,10 +331,57 @@ const makeMessagesRecvSocket = (config) => {
272
331
  msg.messageStubType = Types_1.WAMessageStubType.GROUP_MEMBERSHIP_JOIN_APPROVAL_REQUEST_NON_ADMIN_ADD;
273
332
  msg.messageStubParameters = [participantJid, isDenied ? 'revoked' : 'rejected'];
274
333
  break;
334
+ break;
335
+ default:
336
+ // console.log("BAILEYS-DEBUG:", JSON.stringify({ ...child, content: Buffer.isBuffer(child.content) ? child.content.toString() : child.content, participant }, null, 2))
337
+ }
338
+ };
339
+ const handleNewsletterNotification = (id, node) => {
340
+ const messages = (0, WABinary_1.getBinaryNodeChild)(node, 'messages');
341
+ const message = (0, WABinary_1.getBinaryNodeChild)(messages, 'message');
342
+ const server_id = message.attrs.server_id;
343
+ const reactionsList = (0, WABinary_1.getBinaryNodeChild)(message, 'reactions');
344
+ const viewsList = (0, WABinary_1.getBinaryNodeChildren)(message, 'views_count');
345
+ if (reactionsList) {
346
+ const reactions = (0, WABinary_1.getBinaryNodeChildren)(reactionsList, 'reaction');
347
+ if (reactions.length === 0) {
348
+ ev.emit('newsletter.reaction', { id, server_id, reaction: { removed: true } });
349
+ }
350
+ reactions.forEach(item => {
351
+ var _a, _b;
352
+ ev.emit('newsletter.reaction', { id, server_id, reaction: { code: (_a = item.attrs) === null || _a === void 0 ? void 0 : _a.code, count: +((_b = item.attrs) === null || _b === void 0 ? void 0 : _b.count) } });
353
+ });
354
+ }
355
+ if (viewsList.length) {
356
+ viewsList.forEach(item => {
357
+ ev.emit('newsletter.view', { id, server_id, count: +item.attrs.count });
358
+ });
359
+ }
360
+ };
361
+ const handleMexNewsletterNotification = (id, node) => {
362
+ var _a;
363
+ const operation = node === null || node === void 0 ? void 0 : node.attrs.op_name;
364
+ const content = JSON.parse((_a = node === null || node === void 0 ? void 0 : node.content) === null || _a === void 0 ? void 0 : _a.toString());
365
+ let contentPath;
366
+ if (operation === Types_1.MexOperations.PROMOTE || operation === Types_1.MexOperations.DEMOTE) {
367
+ let action;
368
+ if (operation === Types_1.MexOperations.PROMOTE) {
369
+ action = 'promote';
370
+ contentPath = content.data[Types_1.XWAPaths.PROMOTE];
371
+ }
372
+ if (operation === Types_1.MexOperations.DEMOTE) {
373
+ action = 'demote';
374
+ contentPath = content.data[Types_1.XWAPaths.DEMOTE];
375
+ }
376
+ ev.emit('newsletter-participants.update', { id, author: contentPath.actor.pn, user: contentPath.user.pn, new_role: contentPath.user_new_role, action });
377
+ }
378
+ if (operation === Types_1.MexOperations.UPDATE) {
379
+ contentPath = content.data[Types_1.XWAPaths.METADATA_UPDATE];
380
+ ev.emit('newsletter-settings.update', { id, update: contentPath.thread_metadata.settings });
275
381
  }
276
382
  };
277
383
  const processNotification = async (node) => {
278
- var _a, _b, _c;
384
+ var _a, _b;
279
385
  const result = {};
280
386
  const [child] = (0, WABinary_1.getAllBinaryNodeChildren)(node);
281
387
  const nodeType = node.attrs.type;
@@ -294,6 +400,12 @@ const makeMessagesRecvSocket = (config) => {
294
400
  logger.debug({ jid }, 'got privacy token update');
295
401
  }
296
402
  break;
403
+ case 'newsletter':
404
+ handleNewsletterNotification(node.attrs.from, child);
405
+ break;
406
+ case 'mex':
407
+ handleMexNewsletterNotification(node.attrs.from, child);
408
+ break;
297
409
  case 'w:gp2':
298
410
  handleGroupNotification(node.attrs.participant, child, result);
299
411
  break;
@@ -322,7 +434,7 @@ const makeMessagesRecvSocket = (config) => {
322
434
  const setPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'set');
323
435
  const delPicture = (0, WABinary_1.getBinaryNodeChild)(node, 'delete');
324
436
  ev.emit('contacts.update', [{
325
- id: (0, WABinary_1.jidNormalizedUser)((_a = node === null || node === void 0 ? void 0 : node.attrs) === null || _a === void 0 ? void 0 : _a.from) || ((_c = (_b = (setPicture || delPicture)) === null || _b === void 0 ? void 0 : _b.attrs) === null || _c === void 0 ? void 0 : _c.hash) || '',
437
+ id: from || ((_b = (_a = (setPicture || delPicture)) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.hash) || '',
326
438
  imgUrl: setPicture ? 'changed' : 'removed'
327
439
  }]);
328
440
  if ((0, WABinary_1.isJidGroup)(from)) {
@@ -450,6 +562,7 @@ const makeMessagesRecvSocket = (config) => {
450
562
  };
451
563
  const sendMessagesAgain = async (key, ids, retryNode) => {
452
564
  var _a;
565
+ // todo: implement a cache to store the last 256 sent messages (copy whatsmeow)
453
566
  const msgs = await Promise.all(ids.map(id => getMessage({ ...key, id })));
454
567
  const remoteJid = key.remoteJid;
455
568
  const participant = key.participant || remoteJid;
@@ -488,7 +601,8 @@ const makeMessagesRecvSocket = (config) => {
488
601
  const isLid = attrs.from.includes('lid');
489
602
  const isNodeFromMe = (0, WABinary_1.areJidsSameUser)(attrs.participant || attrs.from, isLid ? (_a = authState.creds.me) === null || _a === void 0 ? void 0 : _a.lid : (_b = authState.creds.me) === null || _b === void 0 ? void 0 : _b.id);
490
603
  const remoteJid = !isNodeFromMe || (0, WABinary_1.isJidGroup)(attrs.from) ? attrs.from : attrs.recipient;
491
- const fromMe = !attrs.recipient || (attrs.type === 'retry' && isNodeFromMe);
604
+ const fromMe = !attrs.recipient || ((attrs.type === 'retry' || attrs.type === 'sender')
605
+ && isNodeFromMe);
492
606
  const key = {
493
607
  remoteJid,
494
608
  id: '',
@@ -598,13 +712,25 @@ const makeMessagesRecvSocket = (config) => {
598
712
  };
599
713
  const handleMessage = async (node) => {
600
714
  var _a, _b, _c;
715
+ if (ignoreMsgLoading && node.attrs.offline) {
716
+ logger.debug({ key: node.attrs.key }, 'ignored offline message');
717
+ await sendMessageAck(node);
718
+ return;
719
+ }
601
720
  if (shouldIgnoreJid(node.attrs.from) && node.attrs.from !== '@s.whatsapp.net') {
602
721
  logger.debug({ key: node.attrs.key }, 'ignored message');
603
722
  await sendMessageAck(node);
604
723
  return;
605
724
  }
725
+ const encNode = (0, WABinary_1.getBinaryNodeChild)(node, 'enc');
726
+ // TODO: temporary fix for crashes and issues resulting of failed msmsg decryption
727
+ if (encNode && encNode.attrs.type === 'msmsg') {
728
+ logger.debug({ key: node.attrs.key }, 'ignored msmsg');
729
+ await sendMessageAck(node);
730
+ return;
731
+ }
606
732
  let response;
607
- if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !(0, WABinary_1.getBinaryNodeChild)(node, 'enc')) {
733
+ if ((0, WABinary_1.getBinaryNodeChild)(node, 'unavailable') && !encNode) {
608
734
  await sendMessageAck(node);
609
735
  const { key } = (0, Utils_1.decodeMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '').fullMessage;
610
736
  response = await requestPlaceholderResend(key);
@@ -618,7 +744,7 @@ const makeMessagesRecvSocket = (config) => {
618
744
  placeholderResendCache.del(node.attrs.id);
619
745
  }
620
746
  }
621
- const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger);
747
+ const { fullMessage: msg, category, author, decrypt } = (0, Utils_1.decryptMessageNode)(node, authState.creds.me.id, authState.creds.me.lid || '', signalRepository, logger, getMessage);
622
748
  if (response && ((_a = msg === null || msg === void 0 ? void 0 : msg.messageStubParameters) === null || _a === void 0 ? void 0 : _a[0]) === Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT) {
623
749
  msg.messageStubParameters = [Utils_1.NO_MESSAGE_FOUND_ERROR_TEXT, response];
624
750
  }
@@ -768,20 +894,28 @@ const makeMessagesRecvSocket = (config) => {
768
894
  await sendMessageAck(node);
769
895
  };
770
896
  const handleBadAck = async ({ attrs }) => {
771
- const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id };
772
- // WARNING: REFRAIN FROM ENABLING THIS FOR NOW. IT WILL CAUSE A LOOP
773
- // // current hypothesis is that if pash is sent in the ack
774
- // // it means -- the message hasn't reached all devices yet
775
- // // we'll retry sending the message here
776
- // if(attrs.phash) {
777
- // logger.info({ attrs }, 'received phash in ack, resending message...')
778
- // const msg = await getMessage(key)
779
- // if(msg) {
780
- // await relayMessage(key.remoteJid!, msg, { messageId: key.id!, useUserDevicesCache: false })
781
- // } else {
782
- // logger.warn({ attrs }, 'could not send message again, as it was not found')
783
- // }
784
- // }
897
+ const key = { remoteJid: attrs.from, fromMe: true, id: attrs.id, server_id: attrs === null || attrs === void 0 ? void 0 : attrs.server_id };
898
+ // current hypothesis is that if pash is sent in the ack
899
+ // it means -- the message hasn't reached all devices yet
900
+ // we'll retry sending the message here
901
+ if (attrs.phash) {
902
+ logger.info({ attrs }, 'received phash in ack, resending message...');
903
+ const cacheKey = `${key.remoteJid}:${key.id}`;
904
+ if ((msgRetryCache.get(cacheKey) || 0) >= maxMsgRetryCount) {
905
+ logger.warn({ attrs }, 'reached max retry count, not sending message again');
906
+ msgRetryCache.del(cacheKey);
907
+ return;
908
+ }
909
+ const retryCount = msgRetryCache.get(cacheKey) || 0;
910
+ const msg = await getMessage(key);
911
+ if (msg) {
912
+ await relayMessage(key.remoteJid, msg, { messageId: key.id, useUserDevicesCache: false });
913
+ msgRetryCache.set(cacheKey, retryCount + 1);
914
+ }
915
+ else {
916
+ logger.warn({ attrs }, 'could not send message again, as it was not found');
917
+ }
918
+ }
785
919
  // error in acknowledgement,
786
920
  // device could not display the message
787
921
  if (attrs.error) {
@@ -905,6 +1039,7 @@ const makeMessagesRecvSocket = (config) => {
905
1039
  sendMessageAck,
906
1040
  sendRetryRequest,
907
1041
  rejectCall,
1042
+ offerCall,
908
1043
  fetchMessageHistory,
909
1044
  requestPlaceholderResend,
910
1045
  };