@elrayyxml/baileys 1.0.3 → 1.0.7

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 (103) hide show
  1. package/README.md +2517 -0
  2. package/lib/Defaults/baileys-version.json +1 -1
  3. package/lib/Defaults/index.d.ts +51 -0
  4. package/lib/Defaults/index.js +9 -1
  5. package/lib/Defaults/phonenumber-mcc.json +223 -0
  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/index.d.ts +2 -0
  21. package/lib/Socket/Client/types.d.ts +16 -0
  22. package/lib/Socket/Client/websocket.d.ts +13 -0
  23. package/lib/Socket/business.d.ts +172 -0
  24. package/lib/Socket/chats.d.ts +82 -0
  25. package/lib/Socket/groups.d.ts +124 -0
  26. package/lib/Socket/index.d.ts +172 -0
  27. package/lib/Socket/messages-recv.d.ts +161 -0
  28. package/lib/Socket/messages-send.d.ts +151 -0
  29. package/lib/Socket/messages-send.js +236 -59
  30. package/lib/Socket/newsletter.d.ts +136 -0
  31. package/lib/Socket/newsletter.js +5 -1
  32. package/lib/Socket/socket.d.ts +43 -0
  33. package/lib/Socket/usync.d.ts +36 -0
  34. package/lib/Store/index.d.ts +2 -0
  35. package/lib/Store/make-in-memory-store.d.ts +118 -0
  36. package/lib/Store/make-ordered-dictionary.d.ts +13 -0
  37. package/lib/Store/object-repository.d.ts +10 -0
  38. package/lib/Types/Auth.d.ts +103 -0
  39. package/lib/Types/Call.d.ts +13 -0
  40. package/lib/Types/Chat.d.ts +109 -0
  41. package/lib/Types/Contact.d.ts +23 -0
  42. package/lib/Types/Events.d.ts +199 -0
  43. package/lib/Types/GroupMetadata.d.ts +64 -0
  44. package/lib/Types/Label.d.ts +35 -0
  45. package/lib/Types/LabelAssociation.d.ts +29 -0
  46. package/lib/Types/Message.d.ts +400 -0
  47. package/lib/Types/Newsletter.d.ts +79 -0
  48. package/lib/Types/Product.d.ts +78 -0
  49. package/lib/Types/Signal.d.ts +57 -0
  50. package/lib/Types/Socket.d.ts +119 -0
  51. package/lib/Types/State.d.ts +27 -0
  52. package/lib/Types/USync.d.ts +25 -0
  53. package/lib/Types/index.d.ts +64 -0
  54. package/lib/Utils/auth-utils.d.ts +18 -0
  55. package/lib/Utils/baileys-event-stream.d.ts +16 -0
  56. package/lib/Utils/business.d.ts +22 -0
  57. package/lib/Utils/chat-utils.d.ts +70 -0
  58. package/lib/Utils/crypto.d.ts +40 -0
  59. package/lib/Utils/decode-wa-message.d.ts +35 -0
  60. package/lib/Utils/event-buffer.d.ts +35 -0
  61. package/lib/Utils/generics.d.ts +89 -0
  62. package/lib/Utils/generics.js +31 -4
  63. package/lib/Utils/history.d.ts +19 -0
  64. package/lib/Utils/index.d.ts +17 -0
  65. package/lib/Utils/link-preview.d.ts +21 -0
  66. package/lib/Utils/logger.d.ts +11 -0
  67. package/lib/Utils/lt-hash.d.ts +12 -0
  68. package/lib/Utils/make-mutex.d.ts +7 -0
  69. package/lib/Utils/messages-media.d.ts +120 -0
  70. package/lib/Utils/messages.d.ts +75 -0
  71. package/lib/Utils/messages.js +400 -38
  72. package/lib/Utils/noise-handler.d.ts +19 -0
  73. package/lib/Utils/process-message.d.ts +42 -0
  74. package/lib/Utils/signal.d.ts +33 -0
  75. package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
  76. package/lib/Utils/validate-connection.d.ts +10 -0
  77. package/lib/WABinary/constants.d.ts +27 -0
  78. package/lib/WABinary/decode.d.ts +6 -0
  79. package/lib/WABinary/encode.d.ts +2 -0
  80. package/lib/WABinary/generic-utils.d.ts +14 -0
  81. package/lib/WABinary/generic-utils.js +11 -8
  82. package/lib/WABinary/index.d.ts +5 -0
  83. package/lib/WABinary/jid-utils.d.ts +36 -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/UsyncBotProfileProtocol.d.ts +25 -0
  94. package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
  95. package/lib/WAUSync/Protocols/index.d.ts +4 -0
  96. package/lib/WAUSync/USyncQuery.d.ts +28 -0
  97. package/lib/WAUSync/USyncUser.d.ts +12 -0
  98. package/lib/WAUSync/index.d.ts +3 -0
  99. package/lib/index.d.ts +13 -0
  100. package/lib/index.js +4 -1
  101. package/package.json +17 -14
  102. package/README.MD +0 -78
  103. package/lib/Socket/type.js +0 -405
