@jkt48connect-corp/baileys 7.2.9 → 7.3.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 (99) 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/noise-handler.d.ts +20 -0
  71. package/lib/Utils/process-message.d.ts +41 -0
  72. package/lib/Utils/signal.d.ts +33 -0
  73. package/lib/Utils/signal.js +11 -19
  74. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  75. package/lib/Utils/use-multi-file-auth-state.js +1 -7
  76. package/lib/Utils/validate-connection.d.ts +11 -0
  77. package/lib/Utils/validate-connection.js +23 -12
  78. package/lib/WABinary/constants.d.ts +27 -0
  79. package/lib/WABinary/decode.d.ts +6 -0
  80. package/lib/WABinary/encode.d.ts +2 -0
  81. package/lib/WABinary/generic-utils.d.ts +14 -0
  82. package/lib/WABinary/index.d.ts +5 -0
  83. package/lib/WABinary/jid-utils.d.ts +31 -0
  84. package/lib/WABinary/types.d.ts +18 -0
  85. package/lib/WAM/BinaryInfo.d.ts +8 -0
  86. package/lib/WAM/constants.d.ts +38 -0
  87. package/lib/WAM/encode.d.ts +2 -0
  88. package/lib/WAM/index.d.ts +3 -0
  89. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  90. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  91. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  92. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  93. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  94. package/lib/WAUSync/USyncQuery.d.ts +26 -0
  95. package/lib/WAUSync/USyncUser.d.ts +10 -0
  96. package/lib/WAUSync/index.d.ts +3 -0
  97. package/lib/index.js +1 -3
  98. package/package.json +7 -4
  99. package/LICENSE +0 -21
