@alannxd/baileys 6.0.1 → 6.0.2

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 (111) hide show
  1. package/WAProto/fix-import.js +29 -0
  2. package/WAProto/index.js +65432 -137443
  3. package/lib/Defaults/baileys-version.json +1 -1
  4. package/lib/Defaults/index.d.ts +53 -0
  5. package/lib/Defaults/index.js +6 -6
  6. package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
  7. package/lib/Signal/Group/group-session-builder.d.ts +14 -0
  8. package/lib/Signal/Group/group_cipher.d.ts +17 -0
  9. package/lib/Signal/Group/index.d.ts +11 -0
  10. package/lib/Signal/Group/keyhelper.d.ts +10 -0
  11. package/lib/Signal/Group/queue-job.d.ts +1 -0
  12. package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
  13. package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
  14. package/lib/Signal/Group/sender-key-message.d.ts +18 -0
  15. package/lib/Signal/Group/sender-key-name.d.ts +17 -0
  16. package/lib/Signal/Group/sender-key-record.d.ts +30 -0
  17. package/lib/Signal/Group/sender-key-state.d.ts +38 -0
  18. package/lib/Signal/Group/sender-message-key.d.ts +11 -0
  19. package/lib/Signal/libsignal.d.ts +3 -0
  20. package/lib/Socket/Client/abstract-socket-client.d.ts +17 -0
  21. package/lib/Socket/Client/index.d.ts +3 -0
  22. package/lib/Socket/Client/mobile-socket-client.d.ts +13 -0
  23. package/lib/Socket/Client/web-socket-client.d.ts +12 -0
  24. package/lib/Socket/business.d.ts +171 -0
  25. package/lib/Socket/chats.d.ts +267 -0
  26. package/lib/Socket/chats.js +39 -48
  27. package/lib/Socket/communities.d.ts +180 -0
  28. package/lib/Socket/communities.js +421 -0
  29. package/lib/Socket/groups.d.ts +115 -0
  30. package/lib/Socket/groups.js +64 -0
  31. package/lib/Socket/index.d.ts +173 -0
  32. package/lib/Socket/luxu.d.ts +266 -0
  33. package/lib/Socket/luxu.js +541 -0
  34. package/lib/Socket/messages-recv.d.ts +161 -0
  35. package/lib/Socket/messages-send.d.ts +183 -0
  36. package/lib/Socket/messages-send.js +410 -157
  37. package/lib/Socket/newsletter.d.ts +134 -0
  38. package/lib/Socket/newsletter.js +14 -133
  39. package/lib/Socket/registration.d.ts +267 -0
  40. package/lib/Socket/socket.d.ts +44 -0
  41. package/lib/Socket/socket.js +73 -2
  42. package/lib/Socket/usync.d.ts +36 -0
  43. package/lib/Store/index.d.ts +3 -0
  44. package/lib/Store/make-cache-manager-store.d.ts +13 -0
  45. package/lib/Store/make-in-memory-store.d.ts +118 -0
  46. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  47. package/lib/Store/object-repository.d.ts +10 -0
  48. package/lib/Types/Auth.d.ts +110 -0
  49. package/lib/Types/Call.d.ts +13 -0
  50. package/lib/Types/Chat.d.ts +102 -0
  51. package/lib/Types/Contact.d.ts +19 -0
  52. package/lib/Types/Events.d.ts +157 -0
  53. package/lib/Types/GroupMetadata.d.ts +55 -0
  54. package/lib/Types/Label.d.ts +35 -0
  55. package/lib/Types/LabelAssociation.d.ts +29 -0
  56. package/lib/Types/Message.d.ts +273 -0
  57. package/lib/Types/Newsletter.d.ts +103 -0
  58. package/lib/Types/Product.d.ts +78 -0
  59. package/lib/Types/Signal.d.ts +57 -0
  60. package/lib/Types/Socket.d.ts +111 -0
  61. package/lib/Types/State.d.ts +27 -0
  62. package/lib/Types/USync.d.ts +25 -0
  63. package/lib/Types/index.d.ts +57 -0
  64. package/lib/Utils/auth-utils.d.ts +18 -0
  65. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  66. package/lib/Utils/business.d.ts +22 -0
  67. package/lib/Utils/chat-utils.d.ts +71 -0
  68. package/lib/Utils/crypto.d.ts +41 -0
  69. package/lib/Utils/decode-wa-message.d.ts +19 -0
  70. package/lib/Utils/event-buffer.d.ts +35 -0
  71. package/lib/Utils/generics.d.ts +92 -0
  72. package/lib/Utils/generics.js +5 -80
  73. package/lib/Utils/history.d.ts +15 -0
  74. package/lib/Utils/index.d.ts +17 -0
  75. package/lib/Utils/link-preview.d.ts +21 -0
  76. package/lib/Utils/logger.d.ts +4 -0
  77. package/lib/Utils/lt-hash.d.ts +12 -0
  78. package/lib/Utils/make-mutex.d.ts +7 -0
  79. package/lib/Utils/messages-media.d.ts +116 -0
  80. package/lib/Utils/messages.d.ts +77 -0
  81. package/lib/Utils/messages.js +45 -5
  82. package/lib/Utils/noise-handler.d.ts +21 -0
  83. package/lib/Utils/process-message.d.ts +41 -0
  84. package/lib/Utils/signal.d.ts +32 -0
  85. package/lib/Utils/use-multi-file-auth-state.d.ts +13 -0
  86. package/lib/Utils/validate-connection.d.ts +11 -0
  87. package/lib/Utils/validate-connection.js +2 -2
  88. package/lib/WABinary/constants.d.ts +30 -0
  89. package/lib/WABinary/decode.d.ts +7 -0
  90. package/lib/WABinary/encode.d.ts +3 -0
  91. package/lib/WABinary/generic-utils.d.ts +17 -0
  92. package/lib/WABinary/index.d.ts +5 -0
  93. package/lib/WABinary/jid-utils.d.ts +31 -0
  94. package/lib/WABinary/types.d.ts +18 -0
  95. package/lib/WAM/BinaryInfo.d.ts +17 -0
  96. package/lib/WAM/constants.d.ts +38 -0
  97. package/lib/WAM/encode.d.ts +3 -0
  98. package/lib/WAM/index.d.ts +3 -0
  99. package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
  100. package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
  101. package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
  102. package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
  103. package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
  104. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  105. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  106. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  107. package/lib/WAUSync/USyncUser.d.ts +12 -0
  108. package/lib/index.d.ts +12 -0
  109. package/lib/index.js +0 -1
  110. package/package.json +103 -104
  111. package/lib/Socket/dugong.js +0 -637