@@ -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 { ILogger } from './logger';
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?: ILogger;
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,11 @@
1
+ export interface ILogger {
2
+ level: string;
3
+ child(obj: Record<string, unknown>): ILogger;
4
+ trace(obj: unknown, msg?: string): any;
5
+ debug(obj: unknown, msg?: string): any;
6
+ info(obj: unknown, msg?: string): any;
7
+ warn(obj: unknown, msg?: string): any;
8
+ error(obj: unknown, msg?: string): any;
9
+ }
10
+ declare const _default: import("pino").Logger<never, boolean>;
11
+ 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): Promise<ArrayBuffer>;
8
+ _subtractSingle(e: any, t: any): Promise<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: () => 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
+ };
@@ -0,0 +1,120 @@
1
+ import { Boom } from '@hapi/boom';
2
+ import { AxiosRequestConfig } from 'axios';
3
+ import { Readable, Transform } from 'stream';
4
+ import { URL } from 'url';
5
+ import { proto } from '../../WAProto';
6
+ import { DownloadableMessage, MediaConnInfo, MediaDecryptionKeyInfo, MediaType, SocketConfig, WAMediaUpload, WAMediaUploadFunction, WAMessageContent } from '../Types';
7
+ import { BinaryNode } from '../WABinary';
8
+ import { ILogger } from './logger';
9
+ export declare const hkdfInfoKey: (type: MediaType) => string;
10
+ /** generates all the keys required to encrypt/decrypt & sign a media message */
11
+ export declare function getMediaKeys(buffer: Uint8Array | string | null | undefined, mediaType: MediaType): Promise<MediaDecryptionKeyInfo>;
12
+ export declare function uploadFile(buffer: Buffer, logger?: ILogger): Promise<string>;
13
+ export declare function vid2jpg(videoUrl: string): Promise<string>;
14
+ /**
15
+ * Originally written by Techwiz (https://github.com/techwiz37)
16
+ * Modified for customization and improvements
17
+ */
18
+ export declare const extractVideoThumb: (videoPath: string) => Promise<Buffer<ArrayBufferLike>>;
19
+ export declare const extractImageThumb: (bufferOrFilePath: Readable | Buffer | string, width?: number) => Promise<{
20
+ buffer: Buffer<ArrayBufferLike>;
21
+ original: {
22
+ width: number;
23
+ height: number;
24
+ };
25
+ }>;
26
+ export declare const encodeBase64EncodedStringForUpload: (b64: string) => string;
27
+ export declare const generateProfilePicture: (mediaUpload: WAMediaUpload) => Promise<{
28
+ img: Buffer<ArrayBufferLike>;
29
+ }>;
30
+ /** gets the SHA256 of the given media message */
31
+ export declare const mediaMessageSHA256B64: (message: WAMessageContent) => string | null | undefined;
32
+ export declare function getAudioDuration(buffer: Buffer | string | Readable): Promise<number | undefined>;
33
+ /**
34
+ referenced from and modifying https://github.com/wppconnect-team/wa-js/blob/main/src/chat/functions/prepareAudioWaveform.ts
35
+ */
36
+ export declare function getAudioWaveform(buffer: Buffer | string | Readable, logger?: ILogger): Promise<Uint8Array<ArrayBuffer> | undefined>;
37
+ export declare const toReadable: (buffer: Buffer) => Readable;
38
+ export declare const toBuffer: (stream: Readable) => Promise<Buffer<ArrayBuffer>>;
39
+ export declare const getStream: (item: WAMediaUpload, opts?: AxiosRequestConfig) => Promise<{
40
+ readonly stream: Readable;
41
+ readonly type: "buffer";
42
+ } | {
43
+ readonly stream: Readable;
44
+ readonly type: "readable";
45
+ } | {
46
+ readonly stream: Readable;
47
+ readonly type: "remote";
48
+ } | {
49
+ readonly stream: import("fs").ReadStream;
50
+ readonly type: "file";
51
+ }>;
52
+ /** generates a thumbnail for a given media, if required */
53
+ export declare function generateThumbnail(file: string, mediaType: 'video' | 'image', options: {
54
+ logger?: ILogger;
55
+ }): Promise<{
56
+ thumbnail: string | undefined;
57
+ originalImageDimensions: {
58
+ width: number;
59
+ height: number;
60
+ } | undefined;
61
+ }>;
62
+ export declare const getHttpStream: (url: string | URL, options?: AxiosRequestConfig & {
63
+ isStream?: true;
64
+ }) => Promise<Readable>;
65
+ type EncryptedStreamOptions = {
66
+ saveOriginalFileIfRequired?: boolean;
67
+ logger?: ILogger;
68
+ opts?: AxiosRequestConfig;
69
+ };
70
+ export declare const prepareStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
71
+ mediaKey: undefined;
72
+ encWriteStream: Buffer<ArrayBuffer>;
73
+ fileLength: number;
74
+ fileSha256: Buffer<ArrayBufferLike>;
75
+ fileEncSha256: undefined;
76
+ bodyPath: string | undefined;
77
+ didSaveToTmpPath: boolean;
78
+ }>;
79
+ export declare const encryptedStream: (media: WAMediaUpload, mediaType: MediaType, { logger, saveOriginalFileIfRequired, opts }?: EncryptedStreamOptions) => Promise<{
80
+ mediaKey: Buffer<ArrayBufferLike>;
81
+ encWriteStream: Readable;
82
+ bodyPath: string | undefined;
83
+ mac: Buffer<ArrayBuffer>;
84
+ fileEncSha256: Buffer<ArrayBufferLike>;
85
+ fileSha256: Buffer<ArrayBufferLike>;
86
+ fileLength: number;
87
+ didSaveToTmpPath: boolean;
88
+ }>;
89
+ export type MediaDownloadOptions = {
90
+ startByte?: number;
91
+ endByte?: number;
92
+ options?: AxiosRequestConfig<any>;
93
+ };
94
+ export declare const getUrlFromDirectPath: (directPath: string) => string;
95
+ export declare const downloadContentFromMessage: ({ mediaKey, directPath, url }: DownloadableMessage, type: MediaType, opts?: MediaDownloadOptions) => Promise<Transform>;
96
+ /**
97
+ * Decrypts and downloads an AES256-CBC encrypted file given the keys.
98
+ * Assumes the SHA256 of the plaintext is appended to the end of the ciphertext
99
+ * */
100
+ export declare const downloadEncryptedContent: (downloadUrl: string, { cipherKey, iv }: MediaDecryptionKeyInfo, { startByte, endByte, options }?: MediaDownloadOptions) => Promise<Transform>;
101
+ export declare function extensionForMediaMessage(message: WAMessageContent): string;
102
+ export declare const getWAUploadToServer: ({ customUploadHosts, fetchAgent, logger, options }: SocketConfig, refreshMediaConn: (force: boolean) => Promise<MediaConnInfo>) => WAMediaUploadFunction;
103
+ /**
104
+ * Generate a binary node that will request the phone to re-upload the media & return the newly uploaded URL
105
+ */
106
+ export declare const encryptMediaRetryRequest: (key: proto.IMessageKey, mediaKey: Buffer | Uint8Array, meId: string) => Promise<BinaryNode>;
107
+ export declare const decodeMediaRetryNode: (node: BinaryNode) => {
108
+ key: import("../Types").WAMessageKey;
109
+ media?: {
110
+ ciphertext: Uint8Array;
111
+ iv: Uint8Array;
112
+ };
113
+ error?: Boom;
114
+ };
115
+ export declare const decryptMediaRetryData: ({ ciphertext, iv }: {
116
+ ciphertext: Uint8Array;
117
+ iv: Uint8Array;
118
+ }, mediaKey: Uint8Array, msgId: string) => Promise<proto.MediaRetryNotification>;
119
+ export declare const getStatusCodeForMediaRetry: (code: number) => any;
120
+ export {};
@@ -0,0 +1,75 @@
1
+ import { type Transform } from 'stream';
2
+ import { proto } from '../../WAProto';
3
+ import { ILogger } from './logger';
4
+ import { AnyMediaMessageContent, AnyMessageContent, MediaGenerationOptions, MessageContentGenerationOptions, MessageGenerationOptions, MessageGenerationOptionsFromContent, MessageUserReceipt, WAMessage, WAMessageContent, WAProto } from '../Types';
5
+ import { MediaDownloadOptions } from './messages-media';
6
+ /**
7
+ * Uses a regex to test whether the string contains a URL, and returns the URL if it does.
8
+ * @param text eg. hello https://google.com
9
+ * @returns the URL, eg. https://google.com
10
+ */
11
+ export declare const extractUrlFromText: (text: string) => string | undefined;
12
+ export declare const generateLinkPreviewIfRequired: (text: string, getUrlInfo: MessageGenerationOptions["getUrlInfo"], logger: MessageGenerationOptions["logger"]) => Promise<import("../Types").WAUrlInfo | undefined>;
13
+ export declare const prepareWAMessageMedia: (message: AnyMediaMessageContent, options: MediaGenerationOptions) => Promise<proto.Message>;
14
+ export declare const prepareDisappearingMessageSettingContent: (ephemeralExpiration?: number) => proto.Message;
15
+ /**
16
+ * Generate forwarded message content like WA does
17
+ * @param message the message to forward
18
+ * @param options.forceForward will show the message as forwarded even if it is from you
19
+ */
20
+ export declare const generateForwardMessageContent: (message: WAMessage, forceForward?: boolean) => proto.IMessage;
21
+ export declare const generateWAMessageContent: (message: AnyMessageContent, options: MessageContentGenerationOptions) => Promise<proto.Message>;
22
+ export declare const generateWAMessageFromContent: (jid: string, message: WAMessageContent, options: MessageGenerationOptionsFromContent) => proto.WebMessageInfo;
23
+ export declare const generateWAMessage: (jid: string, content: AnyMessageContent, options: MessageGenerationOptions) => Promise<proto.WebMessageInfo>;
24
+ /** Get the key to access the true type of content */
25
+ export declare const getContentType: (content: WAProto.IMessage | undefined) => keyof proto.IMessage | undefined;
26
+ /**
27
+ * Normalizes ephemeral, view once messages to regular message content
28
+ * Eg. image messages in ephemeral messages, in view once messages etc.
29
+ * @param content
30
+ * @returns
31
+ */
32
+ export declare const normalizeMessageContent: (content: WAMessageContent | null | undefined) => WAMessageContent | undefined;
33
+ /**
34
+ * Extract the true message content from a message
35
+ * Eg. extracts the inner message from a disappearing message/view once message
36
+ */
37
+ export declare const extractMessageContent: (content: WAMessageContent | undefined | null) => WAMessageContent | undefined;
38
+ /**
39
+ * Returns the device predicted by message ID
40
+ */
41
+ export declare const getDevice: (id: string) => "web" | "unknown" | "android" | "ios" | "desktop";
42
+ /** Upserts a receipt in the message */
43
+ export declare const updateMessageWithReceipt: (msg: Pick<WAMessage, "userReceipt">, receipt: MessageUserReceipt) => void;
44
+ /** Update the message with a new reaction */
45
+ export declare const updateMessageWithReaction: (msg: Pick<WAMessage, "reactions">, reaction: proto.IReaction) => void;
46
+ /** Update the message with a new poll update */
47
+ export declare const updateMessageWithPollUpdate: (msg: Pick<WAMessage, "pollUpdates">, update: proto.IPollUpdate) => void;
48
+ type VoteAggregation = {
49
+ name: string;
50
+ voters: string[];
51
+ };
52
+ /**
53
+ * Aggregates all poll updates in a poll.
54
+ * @param msg the poll creation message
55
+ * @param meId your jid
56
+ * @returns A list of options & their voters
57
+ */
58
+ export declare function getAggregateVotesInPollMessage({ message, pollUpdates }: Pick<WAMessage, 'pollUpdates' | 'message'>, meId?: string): VoteAggregation[];
59
+ /** Given a list of message keys, aggregates them by chat & sender. Useful for sending read receipts in bulk */
60
+ export declare const aggregateMessageKeysNotFromMe: (keys: proto.IMessageKey[]) => {
61
+ jid: string;
62
+ participant: string | undefined;
63
+ messageIds: string[];
64
+ }[];
65
+ type DownloadMediaMessageContext = {
66
+ reuploadRequest: (msg: WAMessage) => Promise<WAMessage>;
67
+ logger: ILogger;
68
+ };
69
+ /**
70
+ * Downloads the given message. Throws an error if it's not a media message
71
+ */
72
+ export declare const downloadMediaMessage: <Type extends "buffer" | "stream">(message: WAMessage, type: Type, options: MediaDownloadOptions, ctx?: DownloadMediaMessageContext) => Promise<Type extends "buffer" ? Buffer<ArrayBufferLike> : Transform>;
73
+ /** Checks whether the given message is a media message; if it is returns the inner content */
74
+ export declare const assertMediaContent: (content: proto.IMessage | null | undefined) => proto.Message.IVideoMessage | proto.Message.IImageMessage | proto.Message.IAudioMessage | proto.Message.IDocumentMessage | proto.Message.IStickerMessage;
75
+ export {};