@alannxd/baileys 6.0.5 → 6.0.9

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 (123) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +341 -286
  3. package/WAProto/WAProto.proto +1782 -359
  4. package/WAProto/index.d.ts +75133 -9893
  5. package/WAProto/index.js +205861 -60606
  6. package/lib/Socket/luxu.js +6 -117
  7. package/lib/Socket/messages-send.js +637 -493
  8. package/lib/Socket/newsletter.js +229 -156
  9. package/lib/Utils/browser-utils.js +26 -6
  10. package/lib/Utils/decode-wa-message.js +33 -0
  11. package/lib/Utils/generics.js +10 -0
  12. package/lib/Utils/index.js +1 -0
  13. package/lib/Utils/message-composer.js +273 -0
  14. package/lib/Utils/messages.js +361 -24
  15. package/lib/WABinary/generic-utils.js +8 -1
  16. package/lib/WABinary/jid-utils.js +2 -0
  17. package/lib/index.js +1 -2
  18. package/package.json +5 -4
  19. package/lib/Defaults/index.d.ts +0 -75
  20. package/lib/Signal/Group/ciphertext-message.d.ts +0 -10
  21. package/lib/Signal/Group/group-session-builder.d.ts +0 -15
  22. package/lib/Signal/Group/group_cipher.d.ts +0 -17
  23. package/lib/Signal/Group/index.d.ts +0 -12
  24. package/lib/Signal/Group/keyhelper.d.ts +0 -11
  25. package/lib/Signal/Group/sender-chain-key.d.ts +0 -14
  26. package/lib/Signal/Group/sender-key-distribution-message.d.ts +0 -17
  27. package/lib/Signal/Group/sender-key-message.d.ts +0 -19
  28. package/lib/Signal/Group/sender-key-name.d.ts +0 -18
  29. package/lib/Signal/Group/sender-key-record.d.ts +0 -31
  30. package/lib/Signal/Group/sender-key-state.d.ts +0 -39
  31. package/lib/Signal/Group/sender-message-key.d.ts +0 -12
  32. package/lib/Signal/libsignal.d.ts +0 -5
  33. package/lib/Signal/lid-mapping.d.ts +0 -23
  34. package/lib/Socket/Client/index.d.ts +0 -3
  35. package/lib/Socket/Client/types.d.ts +0 -16
  36. package/lib/Socket/Client/websocket.d.ts +0 -13
  37. package/lib/Socket/business.d.ts +0 -217
  38. package/lib/Socket/chats.d.ts +0 -124
  39. package/lib/Socket/communities.d.ts +0 -273
  40. package/lib/Socket/groups.d.ts +0 -162
  41. package/lib/Socket/index.d.ts +0 -260
  42. package/lib/Socket/luxu.d.ts +0 -22
  43. package/lib/Socket/messages-recv.d.ts +0 -213
  44. package/lib/Socket/messages-send.d.ts +0 -199
  45. package/lib/Socket/mex.d.ts +0 -3
  46. package/lib/Socket/newsletter.d.ts +0 -170
  47. package/lib/Socket/socket.d.ts +0 -59
  48. package/lib/Store/index.d.ts +0 -10
  49. package/lib/Store/keyed-db.d.ts +0 -22
  50. package/lib/Store/make-cache-manager-store.d.ts +0 -19
  51. package/lib/Store/make-in-memory-store.d.ts +0 -39
  52. package/lib/Store/make-ordered-dictionary.d.ts +0 -14
  53. package/lib/Store/object-repository.d.ts +0 -11
  54. package/lib/Types/Auth.d.ts +0 -117
  55. package/lib/Types/Bussines.d.ts +0 -25
  56. package/lib/Types/Call.d.ts +0 -15
  57. package/lib/Types/Chat.d.ts +0 -124
  58. package/lib/Types/Contact.d.ts +0 -26
  59. package/lib/Types/Events.d.ts +0 -256
  60. package/lib/Types/GroupMetadata.d.ts +0 -71
  61. package/lib/Types/Label.d.ts +0 -47
  62. package/lib/Types/LabelAssociation.d.ts +0 -30
  63. package/lib/Types/Message.d.ts +0 -320
  64. package/lib/Types/Mex.d.ts +0 -141
  65. package/lib/Types/Product.d.ts +0 -79
  66. package/lib/Types/Signal.d.ts +0 -87
  67. package/lib/Types/Socket.d.ts +0 -136
  68. package/lib/Types/State.d.ts +0 -97
  69. package/lib/Types/USync.d.ts +0 -26
  70. package/lib/Types/index.d.ts +0 -65
  71. package/lib/Utils/auth-utils.d.ts +0 -24
  72. package/lib/Utils/browser-utils.d.ts +0 -4
  73. package/lib/Utils/business.d.ts +0 -23
  74. package/lib/Utils/chat-utils.d.ts +0 -100
  75. package/lib/Utils/companion-reg-client-utils.d.ts +0 -17
  76. package/lib/Utils/crypto.d.ts +0 -37
  77. package/lib/Utils/decode-wa-message.d.ts +0 -66
  78. package/lib/Utils/event-buffer.d.ts +0 -36
  79. package/lib/Utils/generics.d.ts +0 -91
  80. package/lib/Utils/history.d.ts +0 -24
  81. package/lib/Utils/identity-change-handler.d.ts +0 -44
  82. package/lib/Utils/index.d.ts +0 -22
  83. package/lib/Utils/link-preview.d.ts +0 -21
  84. package/lib/Utils/logger.d.ts +0 -12
  85. package/lib/Utils/lt-hash.d.ts +0 -8
  86. package/lib/Utils/make-mutex.d.ts +0 -9
  87. package/lib/Utils/message-retry-manager.d.ts +0 -115
  88. package/lib/Utils/messages-media.d.ts +0 -133
  89. package/lib/Utils/messages.d.ts +0 -91
  90. package/lib/Utils/noise-handler.d.ts +0 -20
  91. package/lib/Utils/offline-node-processor.d.ts +0 -17
  92. package/lib/Utils/pre-key-manager.d.ts +0 -28
  93. package/lib/Utils/process-message.d.ts +0 -60
  94. package/lib/Utils/reporting-utils.d.ts +0 -11
  95. package/lib/Utils/signal.d.ts +0 -47
  96. package/lib/Utils/stanza-ack.d.ts +0 -11
  97. package/lib/Utils/sync-action-utils.d.ts +0 -19
  98. package/lib/Utils/tc-token-utils.d.ts +0 -37
  99. package/lib/Utils/use-multi-file-auth-state.d.ts +0 -13
  100. package/lib/Utils/validate-connection.d.ts +0 -11
  101. package/lib/WABinary/constants.d.ts +0 -28
  102. package/lib/WABinary/decode.d.ts +0 -7
  103. package/lib/WABinary/encode.d.ts +0 -3
  104. package/lib/WABinary/generic-utils.d.ts +0 -18
  105. package/lib/WABinary/index.d.ts +0 -6
  106. package/lib/WABinary/jid-utils.d.ts +0 -48
  107. package/lib/WABinary/types.d.ts +0 -19
  108. package/lib/WAM/BinaryInfo.d.ts +0 -9
  109. package/lib/WAM/constants.d.ts +0 -40
  110. package/lib/WAM/encode.d.ts +0 -3
  111. package/lib/WAM/index.d.ts +0 -4
  112. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +0 -10
  113. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +0 -23
  114. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +0 -13
  115. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +0 -13
  116. package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts +0 -10
  117. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +0 -26
  118. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +0 -10
  119. package/lib/WAUSync/Protocols/index.d.ts +0 -6
  120. package/lib/WAUSync/USyncQuery.d.ts +0 -30
  121. package/lib/WAUSync/USyncUser.d.ts +0 -17
  122. package/lib/WAUSync/index.d.ts +0 -4
  123. package/lib/index.d.ts +0 -13