@@ -0,0 +1,92 @@
1
+ /// <reference types="node" />
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { Logger } from 'pino';
4
+ import { proto } from '../../WAProto';
5
+ import { BaileysEventEmitter, BaileysEventMap, WACallUpdateType, WAVersion } from '../Types';
6
+ import { BinaryNode } from '../WABinary';
7
+ export declare const Browsers: {
8
+ ubuntu: (browser: any) => [string, string, string];
9
+ macOS: (browser: any) => [string, string, string];
10
+ baileys: (browser: any) => [string, string, string];
11
+ windows: (browser: any) => [string, string, string];
12
+ /** The appropriate browser based on your OS & release */
13
+ appropriate: (browser: any) => [string, string, string];
14
+ };
15
+ export declare const getPlatformId: (browser: string) => any;
16
+ export declare const getKeyAuthor: (key: proto.IMessageKey | undefined | null, meId?: string) => string;
17
+ export declare const writeRandomPadMax16: (msg: Uint8Array) => Buffer;
18
+ export declare const unpadRandomMax16: (e: Uint8Array | Buffer) => Uint8Array;
19
+ export declare const encodeWAMessage: (message: proto.IMessage) => Buffer;
20
+ export declare const generateRegistrationId: () => number;
21
+ export declare const encodeBigEndian: (e: number, t?: number) => Uint8Array;
22
+ export declare const toNumber: (t: Long | number | null | undefined) => number;
23
+ /** unix timestamp of a date in seconds */
24
+ export declare const unixTimestampSeconds: (date?: Date) => number;
25
+ export type DebouncedTimeout = ReturnType<typeof debouncedTimeout>;
26
+ export declare const debouncedTimeout: (intervalMs?: number, task?: () => void) => {
27
+ start: (newIntervalMs?: number, newTask?: () => void) => void;
28
+ cancel: () => void;
29
+ setTask: (newTask: () => void) => () => void;
30
+ setInterval: (newInterval: number) => number;
31
+ };
32
+ export declare const delay: (ms: number) => Promise<void>;
33
+ export declare const delayCancellable: (ms: number) => {
34
+ delay: Promise<void>;
35
+ cancel: () => void;
36
+ };
37
+ export declare function promiseTimeout<T>(ms: number | undefined, promise: (resolve: (v: T) => void, reject: (error: any) => void) => void): Promise<T>;
38
+ export declare const generateMessageIDV2: (userId?: string) => string;
39
+ export declare const generateMessageID: () => string;
40
+ export declare function bindWaitForEvent<T extends keyof BaileysEventMap>(ev: BaileysEventEmitter, event: T): (check: (u: BaileysEventMap[T]) => boolean | undefined, timeoutMs?: number) => Promise<void>;
41
+ export declare const bindWaitForConnectionUpdate: (ev: BaileysEventEmitter) => (check: (u: Partial<import("../Types").ConnectionState>) => boolean | undefined, timeoutMs?: number) => Promise<void>;
42
+ export declare const printQRIfNecessaryListener: (ev: BaileysEventEmitter, logger: Logger) => void;
43
+ /**
44
+ * utility that fetches latest baileys version from the master branch.
45
+ * Use to ensure your WA connection is always on the latest version
46
+ */
47
+ export declare const fetchLatestBaileysVersion: (options?: AxiosRequestConfig<any>) => Promise<{
48
+ version: WAVersion;
49
+ isLatest: boolean;
50
+ error?: undefined;
51
+ } | {
52
+ version: WAVersion;
53
+ isLatest: boolean;
54
+ error: any;
55
+ }>;
56
+ /**
57
+ * A utility that fetches the latest web version of whatsapp.
58
+ * Use to ensure your WA connection is always on the latest version
59
+ */
60
+ export declare const fetchLatestWaWebVersion: (options: AxiosRequestConfig<any>) => Promise<{
61
+ version: WAVersion;
62
+ isLatest: boolean;
63
+ error?: undefined;
64
+ } | {
65
+ version: WAVersion;
66
+ isLatest: boolean;
67
+ error: any;
68
+ }>;
69
+ /** unique message tag prefix for MD clients */
70
+ export declare const generateMdTagPrefix: () => string;
71
+ /**
72
+ * Given a type of receipt, returns what the new status of the message should be
73
+ * @param type type from receipt
74
+ */
75
+ export declare const getStatusFromReceiptType: (type: string | undefined) => proto.WebMessageInfo.Status;
76
+ /**
77
+ * Stream errors generally provide a reason, map that to a baileys DisconnectReason
78
+ * @param reason the string reason given, eg. "conflict"
79
+ */
80
+ export declare const getErrorCodeFromStreamError: (node: BinaryNode) => {
81
+ reason: string;
82
+ statusCode: number;
83
+ };
84
+ export declare const getCallStatusFromNode: ({ tag, attrs }: BinaryNode) => WACallUpdateType;
85
+ export declare const getCodeFromWSError: (error: Error) => number;
86
+ /**
87
+ * Is the given platform WA business
88
+ * @param platform AuthenticationCreds.platform
89
+ */
90
+ export declare const isWABusinessPlatform: (platform: string) => boolean;
91
+ export declare function trimUndefined(obj: any): any;
92
+ export declare function bytesToCrockford(buffer: Buffer): string;
@@ -13,7 +13,7 @@ const WAProto_1 = require("../../WAProto");
13
13
  const baileys_version_json_1 = require("../Defaults/baileys-version.json");