@@ -0,0 +1,118 @@
1
+ import type KeyedDB from '@adiwajshing/keyed-db';
2
+ import type { Comparable } from '@adiwajshing/keyed-db/lib/Types';
3
+ import type { Logger } from 'pino';
4
+ import { proto } from '../../WAProto';
5
+ import type makeMDSocket from '../Socket';
6
+ import type { BaileysEventEmitter, Chat, ConnectionState, Contact, GroupMetadata, PresenceData, WAMessage, WAMessageCursor, WAMessageKey } from '../Types';
7
+ import { Label } from '../Types/Label';
8
+ import { LabelAssociation } from '../Types/LabelAssociation';
9
+ import { ObjectRepository } from './object-repository';
10
+ type WASocket = ReturnType<typeof makeMDSocket>;
11
+ export declare const waChatKey: (pin: boolean) => {
12
+ key: (c: Chat) => string;
13
+ compare: (k1: string, k2: string) => number;
14
+ };
15
+ export declare const waMessageID: (m: WAMessage) => string;
16
+ export declare const waLabelAssociationKey: Comparable<LabelAssociation, string>;
17
+ export type BaileysInMemoryStoreConfig = {
18
+ chatKey?: Comparable<Chat, string>;
19
+ labelAssociationKey?: Comparable<LabelAssociation, string>;
20
+ logger?: Logger;
21
+ socket?: WASocket;
22
+ };
23
+ declare const _default: (config: BaileysInMemoryStoreConfig) => {
24
+ chats: KeyedDB<Chat, string>;
25
+ contacts: {
26
+ [_: string]: Contact;
27
+ };
28
+ messages: {
29
+ [_: string]: {
30
+ array: proto.IWebMessageInfo[];
31
+ get: (id: string) => proto.IWebMessageInfo | undefined;
32
+ upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
33
+ update: (item: proto.IWebMessageInfo) => boolean;
34
+ remove: (item: proto.IWebMessageInfo) => boolean;
35
+ updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
36
+ clear: () => void;
37
+ filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
38
+ toJSON: () => proto.IWebMessageInfo[];
39
+ fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
40
+ };
41
+ };
42
+ groupMetadata: {
43
+ [_: string]: GroupMetadata;
44
+ };
45
+ state: ConnectionState;
46
+ presences: {
47
+ [id: string]: {
48
+ [participant: string]: PresenceData;
49
+ };
50
+ };
51
+ labels: ObjectRepository<Label>;
52
+ labelAssociations: KeyedDB<LabelAssociation, string>;
53
+ bind: (ev: BaileysEventEmitter) => void;
54
+ /** loads messages from the store, if not found -- uses the legacy connection */
55
+ loadMessages: (jid: string, count: number, cursor: WAMessageCursor) => Promise<proto.IWebMessageInfo[]>;
56
+ /**
57
+ * Get all available labels for profile
58
+ *
59
+ * Keep in mind that the list is formed from predefined tags and tags
60
+ * that were "caught" during their editing.
61
+ */
62
+ getLabels: () => ObjectRepository<Label>;
63
+ /**
64
+ * Get labels for chat
65
+ *
66
+ * @returns Label IDs
67
+ **/
68
+ getChatLabels: (chatId: string) => LabelAssociation[];
69
+ /**
70
+ * Get labels for message
71
+ *
72
+ * @returns Label IDs
73
+ **/
74
+ getMessageLabels: (messageId: string) => string[];
75
+ loadMessage: (jid: string, id: string) => Promise<proto.IWebMessageInfo | undefined>;
76
+ mostRecentMessage: (jid: string) => Promise<proto.IWebMessageInfo>;
77
+ fetchImageUrl: (jid: string, sock: WASocket | undefined) => Promise<string | null | undefined>;
78
+ fetchGroupMetadata: (jid: string, sock: WASocket | undefined) => Promise<GroupMetadata>;
79
+ fetchMessageReceipts: ({ remoteJid, id }: WAMessageKey) => Promise<proto.IUserReceipt[] | null | undefined>;
80
+ toJSON: () => {
81
+ chats: KeyedDB<Chat, string>;
82
+ contacts: {
83
+ [_: string]: Contact;
84
+ };
85
+ messages: {
86
+ [_: string]: {
87
+ array: proto.IWebMessageInfo[];
88
+ get: (id: string) => proto.IWebMessageInfo | undefined;
89
+ upsert: (item: proto.IWebMessageInfo, mode: "append" | "prepend") => void;
90
+ update: (item: proto.IWebMessageInfo) => boolean;
91
+ remove: (item: proto.IWebMessageInfo) => boolean;
92
+ updateAssign: (id: string, update: Partial<proto.IWebMessageInfo>) => boolean;
93
+ clear: () => void;
94
+ filter: (contain: (item: proto.IWebMessageInfo) => boolean) => void;
95
+ toJSON: () => proto.IWebMessageInfo[];
96
+ fromJSON: (newItems: proto.IWebMessageInfo[]) => void;
97
+ };
98
+ };
99
+ labels: ObjectRepository<Label>;
100
+ labelAssociations: KeyedDB<LabelAssociation, string>;
101
+ };
102
+ fromJSON: (json: {
103
+ chats: Chat[];
104
+ contacts: {
105
+ [id: string]: Contact;
106
+ };
107
+ messages: {
108
+ [id: string]: proto.IWebMessageInfo[];
109
+ };
110
+ labels: {
111
+ [labelId: string]: Label;
112
+ };
113
+ labelAssociations: LabelAssociation[];
114
+ }) => void;
115
+ writeToFile: (path: string) => void;
116
+ readFromFile: (path: string) => void;
117
+ };
118
+ export default _default;
@@ -56,6 +56,14 @@ exports.default = (config) => {
56
56
  labels.upsertById(label.id, label);
57
57
  }
58
58
  };