@@ -1,91 +0,0 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { BaileysEventEmitter, BaileysEventMap, ConnectionState, WACallUpdateType, WAMessageKey, WAVersion } from '../Types/index.js';
3
- import { type BinaryNode } from '../WABinary/index.js';
4
- export declare const BufferJSON: {
5
- replacer: (k: any, value: any) => any;
6
- reviver: (_: any, value: any) => any;
7
- };
8
- export declare const getKeyAuthor: (key: WAMessageKey | undefined | null, meId?: string) => string;
9
- export declare const isStringNullOrEmpty: (value: string | null | undefined) => value is null | undefined | "";
10
- export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer<ArrayBuffer>;
11
- export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array<ArrayBuffer>;
12
- export declare const generateParticipantHashV2: (participants: string[]) => string;
13
- export declare const encodeWAMessage: (message: proto.IMessage) => Buffer<ArrayBuffer>;
14
- export declare const generateRegistrationId: () => number;
15
- export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array<ArrayBuffer>;
16
- export declare const toNumber: (t: Long | number | null | undefined) => number;
17
- /** unix timestamp of a date in seconds */
18
- export declare const unixTimestampSeconds: (date?: Date) => number;
19
- export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
20
- export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
21
- start: (newIntervalMs?: number, newTask?: () => void) => void;
22
- cancel: () => void;
23
- setTask: (newTask: () => void) => () => void;
24
- setInterval: (newInterval: number) => number;
25
- };
26
- export declare const delay: (ms: number) => Promise<void>;
27
- export declare const delayCancellable: (ms: number) => {
28
- delay: Promise<void>;
29
- cancel: () => void;
30
- };
31
- export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
32
- export declare const generateMessageIDV2: (userId?: string) => string;
33
- export declare const generateMessageID: () => string;
34
- export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
35
- export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<ConnectionState>) => Promise<boolean | undefined>, timeoutMs?: number) => Promise<void>;
36
- /**
37
- * utility that fetches latest baileys version from the master branch.
38
- * Use to ensure your WA connection is always on the latest version
39
- */
40
- export declare const fetchLatestBaileysVersion: (options?: RequestInit) => Promise<{
41
- version: WAVersion;
42
- isLatest: boolean;
43
- error?: undefined;
44
- } | {
45
- version: WAVersion;
46
- isLatest: boolean;
47
- error: unknown;
48
- }>;
49
- /**
50
- * A utility that fetches the latest web version of whatsapp.
51
- * Use to ensure your WA connection is always on the latest version
52
- */
53
- export declare const fetchLatestWaWebVersion: (options?: RequestInit) => Promise<{
54
- version: WAVersion;
55
- isLatest: boolean;
56
- error?: undefined;
57
- } | {
58
- version: WAVersion;
59
- isLatest: boolean;
60
- error: unknown;
61
- }>;
62
- /** unique message tag prefix for MD clients */
63
- export declare const generateMdTagPrefix: () => string;
64
- /**
65
- * Given a type of receipt, returns what the new status of the message should be
66
- * @param type type from receipt
67
- */
68
- export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status | undefined;
69
- /**
70
- * Stream errors generally provide a reason, map that to a baileys DisconnectReason
71
- * @param reason the string reason given, eg. "conflict"
72
- */
73
- export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
74
- reason: string;
75
- statusCode: number;
76
- };
77
- export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
78
- export declare const getCodeFromWSError: (error: Error) => number;
79
- /**
80
- * Is the given platform WA business
81
- * @param platform AuthenticationCreds.platform
82
- */
83
- export declare const isWABusinessPlatform: (platform: string) => platform is "smba" | "smbi";
84
- export declare function trimUndefined(obj: {
85
- [_: string]: any;
86
- }): {
87
- [_: string]: any;
88
- };
89
- export declare function bytesToCrockford(buffer: Buffer): string;
90
- export declare function encodeNewsletterMessage(message: proto.IMessage): Uint8Array;
91
- //# sourceMappingURL=generics.d.ts.map
@@ -1,24 +0,0 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { Chat, Contact, LIDMapping, WAMessage } from '../Types/index.js';
3
- import type { ILogger } from './logger.js';
4
- export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: RequestInit) => Promise<proto.HistorySync>;
5
- export declare const processHistoryMessage: (item: proto.IHistorySync, logger?: ILogger) => {
6
- chats: Chat[];
7
- contacts: Contact[];
8
- messages: WAMessage[];
9
- lidPnMappings: LIDMapping[];
10
- pastParticipants: proto.IPastParticipants[] | null | undefined;
11
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
12
- progress: number | null | undefined;
13
- };
14
- export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: RequestInit, logger?: ILogger) => Promise<{
15
- chats: Chat[];
16
- contacts: Contact[];
17
- messages: WAMessage[];
18
- lidPnMappings: LIDMapping[];
19
- pastParticipants: proto.IPastParticipants[] | null | undefined;
20
- syncType: proto.HistorySync.HistorySyncType | null | undefined;
21
- progress: number | null | undefined;
22
- }>;
23
- export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification;
24
- //# sourceMappingURL=history.d.ts.map
@@ -1,44 +0,0 @@
1
- import NodeCache from '@cacheable/node-cache';
2
- import { type BinaryNode } from '../WABinary/index.js';
3
- import type { ILogger } from './logger.js';
4
- export type IdentityChangeResult = {
5
- action: 'no_identity_node';
6
- } | {
7
- action: 'invalid_notification';
8
- } | {
9
- action: 'skipped_companion_device';
10
- device: number;
11
- } | {
12
- action: 'skipped_self_primary';
13
- } | {
14
- action: 'debounced';
15
- } | {
16
- action: 'skipped_offline';
17
- } | {
18
- action: 'skipped_no_session';
19
- } | {
20
- action: 'session_refreshed';
21
- } | {
22
- action: 'session_refresh_failed';
23
- error: unknown;
24
- };
25
- export type IdentityChangeContext = {
26
- meId: string | undefined;
27
- meLid: string | undefined;
28
- validateSession: (jid: string) => Promise<{
29
- exists: boolean;
30
- reason?: string;
31
- }>;
32
- assertSessions: (jids: string[], force?: boolean) => Promise<boolean>;
33
- debounceCache: NodeCache<boolean>;
34
- logger: ILogger;
35
- /**
36
- * Invoked right before `assertSessions` is called for an existing-session identity change.
37
- * Used to kick off fire-and-forget side effects (e.g. tctoken re-issuance) in the same
38
- * order WA Web does — i.e. before the E2E session is re-established.
39
- * Must not throw; implementations are responsible for their own error handling.
40
- */
41
- onBeforeSessionRefresh?: (jid: string) => void;
42
- };
43
- export declare function handleIdentityChange(node: BinaryNode, ctx: IdentityChangeContext): Promise<IdentityChangeResult>;
44
- //# sourceMappingURL=identity-change-handler.d.ts.map
@@ -1,22 +0,0 @@
1
- export * from './generics.js';
2
- export * from './decode-wa-message.js';
3
- export * from './messages.js';
4
- export * from './messages-media.js';
5
- export * from './validate-connection.js';
6
- export * from './crypto.js';
7
- export * from './signal.js';
8
- export * from './noise-handler.js';
9
- export * from './history.js';
10
- export * from './chat-utils.js';
11
- export * from './lt-hash.js';
12
- export * from './auth-utils.js';
13
- export * from './use-multi-file-auth-state.js';
14
- export * from './link-preview.js';
15
- export * from './event-buffer.js';
16
- export * from './process-message.js';
17
- export * from './message-retry-manager.js';
18
- export * from './browser-utils.js';
19
- export * from './companion-reg-client-utils.js';
20
- export * from './identity-change-handler.js';
21
- export * from './stanza-ack.js';
22
- //# sourceMappingURL=index.d.ts.map
@@ -1,21 +0,0 @@
1
- import type { WAMediaUploadFunction, WAUrlInfo } from '../Types/index.js';
2
- import type { ILogger } from './logger.js';
3
- export type URLGenerationOptions = {
4
- thumbnailWidth: number;
5
- fetchOpts: {
6
- /** Timeout in ms */
7
- timeout: number;
8
- proxyUrl?: string;
9
- headers?: HeadersInit;
10
- };
11
- uploadImage?: WAMediaUploadFunction;
12
- logger?: ILogger;
13
- };
14
- /**
15
- * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
16
- * Return undefined if the fetch failed or no URL was found
17
- * @param text first matched URL in text
18
- * @returns the URL info required to generate link preview
19
- */
20
- export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
21
- //# sourceMappingURL=link-preview.d.ts.map
@@ -1,12 +0,0 @@
1
- export interface ILogger {
2
- level: string;
3
- child(obj: Record<string, unknown>): ILogger;
4
- trace(obj: unknown, msg?: string): void;
5
- debug(obj: unknown, msg?: string): void;
6
- info(obj: unknown, msg?: string): void;
7
- warn(obj: unknown, msg?: string): void;
8
- error(obj: unknown, msg?: string): void;
9
- }
10
- declare const _default: import("pino").Logger<never, boolean>;
11
- export default _default;
12
- //# sourceMappingURL=logger.d.ts.map
@@ -1,8 +0,0 @@
1
- import { LTHashAntiTampering } from 'whatsapp-rust-bridge';
2
- /**
3
- * LT Hash is a summation based hash algorithm that maintains the integrity of a piece of data
4
- * over a series of mutations. You can add/remove mutations and it'll return a hash equal to
5
- * if the same series of mutations was made sequentially.
6
- */
7
- export declare const LT_HASH_ANTI_TAMPERING: LTHashAntiTampering;
8
- //# sourceMappingURL=lt-hash.d.ts.map
@@ -1,9 +0,0 @@
1
- export declare const makeMutex: () => {
2
- mutex<T>(code: () => Promise<T> | T): Promise<T>;
3
- };
4
- export type Mutex = ReturnType<typeof makeMutex>;
5
- export declare const makeKeyedMutex: () => {
6
- mutex<T>(key: string, task: () => Promise<T> | T): Promise<T>;
7
- };
8
- export type KeyedMutex = ReturnType<typeof makeKeyedMutex>;
9
- //# sourceMappingURL=make-mutex.d.ts.map
@@ -1,115 +0,0 @@
1
- import type { proto } from '../../WAProto/index.js';
2
- import type { ILogger } from './logger.js';
3
- export interface RecentMessageKey {
4
- to: string;
5
- id: string;
6
- }
7
- export interface RecentMessage {
8
- message: proto.IMessage;
9
- timestamp: number;
10
- }
11
- export interface SessionRecreateHistory {
12
- [jid: string]: number;
13
- }
14
- export interface RetryCounter {
15
- [messageId: string]: number;
16
- }
17
- export type PendingPhoneRequest = Record<string, ReturnType<typeof setTimeout>>;
18
- export interface RetryStatistics {
19
- totalRetries: number;
20
- successfulRetries: number;
21
- failedRetries: number;
22
- mediaRetries: number;
23
- sessionRecreations: number;
24
- phoneRequests: number;
25
- }
26
- export declare enum RetryReason {
27
- UnknownError = 0,
28
- SignalErrorNoSession = 1,
29
- SignalErrorInvalidKey = 2,
30
- SignalErrorInvalidKeyId = 3,
31
- /** MAC verification failed - most common cause of decryption failures */
32
- SignalErrorInvalidMessage = 4,
33
- SignalErrorInvalidSignature = 5,
34
- SignalErrorFutureMessage = 6,
35
- /** Explicit MAC failure - session is definitely out of sync */
36
- SignalErrorBadMac = 7,
37
- SignalErrorInvalidSession = 8,
38
- SignalErrorInvalidMsgKey = 9,
39
- BadBroadcastEphemeralSetting = 10,
40
- UnknownCompanionNoPrekey = 11,
41
- AdvFailure = 12,
42
- StatusRevokeDelay = 13
43
- }
44
- export declare class MessageRetryManager {
45
- private logger;
46
- private recentMessagesMap;
47
- private messageKeyIndex;
48
- private sessionRecreateHistory;
49
- private retryCounters;
50
- private baseKeys;
51
- private pendingPhoneRequests;
52
- private readonly maxMsgRetryCount;
53
- private statistics;
54
- constructor(logger: ILogger, maxMsgRetryCount: number);
55
- /**
56
- * Add a recent message to the cache for retry handling
57
- */
58
- addRecentMessage(to: string, id: string, message: proto.IMessage): void;
59
- /**
60
- * Get a recent message from the cache
61
- */
62
- getRecentMessage(to: string, id: string): RecentMessage | undefined;
63
- /**
64
- * Check if a session should be recreated based on retry count, history, and error code.
65
- * MAC errors (codes 4 and 7) trigger immediate session recreation regardless of timeout.
66
- */
67
- shouldRecreateSession(jid: string, hasSession: boolean, errorCode?: RetryReason): {
68
- reason: string;
69
- recreate: boolean;
70
- };
71
- /**
72
- * Parse error code from retry receipt's retry node.
73
- * Returns undefined if no error code is present.
74
- */
75
- parseRetryErrorCode(errorAttr: string | undefined): RetryReason | undefined;
76
- /**
77
- * Check if an error code indicates a MAC failure
78
- */
79
- isMacError(errorCode: RetryReason | undefined): boolean;
80
- /**
81
- * Increment retry counter for a message
82
- */
83
- incrementRetryCount(messageId: string): number;
84
- /**
85
- * Get retry count for a message
86
- */
87
- getRetryCount(messageId: string): number;
88
- /**
89
- * Check if message has exceeded maximum retry attempts
90
- */
91
- hasExceededMaxRetries(messageId: string): boolean;
92
- /**
93
- * Mark retry as successful
94
- */
95
- markRetrySuccess(messageId: string): void;
96
- /**
97
- * Mark retry as failed
98
- */
99
- markRetryFailed(messageId: string): void;
100
- /**
101
- * Schedule a phone request with delay
102
- */
103
- schedulePhoneRequest(messageId: string, callback: () => void, delay?: number): void;
104
- /**
105
- * Cancel pending phone request
106
- */
107
- cancelPendingPhoneRequest(messageId: string): void;
108
- clear(): void;
109
- saveBaseKey(addr: string, msgId: string, baseKey: Uint8Array): void;
110
- hasSameBaseKey(addr: string, msgId: string, baseKey: Uint8Array): boolean;
111
- deleteBaseKey(addr: string, msgId: string): void;
112
- private keyToString;
113
- private removeRecentMessage;
114
- }
115
- //# sourceMappingURL=message-retry-manager.d.ts.map
@@ -1,133 +0,0 @@
1
- import { Boom } from '@hapi/boom';
2
- import type { Agent } from 'https';
3
- import { Readable, Transform } from 'stream';
4
- import { URL } from 'url';
5
- import { proto } from '../../WAProto/index.js';
6
- import { type MediaType } from '../Defaults/index.js';
7
- import type { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent, WAMessageKey } from '../Types/index.js';
8
- import { type BinaryNode } from '../WABinary/index.js';
9
- import type { ILogger } from './logger.js';
10
- export declare const hkdfInfoKey: (type: MediaType) => string;
11
- export declare const getRawMediaUploadData: (media: WAMediaUpload, mediaType: MediaType, logger?: ILogger) => Promise<{
12
- filePath: string;
13
- fileSha256: Buffer<ArrayBufferLike>;
14
- fileLength: number;
15
- }>;
16
- /** generates all the keys required to encrypt/decrypt & sign a media message */
17
- export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
18
- export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
19
- buffer: any;
20
- original: {
21
- width: any;
22
- height: any;
23
- };
24
- }>;
25
- export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
26
- export declare const generateProfilePicture: (mediaUpload: WAMediaUpload, dimensions?: {
27
- width: number;
28
- height: number;
29
- }) => Promise<{
30
- img: Buffer<ArrayBufferLike>;
31
- }>;
32
- /** gets the SHA256 of the given media message */
33
- export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
34
- export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
35
- /**
36
- referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
37
- */
38
- export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
39
- export declare const toReadable: (buffer: Buffer) => Readable;
40
- export declare const toBuffer: (stream: Readable) => Promise<Buffer<ArrayBuffer>>;
41
- export declare const getStream: (item: WAMediaUpload, opts?: RequestInit & {
42
- maxContentLength?: number;
43
- }) => Promise<{
44
- readonly stream: Readable;
45
- readonly type: "buffer";
46
- } | {
47
- readonly stream: Readable;
48
- readonly type: "readable";
49
- } | {
50
- readonly stream: Readable;
51
- readonly type: "remote";
52
- } | {
53
- readonly stream: import("fs").ReadStream;
54
- readonly type: "file";
55
- }>;
56
- /** generates a thumbnail for a given media, if required */
57
- export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
58
- logger?: ILogger;
59
- }): Promise<{
60
- thumbnail: string | undefined;
61
- originalImageDimensions: {
62
- width: number;
63
- height: number;
64
- } | undefined;
65
- }>;
66
- export declare const getHttpStream: (url: string | URL, options?: RequestInit & {
67
- isStream?: true;
68
- }) => Promise<Readable>;
69
- type EncryptedStreamOptions = {
70
- saveOriginalFileIfRequired?: boolean;
71
- logger?: ILogger;
72
- opts?: RequestInit;
73
- };
74
- export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
75
- mediaKey: Buffer<ArrayBufferLike>;
76
- originalFilePath: string | undefined;
77
- encFilePath: string;
78
- mac: Buffer<ArrayBuffer>;
79
- fileEncSha256: Buffer<ArrayBufferLike>;
80
- fileSha256: Buffer<ArrayBufferLike>;
81
- fileLength: number;
82
- }>;
83
- export declare const DEF_MEDIA_HOST = "mmg.whatsapp.net";
84
- export type MediaDownloadOptions = {
85
- startByte?: number;
86
- endByte?: number;
87
- options?: RequestInit;
88
- /** Optional media host override; falls back to DEF_MEDIA_HOST when not provided. */
89
- host?: string;
90
- };
91
- export declare const getUrlFromDirectPath: (directPath: string, host?: string) => string;
92
- export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
93
- /**
94
- * Decrypts and downloads an AES256-CBC encrypted file given the keys.
95
- * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
96
- * */
97
- export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
98
- export declare function extensionForMediaMessage(message: WAMessageContent): string;
99
- type MediaUploadResult = {
100
- url?: string;
101
- direct_path?: string;
102
- meta_hmac?: string;
103
- ts?: number;
104
- fbid?: number;
105
- };
106
- export type UploadParams = {
107
- url: string;
108
- filePath: string;
109
- headers: Record<string, string>;
110
- timeoutMs?: number;
111
- agent?: Agent;
112
- };
113
- export declare const uploadWithNodeHttp: ({ url, filePath, headers, timeoutMs, agent }: UploadParams, redirectCount?: number) => Promise<MediaUploadResult | undefined>;
114
- export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
115
- /**
116
- * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
117
- */
118
- export declare const encryptMediaRetryRequest: (key: WAMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
119
- export declare const decodeMediaRetryNode: (node: BinaryNode) => {
120
- key: WAMessageKey;
121
- media?: {
122
- ciphertext: Uint8Array;
123
- iv: Uint8Array;
124
- };
125
- error?: Boom;
126
- };
127
- export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
128
- ciphertext: Uint8Array;
129
- iv: Uint8Array;
130
- }, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
131
- export declare const getStatusCodeForMediaRetry: (code: number) => 200 | 412 | 404 | 418;
132
- export {};
133
- //# sourceMappingURL=messages-media.d.ts.map
@@ -1,91 +0,0 @@
1
- import { type Transform } from 'stream';
2
- import { proto } from '../../WAProto/index.js';
3
- import type { AnyMediaMessageContent, AnyMessageContent, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAMessageKey } from '../Types/index.js';
4
- import type { ILogger } from './logger.js';
5
- import { type MediaDownloadOptions } from './messages-media.js';
6
- type ExtractByKey<T, K extends PropertyKey> = T extends Record<K, any> ? T : never;
7
- /**
8
- * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
9
- * @param text eg. hello https://google.com
10
- * @returns the URL, eg. https://google.com
11
- */
12
- export declare const extractUrlFromText: (text: string) => string | undefined;
13
- export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions["getUrlInfo"], logger: MessageGenerationOptions["logger"]) => Promise<import("../Types/index.js").WAUrlInfo | undefined>;
14
- export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
15
- export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
16
- /**
17
- * Generate forwarded message content like WA does
18
- * @param message the message to forward
19
- * @param options.forceForward will show the message as forwarded even if it is from you
20
- */
21
- export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
22
- export declare const hasNonNullishProperty: <K extends PropertyKey>(message: AnyMessageContent, key: K) => message is ExtractByKey<AnyMessageContent, K>;
23
- export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
24
- export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => WAMessage;
25
- export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<WAMessage>;
26
- /** Get the key to access the true type of content */
27
- export declare const getContentType: (content: proto.IMessage | undefined) => keyof proto.IMessage | undefined;
28
- /**
29
- * Normalizes ephemeral, view once messages to regular message content
30
- * Eg. image messages in ephemeral messages, in view once messages etc.
31
- * @param content
32
- * @returns
33
- */
34
- export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
35
- /**
36
- * Extract the true message content from a message
37
- * Eg. extracts the inner message from a disappearing message/view once message
38
- */
39
- export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
40
- /**
41
- * Returns the device predicted by message ID
42
- */
43
- export declare const getDevice: (id: string) => "web" | "unknown" | "android" | "ios" | "desktop";
44
- /** Upserts a receipt in the message */
45
- export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, "userReceipt">, receipt: MessageUserReceipt) => void;
46
- /** Update the message with a new reaction */
47
- export declare const updateMessageWithReaction: (msg: Pick<WAMessage, "reactions">, reaction: proto.IReaction) => void;
48
- /** Update the message with a new poll update */
49
- export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, "pollUpdates">, update: proto.IPollUpdate) => void;
50
- /** Update the message with a new event response */
51
- export declare const updateMessageWithEventResponse: (msg: Pick<WAMessage, "eventResponses">, update: proto.IEventResponse) => void;
52
- type VoteAggregation = {
53
- name: string;
54
- voters: string[];
55
- };
56
- /**
57
- * Aggregates all poll updates in a poll.
58
- * @param msg the poll creation message
59
- * @param meId your jid
60
- * @returns A list of options & their voters
61
- */
62
- export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
63
- type ResponseAggregation = {
64
- response: string;
65
- responders: string[];
66
- };
67
- /**
68
- * Aggregates all event responses in an event message.
69
- * @param msg the event creation message
70
- * @param meId your jid
71
- * @returns A list of response types & their responders
72
- */
73
- export declare function getAggregateResponsesInEventMessage({ eventResponses }: Pick<WAMessage, 'eventResponses'>, meId?: string): ResponseAggregation[];
74
- /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
75
- export declare const aggregateMessageKeysNotFromMe: (keys: WAMessageKey[]) => {
76
- jid: string;
77
- participant: string | undefined;
78
- messageIds: string[];
79
- }[];
80
- type DownloadMediaMessageContext = {
81
- reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
82
- logger: ILogger;
83
- };
84
- /**
85
- * Downloads the given message. Throws an error if it's not a media message
86
- */
87
- export declare const downloadMediaMessage: <Type extends "buffer" | "stream">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer<ArrayBufferLike> : Transform>;
88
- /** Checks whether the given message is a media message; if it is returns the inner content */
89
- export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
90
- export {};
91
- //# sourceMappingURL=messages.d.ts.map
@@ -1,20 +0,0 @@
1
- import { proto } from '../../WAProto/index.js';
2
- import type { KeyPair } from '../Types/index.js';
3
- import type { BinaryNode } from '../WABinary/index.js';
4
- import type { ILogger } from './logger.js';
5
- export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, logger, routingInfo }: {
6
- keyPair: KeyPair;
7
- NOISE_HEADER: Uint8Array;
8
- logger: ILogger;
9
- routingInfo?: Buffer | undefined;
10
- }) => {
11
- encrypt: (plaintext: Uint8Array) => Uint8Array;
12
- decrypt: (ciphertext: Uint8Array) => Uint8Array;
13
- authenticate: (data: Uint8Array) => void;
14
- mixIntoKey: (data: Uint8Array) => void;
15
- finishInit: () => Promise<void>;
16
- processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Uint8Array<ArrayBufferLike>;
17
- encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
18
- decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
19
- };
20
- //# sourceMappingURL=noise-handler.d.ts.map
@@ -1,17 +0,0 @@
1
- import type { BinaryNode } from '../WABinary/index.js';
2
- export type MessageType = 'message' | 'call' | 'receipt' | 'notification';
3
- export type OfflineNodeProcessorDeps = {
4
- isWsOpen: () => boolean;
5
- onUnexpectedError: (error: Error, msg: string) => void;
6
- yieldToEventLoop: () => Promise<void>;
7
- };
8
- /**
9
- * Creates a processor for offline stanza nodes that:
10
- * - Queues nodes for sequential processing
11
- * - Yields to the event loop periodically to avoid blocking
12
- * - Catches handler errors to prevent the processing loop from crashing
13
- */
14
- export declare function makeOfflineNodeProcessor(nodeProcessorMap: Map<MessageType, (node: BinaryNode) => Promise<void>>, deps: OfflineNodeProcessorDeps, batchSize?: number): {
15
- enqueue: (type: MessageType, node: BinaryNode) => void;
16
- };
17
- //# sourceMappingURL=offline-node-processor.d.ts.map
@@ -1,28 +0,0 @@
1
- import type { SignalDataSet, SignalDataTypeMap, SignalKeyStore } from '../Types/index.js';
2
- import type { ILogger } from './logger.js';
3
- /**
4
- * Manages pre-key operations with proper concurrency control
5
- */
6
- export declare class PreKeyManager {
7
- private readonly store;
8
- private readonly logger;
9
- private readonly queues;
10
- constructor(store: SignalKeyStore, logger: ILogger);
11
- /**
12
- * Get or create a queue for a specific key type
13
- */
14
- private getQueue;
15
- /**
16
- * Process pre-key operations (updates and deletions)
17
- */
18
- processOperations(data: SignalDataSet, keyType: keyof SignalDataTypeMap, transactionCache: SignalDataSet, mutations: SignalDataSet, isInTransaction: boolean): Promise<void>;
19
- /**
20
- * Process deletions with validation
21
- */
22
- private processDeletions;
23
- /**
24
- * Validate and process pre-key deletions outside transactions
25
- */
26
- validateDeletions(data: SignalDataSet, keyType: keyof SignalDataTypeMap): Promise<void>;
27
- }
28
- //# sourceMappingURL=pre-key-manager.d.ts.map