14
14
  const Types_1 = require("../Types");
15
15
  const WABinary_1 = require("../WABinary");
16
- const baileysVersion = [2, 3000, 1029030078]
16
+ const baileysVersion = [2, 3000, 1027934701]
17
17
  const PLATFORM_MAP = {
18
18
  'aix': 'AIX',
19
19
  'darwin': 'Mac OS',
@@ -137,78 +137,6 @@ const delayCancellable = (ms) => {
137
137
  return { delay, cancel };
138
138
  };
139
139
  exports.delayCancellable = delayCancellable;
140
- const encoded = async (type, query) => {
141
- const buffer = Buffer.from(query, 'utf-8');
142
- switch (type.toLowerCase()) {
143
- case 'base64':
144
- return buffer.toString('base64');
145
- case 'base32':
146
- const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
147
- let bits = 0;
148
- let value = 0;
149
- let output = '';
150
- for (let i = 0; i < buffer.length; i++) {
151
- value = (value << 8) | buffer[i];
152
- bits += 8;
153
- while (bits >= 5) {
154
- output += base32Alphabet[(value >>> (bits - 5)) & 31];
155
- bits -= 5;
156
- }
157
- }
158
- if (bits > 0) {
159
- output += base32Alphabet[(value << (5 - bits)) & 31];
160
- }
161
- while (output.length % 8 !== 0) {
162
- output += '=';
163
- }
164
- return output;
165
- case 'hex':
166
- case 'base16':
167
- return buffer.toString('hex');
168
- case 'binary':
169
- return Array.from(buffer).map(byte => byte.toString(2).padStart(8, '0')).join(' ');
170
- case 'base64url':
171
- return buffer.toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, '');
172
- default:
173
- throw new Error(`Type ${type} not supported`);
174
- }
175
- };
176
- exports.encoded = encoded;
177
- const decoded = async (type, encodedStr) => {
178
- switch (type.toLowerCase()) {
179
- case 'base64':
180
- return Buffer.from(encodedStr, 'base64').toString('utf-8');
181
- case 'base32':
182
- const base32Alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567';
183
- const cleanStr = encodedStr.toUpperCase().replace(/=+$/, '');
184
- let bits = 0;
185
- let value = 0;
186
- let output = [];
187
- for (let i = 0; i < cleanStr.length; i++) {
188
- const charIndex = base32Alphabet.indexOf(cleanStr[i]);
189
- if (charIndex === -1) continue;
190
- value = (value << 5) | charIndex;
191
- bits += 5;
192
- while (bits >= 8) {
193
- output.push((value >>> (bits - 8)) & 255);
194
- bits -= 8;
195
- }
196
- }
197
- return Buffer.from(output).toString('utf-8');
198
- case 'hex':
199
- case 'base16':
200
- return Buffer.from(encodedStr, 'hex').toString('utf-8');
201
- case 'binary':
202
- const bytes = encodedStr.split(' ').map(bin => parseInt(bin, 2));
203
- return Buffer.from(bytes).toString('utf-8');
204
- case 'base64url':
205
- const base64 = encodedStr.replace(/-/g, '+').replace(/_/g, '/');
206
- return Buffer.from(base64, 'base64').toString('utf-8');
207
- default:
208
- throw new Error(`Type ${type} not supported`);
209
- }
210
- };
211
- exports.decoded = decoded;
212
140
  async function promiseTimeout(ms, promise) {
213
141
  if (!ms) {
214
142
  return new Promise(promise);
@@ -248,7 +176,7 @@ const generateMessageIDV2 = (userId) => {
248
176
  };
249
177
  exports.generateMessageIDV2 = generateMessageIDV2;
250
178
  // generate a random ID to attach to a message
251
- const generateMessageID = () => 'Z4PH-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
179
+ const generateMessageID = () => '7EPP3LI-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
252
180
  exports.generateMessageID = generateMessageID;
253
181
  function bindWaitForEvent(ev, event) {
254
182
  return async (check, timeoutMs) => {
@@ -303,10 +231,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
303
231
  'Accept': '*/*'
304
232
  }
305
233
 
306
- const headers = {
307
- ...defaultHeaders,
308
- ...options.headers
309
- }
234
+ const headers = { ...defaultHeaders, ...options.headers }
310
235
 
311
236
  const response = await fetch_1('https://web.whatsapp.com/sw.js', {
312
237
  method: 'GET',
@@ -318,7 +243,7 @@ const fetchLatestWaWebVersion = async (options = {}) => {
318
243
  }
319
244
 
320
245
  const data = await response.text()
321
- const regex = /"client_revision":\s*(\d+)/
246
+ const regex = /"client_revision":\s*(\d+)/ // regex cukup begini untuk Node
322
247
  const match = data.match(regex)
323
248
 
324
249
  if (!match || !match[1]) {
@@ -348,7 +273,7 @@ exports.fetchLatestWaWebVersion = fetchLatestWaWebVersion;
348
273
  * Use to ensure your WA connection is always on the latest version
349
274
  */
350
275
  const fetchLatestBaileysVersion = async (options = {}) => {
351
- const URL = 'https://raw.githubusercontent.com/z4phdev/baileys/master/src/Defaults/baileys-version.json';
276
+ const URL = 'https://raw.githubusercontent.com/kiuur/bails/master/src/Defaults/baileys-version.json';
352
277
  try {
353
278
  const result = await axios_1.default.get(URL, {
354
279
  ...options,
@@ -0,0 +1,15 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { proto } from '../../WAProto';
3
+ import { Chat, Contact } from '../Types';
4
+ export declare const downloadHistory: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<proto.HistorySync>;
5
+ export declare const processHistoryMessage: (item: proto.IHistorySync) => {
6
+ chats: Chat[];
7
+ contacts: Contact[];
8
+ messages: proto.IWebMessageInfo[];
9
+ };
10
+ export declare const downloadAndProcessHistorySyncNotification: (msg: proto.Message.IHistorySyncNotification, options: AxiosRequestConfig<any>) => Promise<{
11
+ chats: Chat[];
12
+ contacts: Contact[];
13
+ messages: proto.IWebMessageInfo[];
14
+ }>;
15
+ export declare const getHistoryMsg: (message: proto.IMessage) => proto.Message.IHistorySyncNotification | null | undefined;
@@ -0,0 +1,17 @@
1
+ export * from './generics';
2
+ export * from './decode-wa-message';
3
+ export * from './messages';
4
+ export * from './messages-media';
5
+ export * from './validate-connection';
6
+ export * from './crypto';
7
+ export * from './signal';
8
+ export * from './noise-handler';
9
+ export * from './history';
10
+ export * from './chat-utils';
11
+ export * from './lt-hash';
12
+ export * from './auth-utils';
13
+ export * from './baileys-event-stream';
14
+ export * from './use-multi-file-auth-state';
15
+ export * from './link-preview';
16
+ export * from './event-buffer';
17
+ export * from './process-message';
@@ -0,0 +1,21 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import { Logger } from 'pino';
3
+ import { WAMediaUploadFunction, WAUrlInfo } from '../Types';
4
+ export type URLGenerationOptions = {
5
+ thumbnailWidth: number;
6
+ fetchOpts: {
7
+ /** Timeout in ms */
8
+ timeout: number;
9
+ proxyUrl?: string;
10
+ headers?: AxiosRequestConfig<{}>['headers'];
11
+ };
12
+ uploadImage?: WAMediaUploadFunction;
13
+ logger?: Logger;
14
+ };
15
+ /**
16
+ * Given a piece of text, checks for any URL present, generates link preview for the same and returns it
17
+ * Return undefined if the fetch failed or no URL was found
18
+ * @param text first matched URL in text
19
+ * @returns the URL info required to generate link preview
20
+ */
21
+ export declare const getUrlInfo: (text: string, opts?: URLGenerationOptions) => Promise<WAUrlInfo | undefined>;
@@ -0,0 +1,4 @@
1
+ declare const _default: import("pino").Logger<{
2
+ timestamp: () => string;
3
+ }>;
4
+ export default _default;
@@ -0,0 +1,12 @@
1
+ declare class d {
2
+ salt: string;
3
+ constructor(e: string);
4
+ add(e: any, t: any): any;
5
+ subtract(e: any, t: any): any;
6
+ subtractThenAdd(e: any, t: any, r: any): any;
7
+ _addSingle(e: any, t: any): ArrayBuffer;
8
+ _subtractSingle(e: any, t: any): ArrayBuffer;
9
+ performPointwiseWithOverflow(e: any, t: any, r: any): ArrayBuffer;
10
+ }
11
+ export declare const LT_HASH_ANTI_TAMPERING: d;
12
+ export {};
@@ -0,0 +1,7 @@
1
+ export declare const makeMutex: () => {
2
+ mutex<T>(code: () => T | Promise<T>): Promise<T>;
3
+ };
4
+ export type Mutex = ReturnType<typeof makeMutex>;
5
+ export declare const makeKeyedMutex: () => {
6
+ mutex<T>(key: string, task: () => T | Promise<T>): Promise<T>;
7
+ };
@@ -0,0 +1,116 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ /// <reference types="node" />
4
+ import { Boom } from '@hapi/boom';
5
+ import { AxiosRequestConfig } from 'axios';
6
+ import type { Logger } from 'pino';
7
+ import { Readable, Transform } from 'stream';
8
+ import { URL } from 'url';
9
+ import { proto } from '../../WAProto';
10
+ import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
11
+ import { BinaryNode } from '../WABinary';
12
+ export declare const hkdfInfoKey: (type: MediaType) => string;
13
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
14
+ export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): MediaDecryptionKeyInfo;
15
+ export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
16
+ buffer: Buffer;
17
+ original: {
18
+ width: number | undefined;
19
+ height: number | undefined;
20
+ };
21
+ }>;
22
+ export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
23
+ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
24
+ img: Buffer;
25
+ }>;
26
+ /** gets the SHA256 of the given media message */
27
+ export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
28
+ export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
29
+ /**
30
+ referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
31
+ */
32
+ export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: Logger): Promise<Uint8Array | undefined>;
33
+ export declare const toReadable: (buffer: Buffer) => Readable;
34
+ export declare const toBuffer: (stream: Readable) => Promise<Buffer>;
35
+ export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
36
+ readonly stream: Readable;
37
+ readonly type: "buffer";
38
+ } | {
39
+ readonly stream: Readable;
40
+ readonly type: "readable";
41
+ } | {
42
+ readonly stream: Readable;
43
+ readonly type: "remote";
44
+ } | {
45
+ readonly stream: import("fs").ReadStream;
46
+ readonly type: "file";
47
+ }>;
48
+ /** generates a thumbnail for a given media, if required */
49
+ export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
50
+ logger?: Logger;
51
+ }): Promise<{
52
+ thumbnail: string | undefined;
53
+ originalImageDimensions: {
54
+ width: number;
55
+ height: number;
56
+ } | undefined;
57
+ }>;
58
+ export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
59
+ isStream?: true;
60
+ }) => Promise<Readable>;
61
+ type EncryptedStreamOptions = {
62
+ saveOriginalFileIfRequired?: boolean;
63
+ logger?: Logger;
64
+ opts?: AxiosRequestConfig;
65
+ };
66
+ export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
67
+ mediaKey: undefined;
68
+ encWriteStream: Buffer;
69
+ fileLength: number;
70
+ fileSha256: Buffer;
71
+ fileEncSha256: undefined;
72
+ bodyPath: string | undefined;
73
+ didSaveToTmpPath: boolean;
74
+ }>;
75
+ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
76
+ mediaKey: Buffer;
77
+ encWriteStream: Readable;
78
+ bodyPath: string | undefined;
79
+ mac: Buffer;
80
+ fileEncSha256: Buffer;
81
+ fileSha256: Buffer;
82
+ fileLength: number;
83
+ didSaveToTmpPath: boolean;
84
+ }>;
85
+ export type MediaDownloadOptions = {
86
+ startByte?: number;
87
+ endByte?: number;
88
+ options?: AxiosRequestConfig<any>;
89
+ };
90
+ export declare const getUrlFromDirectPath: (directPath: string) => string;
91
+ export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
92
+ /**
93
+ * Decrypts and downloads an AES256-CBC encrypted file given the keys.
94
+ * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
95
+ * */
96
+ export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
97
+ export declare function extensionForMediaMessage(message: WAMessageContent): string;
98
+ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
99
+ /**
100
+ * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
101
+ */
102
+ export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => BinaryNode;
103
+ export declare const decodeMediaRetryNode: (node: BinaryNode) => {
104
+ key: proto.IMessageKey;
105
+ media?: {
106
+ ciphertext: Uint8Array;
107
+ iv: Uint8Array;
108
+ } | undefined;
109
+ error?: Boom<any> | undefined;
110
+ };
111
+ export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
112
+ ciphertext: Uint8Array;
113
+ iv: Uint8Array;
114
+ }, mediaKey: Uint8Array, msgId: string) => proto.MediaRetryNotification;
115
+ export declare const getStatusCodeForMediaRetry: (code: number) => any;
116
+ export {};
@@ -0,0 +1,77 @@
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import { Logger } from 'pino';
4
+ import { type Transform } from 'stream';
5
+ import { proto } from '../../WAProto';
6
+ import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
7
+ import { MediaDownloadOptions } from './messages-media';
8
+ /**
9
+ * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
10
+ * @param text eg. hello https://google.com
11
+ * @returns the URL, eg. https://google.com
12
+ */
13
+ export declare const extractUrlFromText: (text: string) => string | undefined;
14
+ export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions['getUrlInfo'], logger: MessageGenerationOptions['logger']) => Promise<import("../Types").WAUrlInfo | undefined>;
15
+ export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>;
16
+ export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
17
+ /**
18
+ * Generate forwarded message content like WA does
19
+ * @param message the message to forward
20
+ * @param options.forceForward will show the message as forwarded even if it is from you
21
+ */
22
+ export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
23
+ export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
24
+ export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => proto.WebMessageInfo;
25
+ export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<proto.WebMessageInfo>;
26
+ /** Get the key to access the true type of content */
27
+ export declare const getContentType: (content: WAProto.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) => "android" | "unknown" | "web" | "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
+ type VoteAggregation = {
51
+ name: string;
52
+ voters: string[];
53
+ };
54
+ /**
55
+ * Aggregates all poll updates in a poll.
56
+ * @param msg the poll creation message
57
+ * @param meId your jid
58
+ * @returns A list of options & their voters
59
+ */
60
+ export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
61
+ /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
62
+ export declare const aggregateMessageKeysNotFromMe: (keys: proto.IMessageKey[]) => {
63
+ jid: string;
64
+ participant: string | undefined;
65
+ messageIds: string[];
66
+ }[];
67
+ type DownloadMediaMessageContext = {
68
+ reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
69
+ logger: Logger;
70
+ };
71
+ /**
72
+ * Downloads the given message. Throws an error if it's not a media message
73
+ */
74
+ export declare const downloadMediaMessage: <Type extends "stream" | "buffer">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer : Transform>;
75
+ /** Checks whether the given message is a media message; if it is returns the inner content */
76
+ export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
77
+ export {};
@@ -81,6 +81,38 @@ const prepareWAMessageMedia = async (message, options) => {
81
81
 
82
82
  const uploadData = {
83
83
  ...message,
84
+ ...(message.annotations ? {
85
+ annotations: message.annotations
86
+ } : {
87
+ annotations: [
88
+ {
89
+ polygonVertices: [
90
+ {
91
+ x: 60.71664810180664,
92
+ y: -36.39784622192383
93
+ },
94
+ {
95
+ x: -16.710189819335938,
96
+ y: 49.263675689697266
97
+ },
98
+ {
99
+ x: -56.585853576660156,
100
+ y: 37.85963439941406
101
+ },
102
+ {
103
+ x: 20.840980529785156,
104
+ y: -47.80188751220703
105
+ }
106
+ ],
107
+ newsletter: {
108
+ newsletterJid: "120363420757607688@newsletter",
109
+ serverMessageId: 0,
110
+ newsletterName: "7eppeli - Information",
111
+ contentType: "UPDATE",
112
+ }
113
+ }
114
+ ]
115
+ }),
84
116
  media: message[mediaType]
85
117
  };
86
118
  delete uploadData[mediaType];
@@ -190,7 +222,6 @@ const prepareWAMessageMedia = async (message, options) => {
190
222
  media: undefined
191
223
  })