59
+ const getValidContacts = () => {
60
+ for (const contact of Object.keys(contacts)) {
61
+ if (contact.indexOf('@') < 0) {
62
+ delete contacts[contact];
63
+ }
64
+ }
65
+ return Object.keys(contacts);
66
+ };
59
67
  /**
60
68
  * binds to a BaileysEventEmitter.
61
69
  * It listens to all events and constructs a state that you can query accurate data from.
@@ -104,10 +112,11 @@ exports.default = (config) => {
104
112
  contact = contacts[update.id];
105
113
  }
106
114
  else {
107
- const contactHashes = await Promise.all(Object.keys(contacts).map(async (contactId) => {
115
+ const validContacts = getValidContacts();
116
+ const contactHashes = validContacts.map((contactId) => {
108
117
  const { user } = (0, WABinary_1.jidDecode)(contactId);
109
- return [contactId, (await (0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
110
- }));
118
+ return [contactId, ((0, Utils_1.md5)(Buffer.from(user + 'WA_ADD_NOTIF', 'utf8'))).toString('base64').slice(0, 3)];
119
+ });
111
120
  contact = contacts[((_a = contactHashes.find(([, b]) => b === update.id)) === null || _a === void 0 ? void 0 : _a[0]) || '']; // find contact by attrs.hash, when user is not saved as a contact
112
121
  }
113
122
  if (contact) {
@@ -117,11 +126,11 @@ exports.default = (config) => {
117
126
  else if (update.imgUrl === 'removed') {
118
127
  delete contact.imgUrl;
119
128
  }
129
+ Object.assign(contacts[contact.id], contact);
120
130
  }
121
131
  else {
122
- return logger.debug({ update }, 'got update for non-existant contact');
132
+ logger.debug({ update }, 'got update for non-existant contact');
123
133
  }
124
- Object.assign(contacts[contact.id], contact);
125
134
  }
126
135
  });
127
136
  ev.on('chats.upsert', newChats => {
@@ -182,14 +191,16 @@ exports.default = (config) => {
182
191
  const jid = (0, WABinary_1.jidNormalizedUser)(msg.key.remoteJid);
183
192
  const list = assertMessageList(jid);
184
193
  list.upsert(msg, 'append');
185
- if (type === 'notify' && !chats.get(jid)) {
186
- ev.emit('chats.upsert', [
187
- {
188
- id: jid,
189
- conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
190
- unreadCount: 1
191
- }
192
- ]);
194
+ if (type === 'notify') {
195
+ if (!chats.get(jid)) {
196
+ ev.emit('chats.upsert', [
197
+ {
198
+ id: jid,
199
+ conversationTimestamp: (0, Utils_1.toNumber)(msg.messageTimestamp),
200
+ unreadCount: 1
201
+ }
202
+ ]);
203
+ }
193
204
  }
194
205
  }
195
206
  break;
@@ -0,0 +1,13 @@
1
+ declare function makeOrderedDictionary<T>(idGetter: (item: T) => string): {
2
+ array: T[];
3
+ get: (id: string) => T | undefined;
4
+ upsert: (item: T, mode: "append" | "prepend") => void;
5
+ update: (item: T) => boolean;
6
+ remove: (item: T) => boolean;
7
+ updateAssign: (id: string, update: Partial<T>) => boolean;
8
+ clear: () => void;
9
+ filter: (contain: (item: T) => boolean) => void;
10
+ toJSON: () => T[];
11
+ fromJSON: (newItems: T[]) => void;
12
+ };
13
+ export default makeOrderedDictionary;
@@ -0,0 +1,10 @@
1
+ export declare class ObjectRepository<T extends object> {
2
+ readonly entityMap: Map<string, T>;
3
+ constructor(entities?: Record<string, T>);
4
+ findById(id: string): T | undefined;
5
+ findAll(): T[];
6
+ upsertById(id: string, entity: T): Map<string, T>;
7
+ deleteById(id: string): boolean;
8
+ count(): number;
9
+ toJSON(): T[];
10
+ }
@@ -0,0 +1,109 @@
1
+ import type { proto } from '../../WAProto';
2
+ import { RegistrationOptions } from '../Socket/registration';
3
+ import type { Contact } from './Contact';
4
+ import type { MinimalMessage } from './Message';
5
+ export type KeyPair = {
6
+ public: Uint8Array;
7
+ private: Uint8Array;
8
+ };
9
+ export type SignedKeyPair = {
10
+ keyPair: KeyPair;
11
+ signature: Uint8Array;
12
+ keyId: number;
13
+ timestampS?: number;
14
+ };
15
+ export type ProtocolAddress = {
16
+ name: string;
17
+ deviceId: number;
18
+ };
19
+ export type SignalIdentity = {
20
+ identifier: ProtocolAddress;
21
+ identifierKey: Uint8Array;
22
+ };
23
+ export type LTHashState = {
24
+ version: number;
25
+ hash: Buffer;
26
+ indexValueMap: {
27
+ [indexMacBase64: string]: {
28
+ valueMac: Uint8Array | Buffer;
29
+ };
30
+ };
31
+ };
32
+ export type SignalCreds = {
33
+ readonly signedIdentityKey: KeyPair;
34
+ readonly signedPreKey: SignedKeyPair;
35
+ readonly registrationId: number;
36
+ };
37
+ export type AccountSettings = {
38
+ /** unarchive chats when a new message is received */
39
+ unarchiveChats: boolean;
40
+ /** the default mode to start new conversations with */
41
+ defaultDisappearingMode?: Pick<proto.IConversation, 'ephemeralExpiration' | 'ephemeralSettingTimestamp'>;
42
+ };
43
+ export type AuthenticationCreds = SignalCreds & {
44
+ readonly noiseKey: KeyPair;
45
+ readonly pairingEphemeralKeyPair: KeyPair;
46
+ advSecretKey: string;
47
+ me?: Contact;
48
+ account?: proto.IADVSignedDeviceIdentity;
49
+ signalIdentities?: SignalIdentity[];
50
+ myAppStateKeyId?: string;
51
+ firstUnuploadedPreKeyId: number;
52
+ nextPreKeyId: number;
53
+ lastAccountSyncTimestamp?: number;
54
+ platform?: string;
55
+ processedHistoryMessages: MinimalMessage[];
56
+ /** number of times history & app state has been synced */
57
+ accountSyncCounter: number;
58
+ accountSettings: AccountSettings;
59
+ deviceId: string;
60
+ phoneId: string;
61
+ identityId: Buffer;
62
+ registered: boolean;
63
+ backupToken: Buffer;
64
+ registration: RegistrationOptions;
65
+ pairingCode: string | undefined;
66
+ lastPropHash: string | undefined;
67
+ routingInfo: Buffer | undefined;
68
+ };
69
+ export type SignalDataTypeMap = {
70
+ 'pre-key': KeyPair;
71
+ 'session': Uint8Array;
72
+ 'sender-key': Uint8Array;
73
+ 'sender-key-memory': {
74
+ [jid: string]: boolean;
75
+ };
76
+ 'app-state-sync-key': proto.Message.IAppStateSyncKeyData;
77
+ 'app-state-sync-version': LTHashState;
78
+ };
79
+ export type SignalDataSet = {
80
+ [T in keyof SignalDataTypeMap]?: {
81
+ [id: string]: SignalDataTypeMap[T] | null;
82
+ };
83
+ };
84
+ type Awaitable<T> = T | Promise<T>;
85
+ export type SignalKeyStore = {
86
+ get<T extends keyof SignalDataTypeMap>(type: T, ids: string[]): Awaitable<{
87
+ [id: string]: SignalDataTypeMap[T];
88
+ }>;
89
+ set(data: SignalDataSet): Awaitable<void>;
90
+ /** clear all the data in the store */
91
+ clear?(): Awaitable<void>;
92
+ };
93
+ export type SignalKeyStoreWithTransaction = SignalKeyStore & {
94
+ isInTransaction: () => boolean;
95
+ transaction<T>(exec: () => Promise<T>): Promise<T>;
96
+ };
97
+ export type TransactionCapabilityOptions = {
98
+ maxCommitRetries: number;
99
+ delayBetweenTriesMs: number;
100
+ };
101
+ export type SignalAuthState = {
102
+ creds: SignalCreds;
103
+ keys: SignalKeyStore | SignalKeyStoreWithTransaction;
104
+ };
105
+ export type AuthenticationState = {
106
+ creds: AuthenticationCreds;
107
+ keys: SignalKeyStore;
108
+ };
109
+ export {};
@@ -0,0 +1,13 @@
1
+ export type WACallUpdateType = 'offer' | 'ringing' | 'timeout' | 'reject' | 'accept' | 'terminate';
2
+ export type WACallEvent = {
3
+ chatId: string;
4
+ from: string;
5
+ isGroup?: boolean;
6
+ groupJid?: string;
7
+ id: string;
8
+ date: Date;
9
+ isVideo?: boolean;
10
+ status: WACallUpdateType;
11
+ offline: boolean;
12
+ latencyMs?: number;
13
+ };
@@ -0,0 +1,107 @@
1
+ import type { proto } from '../../WAProto';
2
+ import type { AccountSettings } from './Auth';
3
+ import type { BufferedEventData } from './Events';
4
+ import type { LabelActionBody } from './Label';
5
+ import type { ChatLabelAssociationActionBody } from './LabelAssociation';
6
+ import type { MessageLabelAssociationActionBody } from './LabelAssociation';
7
+ import type { MinimalMessage, WAMessageKey } from './Message';
8
+ /** privacy settings in WhatsApp Web */
9
+ export type WAPrivacyValue = 'all' | 'contacts' | 'contact_blacklist' | 'none';
10
+ export type WAPrivacyOnlineValue = 'all' | 'match_last_seen';
11
+ export type WAPrivacyGroupAddValue = 'all' | 'contacts' | 'contact_blacklist';
12
+ export type WAReadReceiptsValue = 'all' | 'none';
13
+ export type WAPrivacyCallValue = 'all' | 'known';
14
+ /** set of statuses visible to other people; see updatePresence() in WhatsAppWeb.Send */
15
+ export type WAPresence = 'unavailable' | 'available' | 'composing' | 'recording' | 'paused';
16
+ export declare const ALL_WA_PATCH_NAMES: readonly ["critical_block", "critical_unblock_low", "regular_high", "regular_low", "regular"];
17
+ export type WAPatchName = typeof ALL_WA_PATCH_NAMES[number];
18
+ export interface PresenceData {
19
+ lastKnownPresence: WAPresence;
20
+ lastSeen?: number;
21
+ }
22
+ export type ChatMutation = {
23
+ syncAction: proto.ISyncActionData;
24
+ index: string[];
25
+ };
26
+ export type WAPatchCreate = {
27
+ syncAction: proto.ISyncActionValue;
28
+ index: string[];
29
+ type: WAPatchName;
30
+ apiVersion: number;
31
+ operation: proto.SyncdMutation.SyncdOperation;
32
+ };
33
+ export type Chat = proto.IConversation & {
34
+ /** unix timestamp of when the last message was received in the chat */
35
+ lastMessageRecvTimestamp?: number;
36
+ };
37
+ export type ChatUpdate = Partial<Chat & {
38
+ /**
39
+ * if specified in the update,
40
+ * the EV buffer will check if the condition gets fulfilled before applying the update
41
+ * Right now, used to determine when to release an app state sync event
42
+ *
43
+ * @returns true, if the update should be applied;
44
+ * false if it can be discarded;
45
+ * undefined if the condition is not yet fulfilled
46
+ * */
47
+ conditional: (bufferedData: BufferedEventData) => boolean | undefined;
48
+ }>;
49
+ /**
50
+ * the last messages in a chat, sorted reverse-chronologically. That is, the latest message should be first in the chat
51
+ * for MD modifications, the last message in the array (i.e. the earlist message) must be the last message recv in the chat
52
+ * */
53
+ export type LastMessageList = MinimalMessage[] | proto.SyncActionValue.ISyncActionMessageRange;
54
+ export type ChatModification = {
55
+ archive: boolean;
56
+ lastMessages: LastMessageList;
57
+ } | {
58
+ pushNameSetting: string;
59
+ } | {
60
+ pin: boolean;
61
+ } | {
62
+ /** mute for duration, or provide timestamp of mute to remove*/
63
+ mute: number | null;
64
+ } | {
65
+ clear: boolean;
66
+ } | {
67
+ deleteForMe: {
68
+ deleteMedia: boolean;
69
+ key: WAMessageKey;
70
+ timestamp: number;
71
+ };
72
+ } | {
73
+ star: {
74
+ messages: {
75
+ id: string;
76
+ fromMe?: boolean;
77
+ }[];
78
+ star: boolean;
79
+ };
80
+ } | {
81
+ markRead: boolean;
82
+ lastMessages: LastMessageList;
83
+ } | {
84
+ delete: true;
85
+ lastMessages: LastMessageList;
86
+ } | {
87
+ addLabel: LabelActionBody;
88
+ } | {
89
+ addChatLabel: ChatLabelAssociationActionBody;
90
+ } | {
91
+ removeChatLabel: ChatLabelAssociationActionBody;
92
+ } | {
93
+ addMessageLabel: MessageLabelAssociationActionBody;
94
+ } | {
95
+ removeMessageLabel: MessageLabelAssociationActionBody;
96
+ };
97
+ export type InitialReceivedChatsState = {
98
+ [jid: string]: {
99
+ /** the last message received from the other party */
100
+ lastMsgRecvTimestamp?: number;
101
+ /** the absolute last message in the chat */
102
+ lastMsgTimestamp: number;
103
+ };
104
+ };
105
+ export type InitialAppStateSyncOptions = {
106
+ accountSettings: AccountSettings;
107
+ };
@@ -0,0 +1,19 @@
1
+ export interface Contact {
2
+ id: string;
3
+ lid?: string;
4
+ /** name of the contact, you have saved on your WA */
5
+ name?: string;
6
+ /** name of the contact, the contact has set on their own on WA */
7
+ notify?: string;
8
+ /** I have no idea */
9
+ verifiedName?: string;
10
+ /**
11
+ * Url of the profile picture of the contact
12
+ *
13
+ * 'changed' => if the profile picture has changed
14
+ * null => if the profile picture has not been set (default profile picture)
15
+ * any other string => url of the profile picture
16
+ */
17
+ imgUrl?: string | null | 'changed';
18
+ status?: string;
19
+ }
@@ -0,0 +1,172 @@
1
+ import type { Boom } from '@hapi/boom';
2
+ import { proto } from '../../WAProto';
3
+ import { AuthenticationCreds } from './Auth';
4
+ import { WACallEvent } from './Call';
5
+ import { Chat, ChatUpdate, PresenceData } from './Chat';
6
+ import { Contact } from './Contact';
7
+ import { GroupMetadata, ParticipantAction, RequestJoinAction, RequestJoinMethod } from './GroupMetadata';
8
+ import { Label } from './Label';
9
+ import { LabelAssociation } from './LabelAssociation';
10
+ import { MessageUpsertType, MessageUserReceiptUpdate, WAMessage, WAMessageKey, WAMessageUpdate } from './Message';
11
+ import { ConnectionState } from './State';
12
+ export type BaileysEventMap = {
13
+ /** connection state has been updated -- WS closed, opened, connecting etc. */
14
+ 'connection.update': Partial<ConnectionState>;
15
+ /** credentials updated -- some metadata, keys or something */
16
+ 'creds.update': Partial<AuthenticationCreds>;
17
+ /** set chats (history sync), everything is reverse chronologically sorted */
18
+ 'messaging-history.set': {
19
+ chats: Chat[];
20
+ contacts: Contact[];
21
+ messages: WAMessage[];
22
+ isLatest?: boolean;
23
+ progress?: number | null;
24
+ syncType?: proto.HistorySync.HistorySyncType;
25
+ peerDataRequestSessionId?: string | null;
26
+ };
27
+ /** upsert chats */
28
+ 'chats.upsert': Chat[];
29
+ /** update the given chats */
30
+ 'chats.update': ChatUpdate[];
31
+ 'chats.phoneNumberShare': {
32
+ lid: string;
33
+ jid: string;
34
+ };
35
+ /** delete chats with given ID */
36
+ 'chats.delete': string[];
37
+ /** presence of contact in a chat updated */
38
+ 'presence.update': {
39
+ id: string;
40
+ presences: {
41
+ [participant: string]: PresenceData;
42
+ };
43
+ };
44
+ 'contacts.upsert': Contact[];
45
+ 'contacts.update': Partial<Contact>[];
46
+ 'messages.delete': {
47
+ keys: WAMessageKey[];
48
+ } | {
49
+ jid: string;
50
+ all: true;
51
+ };
52
+ 'messages.update': WAMessageUpdate[];
53
+ 'messages.media-update': {
54
+ key: WAMessageKey;
55
+ media?: {
56
+ ciphertext: Uint8Array;
57
+ iv: Uint8Array;
58
+ };
59
+ error?: Boom;
60
+ }[];
61
+ /**
62
+ * add/update the given messages. If they were received while the connection was online,
63
+ * the update will have type: "notify"
64
+ * if requestId is provided, then the messages was received from the phone due to it being unavailable
65
+ * */
66
+ 'messages.upsert': {
67
+ messages: WAMessage[];
68
+ type: MessageUpsertType;
69
+ requestId?: string;
70
+ };
71
+ /** message was reacted to. If reaction was removed -- then "reaction.text" will be falsey */
72
+ 'messages.reaction': {
73
+ key: WAMessageKey;
74
+ reaction: proto.IReaction;
75
+ }[];
76
+ 'message-receipt.update': MessageUserReceiptUpdate[];
77
+ 'groups.upsert': GroupMetadata[];
78
+ 'groups.update': Partial<GroupMetadata>[];
79
+ /** apply an action to participants in a group */
80
+ 'group-participants.update': {
81
+ id: string;
82
+ author: string;
83
+ participants: string[];
84
+ action: ParticipantAction;
85
+ };
86
+ 'group.join-request': {
87
+ id: string;
88
+ author: string;
89
+ participant: string;
90
+ action: RequestJoinAction;
91
+ method: RequestJoinMethod;
92
+ };
93
+ 'blocklist.set': {
94
+ blocklist: string[];
95
+ };
96
+ 'blocklist.update': {
97
+ blocklist: string[];
98
+ type: 'add' | 'remove';
99
+ };
100
+ /** Receive an update on a call, including when the call was received, rejected, accepted */
101
+ 'call': WACallEvent[];
102
+ 'labels.edit': Label;
103
+ 'labels.association': {
104
+ association: LabelAssociation;
105
+ type: 'add' | 'remove';
106
+ };
107
+ };
108
+ export type BufferedEventData = {
109
+ historySets: {
110
+ chats: {
111
+ [jid: string]: Chat;
112
+ };
113
+ contacts: {
114
+ [jid: string]: Contact;
115
+ };
116
+ messages: {
117
+ [uqId: string]: WAMessage;
118
+ };
119
+ empty: boolean;
120
+ isLatest: boolean;
121
+ progress?: number | null;
122
+ syncType?: proto.HistorySync.HistorySyncType;
123
+ peerDataRequestSessionId?: string;
124
+ };
125
+ chatUpserts: {
126
+ [jid: string]: Chat;
127
+ };
128
+ chatUpdates: {
129
+ [jid: string]: ChatUpdate;
130
+ };
131
+ chatDeletes: Set<string>;
132
+ contactUpserts: {
133
+ [jid: string]: Contact;
134
+ };
135
+ contactUpdates: {
136
+ [jid: string]: Partial<Contact>;
137
+ };
138
+ messageUpserts: {
139
+ [key: string]: {
140
+ type: MessageUpsertType;
141
+ message: WAMessage;
142
+ };
143
+ };
144
+ messageUpdates: {
145
+ [key: string]: WAMessageUpdate;
146
+ };
147
+ messageDeletes: {
148
+ [key: string]: WAMessageKey;
149
+ };
150
+ messageReactions: {
151
+ [key: string]: {
152
+ key: WAMessageKey;
153
+ reactions: proto.IReaction[];
154
+ };
155
+ };
156
+ messageReceipts: {
157
+ [key: string]: {
158
+ key: WAMessageKey;
159
+ userReceipt: proto.IUserReceipt[];
160
+ };
161
+ };
162
+ groupUpdates: {
163
+ [jid: string]: Partial<GroupMetadata>;
164
+ };
165
+ };
166
+ export type BaileysEvent = keyof BaileysEventMap;
167
+ export interface BaileysEventEmitter {
168
+ on<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void;
169
+ off<T extends keyof BaileysEventMap>(event: T, listener: (arg: BaileysEventMap[T]) => void): void;
170
+ removeAllListeners<T extends keyof BaileysEventMap>(event: T): void;
171
+ emit<T extends keyof BaileysEventMap>(event: T, arg: BaileysEventMap[T]): boolean;
172
+ }