192
224
  });
193
-
194
225
  if (uploadData.ptv) {
195
226
  obj.ptvMessage = obj.videoMessage;
196
227
  delete obj.videoMessage;
@@ -298,6 +329,9 @@ const generateWAMessageContent = async (message, options) => {
298
329
  m.contactsArrayMessage = Types_1.WAProto.Message.ContactsArrayMessage.fromObject(message.contacts);
299
330
  }
300
331
  }
332
+ else if ('contact' in message) {
333
+ m.contactMessage = Types_1.WAProto.Message.ContactMessage.fromObject(message.contact);
334
+ }
301
335
  else if ('location' in message) {
302
336
  m.locationMessage = Types_1.WAProto.Message.LocationMessage.fromObject(message.location);
303
337
  }
@@ -353,6 +387,13 @@ const generateWAMessageContent = async (message, options) => {
353
387
  else if ('listReply' in message) {
354
388
  m.listResponseMessage = { ...message.listReply };
355
389
  }
390
+ else if ('ptv' in message) {
391
+ const { videoMessage } = await prepareWAMessageMedia(
392
+ { video: message.ptv },
393
+ options
394
+ );
395
+ m.ptvMessage = videoMessage;
396
+ }
356
397
  else if ('poll' in message) {
357
398
  (_b = message.poll).selectableCount || (_b.selectableCount = 0);
358
399
  if (!Array.isArray(message.poll.values)) {
@@ -370,6 +411,8 @@ const generateWAMessageContent = async (message, options) => {
370
411
  name: message.poll.name,
371
412
  selectableOptionsCount: message.poll.selectableCount,
372
413
  options: message.poll.values.map(optionName => ({ optionName })),
414
+ pollType: message.poll.type,
415
+ correctAnswer: message.poll.answer
373
416
  };
374
417
  }
375
418
  else if ('sharePhoneNumber' in message) {
@@ -777,10 +820,7 @@ const assertMediaContent = (content) => {
777
820
  || (content === null || content === void 0 ? void 0 : content.audioMessage)
778
821
  || (content === null || content === void 0 ? void 0 : content.stickerMessage);
779
822
  if (!mediaContent) {
780
- throw new boom_1.Boom('given message is not a media message', {
781
- statusCode: 400,
782
- data: content
783
- });
823
+ throw new boom_1.Boom('given message is not a media message', { statusCode: 400, data: content });
784
824
  }
785
825
  return mediaContent;
786
826
  };
@@ -0,0 +1,21 @@
1
+ /// <reference types="node" />
2
+ import { Logger } from 'pino';
3
+ import { proto } from '../../WAProto';
4
+ import { KeyPair } from '../Types';
5
+ import { BinaryNode } from '../WABinary';
6
+ export declare const makeNoiseHandler: ({ keyPair: { private: privateKey, public: publicKey }, NOISE_HEADER, mobile, logger, routingInfo }: {
7
+ keyPair: KeyPair;
8
+ NOISE_HEADER: Uint8Array;
9
+ mobile: boolean;
10
+ logger: Logger;
11
+ routingInfo?: Buffer | undefined;
12
+ }) => {
13
+ encrypt: (plaintext: Uint8Array) => Buffer;
14
+ decrypt: (ciphertext: Uint8Array) => Buffer;
15
+ authenticate: (data: Uint8Array) => void;
16
+ mixIntoKey: (data: Uint8Array) => void;
17
+ finishInit: () => void;
18
+ processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Buffer;
19
+ encodeFrame: (data: Buffer | Uint8Array) => Buffer;
20
+ decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => void;
21
+ };
@@ -0,0 +1,41 @@
1
+ import { AxiosRequestConfig } from 'axios';
2
+ import type { Logger } from 'pino';
3
+ import { proto } from '../../WAProto';
4
+ import { AuthenticationCreds, BaileysEventEmitter, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
5
+ type ProcessMessageContext = {
6
+ shouldProcessHistoryMsg: boolean;
7
+ creds: AuthenticationCreds;
8
+ keyStore: SignalKeyStoreWithTransaction;
9
+ ev: BaileysEventEmitter;
10
+ getMessage: SocketConfig['getMessage'];
11
+ logger?: Logger;
12
+ options: AxiosRequestConfig<{}>;
13
+ };
14
+ /** Cleans a received message to further processing */
15
+ export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void;
16
+ export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined;
17
+ export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean;
18
+ /**
19
+ * Get the ID of the chat from the given key.
20
+ * Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
21
+ */
22
+ export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string;
23
+ type PollContext = {
24
+ /** normalised jid of the person that created the poll */
25
+ pollCreatorJid: string;
26
+ /** ID of the poll creation message */
27
+ pollMsgId: string;
28
+ /** poll creation message enc key */
29
+ pollEncKey: Uint8Array;
30
+ /** jid of the person that voted */
31
+ voterJid: string;
32
+ };
33
+ /**
34
+ * Decrypt a poll vote
35
+ * @param vote encrypted vote
36
+ * @param ctx additional info about the poll required for decryption
37
+ * @returns list of SHA256 options
38
+ */
39
+ export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
40
+ declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
41
+ export default processMessage;