@elrayyxml/baileys 1.0.6 → 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.
- package/README.md +58 -26
- package/lib/Defaults/baileys-version.json +1 -1
- package/lib/Defaults/index.d.ts +51 -0
- package/lib/Defaults/index.js +4 -0
- package/lib/Signal/Group/ciphertext-message.d.ts +9 -0
- package/lib/Signal/Group/group-session-builder.d.ts +14 -0
- package/lib/Signal/Group/group_cipher.d.ts +17 -0
- package/lib/Signal/Group/index.d.ts +11 -0
- package/lib/Signal/Group/keyhelper.d.ts +10 -0
- package/lib/Signal/Group/queue-job.d.ts +1 -0
- package/lib/Signal/Group/sender-chain-key.d.ts +13 -0
- package/lib/Signal/Group/sender-key-distribution-message.d.ts +16 -0
- package/lib/Signal/Group/sender-key-message.d.ts +18 -0
- package/lib/Signal/Group/sender-key-name.d.ts +17 -0
- package/lib/Signal/Group/sender-key-record.d.ts +30 -0
- package/lib/Signal/Group/sender-key-state.d.ts +38 -0
- package/lib/Signal/Group/sender-message-key.d.ts +11 -0
- package/lib/Signal/libsignal.d.ts +3 -0
- package/lib/Socket/Client/index.d.ts +2 -0
- package/lib/Socket/Client/types.d.ts +16 -0
- package/lib/Socket/Client/websocket.d.ts +13 -0
- package/lib/Socket/business.d.ts +172 -0
- package/lib/Socket/chats.d.ts +82 -0
- package/lib/Socket/groups.d.ts +124 -0
- package/lib/Socket/index.d.ts +172 -0
- package/lib/Socket/messages-recv.d.ts +161 -0
- package/lib/Socket/messages-send.d.ts +151 -0
- package/lib/Socket/messages-send.js +8 -36
- package/lib/Socket/newsletter.d.ts +136 -0
- package/lib/Socket/newsletter.js +5 -1
- package/lib/Socket/socket.d.ts +43 -0
- package/lib/Socket/usync.d.ts +36 -0
- package/lib/Store/index.d.ts +2 -0
- package/lib/Store/make-in-memory-store.d.ts +118 -0
- package/lib/Store/make-ordered-dictionary.d.ts +13 -0
- package/lib/Store/object-repository.d.ts +10 -0
- package/lib/Types/Auth.d.ts +103 -0
- package/lib/Types/Call.d.ts +13 -0
- package/lib/Types/Chat.d.ts +109 -0
- package/lib/Types/Contact.d.ts +23 -0
- package/lib/Types/Events.d.ts +199 -0
- package/lib/Types/GroupMetadata.d.ts +64 -0
- package/lib/Types/Label.d.ts +35 -0
- package/lib/Types/LabelAssociation.d.ts +29 -0
- package/lib/Types/Message.d.ts +400 -0
- package/lib/Types/Newsletter.d.ts +79 -0
- package/lib/Types/Product.d.ts +78 -0
- package/lib/Types/Signal.d.ts +57 -0
- package/lib/Types/Socket.d.ts +119 -0
- package/lib/Types/State.d.ts +27 -0
- package/lib/Types/USync.d.ts +25 -0
- package/lib/Types/index.d.ts +64 -0
- package/lib/Utils/auth-utils.d.ts +18 -0
- package/lib/Utils/baileys-event-stream.d.ts +16 -0
- package/lib/Utils/business.d.ts +22 -0
- package/lib/Utils/chat-utils.d.ts +70 -0
- package/lib/Utils/crypto.d.ts +40 -0
- package/lib/Utils/decode-wa-message.d.ts +35 -0
- package/lib/Utils/event-buffer.d.ts +35 -0
- package/lib/Utils/generics.d.ts +89 -0
- package/lib/Utils/generics.js +0 -1
- package/lib/Utils/history.d.ts +19 -0
- package/lib/Utils/index.d.ts +17 -0
- package/lib/Utils/link-preview.d.ts +21 -0
- package/lib/Utils/logger.d.ts +11 -0
- package/lib/Utils/lt-hash.d.ts +12 -0
- package/lib/Utils/make-mutex.d.ts +7 -0
- package/lib/Utils/messages-media.d.ts +120 -0
- package/lib/Utils/messages.d.ts +75 -0
- package/lib/Utils/messages.js +305 -35
- package/lib/Utils/noise-handler.d.ts +19 -0
- package/lib/Utils/process-message.d.ts +42 -0
- package/lib/Utils/signal.d.ts +33 -0
- package/lib/Utils/use-multi-file-auth-state.d.ts +12 -0
- package/lib/Utils/validate-connection.d.ts +10 -0
- package/lib/WABinary/constants.d.ts +27 -0
- package/lib/WABinary/decode.d.ts +6 -0
- package/lib/WABinary/encode.d.ts +2 -0
- package/lib/WABinary/generic-utils.d.ts +14 -0
- package/lib/WABinary/generic-utils.js +1 -9
- package/lib/WABinary/index.d.ts +5 -0
- package/lib/WABinary/jid-utils.d.ts +36 -0
- package/lib/WABinary/types.d.ts +18 -0
- package/lib/WAM/BinaryInfo.d.ts +8 -0
- package/lib/WAM/constants.d.ts +38 -0
- package/lib/WAM/encode.d.ts +2 -0
- package/lib/WAM/index.d.ts +3 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts +9 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts +22 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts +12 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts +25 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts +8 -0
- package/lib/WAUSync/Protocols/index.d.ts +4 -0
- package/lib/WAUSync/USyncQuery.d.ts +28 -0
- package/lib/WAUSync/USyncUser.d.ts +12 -0
- package/lib/WAUSync/index.d.ts +3 -0
- package/lib/index.d.ts +13 -0
- package/lib/index.js +4 -1
- package/package.json +14 -13
|
@@ -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,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 {};
|
package/lib/Utils/messages.js
CHANGED
|
@@ -16,6 +16,7 @@ const WABinary_1 = require("../WABinary");
|
|
|
16
16
|
const crypto_2 = require("./crypto");
|
|
17
17
|
const generics_1 = require("./generics");
|
|
18
18
|
const messages_media_1 = require("./messages-media");
|
|
19
|
+
const fflate_1 = require("fflate");
|
|
19
20
|
const MIMETYPE_MAP = {
|
|
20
21
|
image: 'image/jpeg',
|
|
21
22
|
video: 'video/mp4',
|
|
@@ -79,38 +80,6 @@ const prepareWAMessageMedia = async (message, options) => {
|
|
|
79
80
|
}
|
|
80
81
|
const uploadData = {
|
|
81
82
|
...message,
|
|
82
|
-
...(message.annotations ? {
|
|
83
|
-
annotations: message.annotations
|
|
84
|
-
} : {
|
|
85
|
-
annotations: [
|
|
86
|
-
{
|
|
87
|
-
polygonVertices: [
|
|
88
|
-
{
|
|
89
|
-
x: 60.71664810180664,
|
|
90
|
-
y: -36.39784622192383
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
x: -16.710189819335938,
|
|
94
|
-
y: 49.263675689697266
|
|
95
|
-
},
|
|
96
|
-
{
|
|
97
|
-
x: -56.585853576660156,
|
|
98
|
-
y: 37.85963439941406
|
|
99
|
-
},
|
|
100
|
-
{
|
|
101
|
-
x: 20.840980529785156,
|
|
102
|
-
y: -47.80188751220703
|
|
103
|
-
}
|
|
104
|
-
],
|
|
105
|
-
newsletter: {
|
|
106
|
-
newsletterJid: "120363402530588049@newsletter",
|
|
107
|
-
serverMessageId: 0,
|
|
108
|
-
newsletterName: "elrayyxml notifier ",
|
|
109
|
-
contentType: "UPDATE",
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
]
|
|
113
|
-
}),
|
|
114
83
|
media: message[mediaType]
|
|
115
84
|
};
|
|
116
85
|
delete uploadData[mediaType];
|
|
@@ -321,7 +290,7 @@ exports.generateForwardMessageContent = generateForwardMessageContent;
|
|
|
321
290
|
const generateWAMessageContent = async (message, options) => {
|
|
322
291
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o;
|
|
323
292
|
var _p, _q;
|
|
324
|
-
let m = {};
|
|
293
|
+
let m = {};
|
|
325
294
|
if ('text' in message) {
|
|
326
295
|
const extContent = { text: message.text };
|
|
327
296
|
let urlInfo = message.linkPreview;
|
|
@@ -533,8 +502,8 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
533
502
|
m.messageContextInfo = {
|
|
534
503
|
// encKey
|
|
535
504
|
messageSecret: message.poll.messageSecret || (0, crypto_1.randomBytes)(32),
|
|
536
|
-
|
|
537
|
-
|
|
505
|
+
};
|
|
506
|
+
const pollCreationMessage = {
|
|
538
507
|
name: message.poll.name,
|
|
539
508
|
selectableOptionsCount: message.poll.selectableCount,
|
|
540
509
|
options: message.poll.values.map(optionName => ({ optionName })),
|
|
@@ -554,6 +523,113 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
554
523
|
}
|
|
555
524
|
}
|
|
556
525
|
}
|
|
526
|
+
else if ('stickerPack' in message) {
|
|
527
|
+
const { stickers, cover, name, publisher, packId, description } = message.stickerPack;
|
|
528
|
+
const { Readable } = require('stream');
|
|
529
|
+
const Jimp = require('jimp');
|
|
530
|
+
const stickerData = {};
|
|
531
|
+
const stickerPackId = packId || (0, generics_1.generateMessageID)();
|
|
532
|
+
const trayIconFileName = `${stickerPackId}.webp`;
|
|
533
|
+
|
|
534
|
+
const stickerPromises = stickers.map(async (s, i) => {
|
|
535
|
+
const { stream } = await (0, messages_media_1.getStream)(s.sticker);
|
|
536
|
+
const buffer = await (0, messages_media_1.toBuffer)(stream);
|
|
537
|
+
const hash = (0, crypto_2.sha256)(buffer).toString('base64url');
|
|
538
|
+
const fileName = `${i.toString().padStart(2, '0')}_${hash}.webp`;
|
|
539
|
+
stickerData[fileName] = [new Uint8Array(buffer), { level: 0 }];
|
|
540
|
+
return {
|
|
541
|
+
fileName,
|
|
542
|
+
mimetype: 'image/webp',
|
|
543
|
+
isAnimated: s.isAnimated || false,
|
|
544
|
+
isLottie: s.isLottie || false,
|
|
545
|
+
emojis: s.emojis || [],
|
|
546
|
+
accessibilityLabel: s.accessibilityLabel || ''
|
|
547
|
+
};
|
|
548
|
+
});
|
|
549
|
+
|
|
550
|
+
const stickerMetadata = await Promise.all(stickerPromises);
|
|
551
|
+
|
|
552
|
+
const coverBuffer = await (0, messages_media_1.toBuffer)((await (0, messages_media_1.getStream)(cover)).stream);
|
|
553
|
+
stickerData[trayIconFileName] = [new Uint8Array(coverBuffer), { level: 0 }];
|
|
554
|
+
|
|
555
|
+
const zipBuffer = await new Promise((resolve, reject) => {
|
|
556
|
+
(0, fflate_1.zip)(stickerData, (err, data) => {
|
|
557
|
+
if (err) reject(err);
|
|
558
|
+
else resolve(Buffer.from(data));
|
|
559
|
+
});
|
|
560
|
+
});
|
|
561
|
+
|
|
562
|
+
const stickerPackUpload = await (0, messages_media_1.encryptedStream)(
|
|
563
|
+
{ stream: Readable.from(zipBuffer) },
|
|
564
|
+
'sticker-pack', {
|
|
565
|
+
logger: options.logger,
|
|
566
|
+
opts: options.options
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
|
|
570
|
+
const stickerPackUploadResult = await options.upload(stickerPackUpload.encWriteStream, {
|
|
571
|
+
fileEncSha256B64: stickerPackUpload.fileEncSha256.toString('base64'),
|
|
572
|
+
mediaType: 'sticker-pack',
|
|
573
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
let thumbnailDirectPath, thumbnailSha256, thumbnailEncSha256, imageDataHash;
|
|
577
|
+
|
|
578
|
+
try {
|
|
579
|
+
const jimpImage = await Jimp.read(coverBuffer);
|
|
580
|
+
const thumbnailBuffer = await jimpImage.resize(252, 252).getBufferAsync(Jimp.MIME_JPEG);
|
|
581
|
+
|
|
582
|
+
const thumbUpload = await (0, messages_media_1.encryptedStream)(
|
|
583
|
+
{ stream: Readable.from(thumbnailBuffer) },
|
|
584
|
+
'thumbnail-sticker-pack', {
|
|
585
|
+
logger: options.logger,
|
|
586
|
+
opts: options.options,
|
|
587
|
+
mediaKey: stickerPackUpload.mediaKey
|
|
588
|
+
}
|
|
589
|
+
);
|
|
590
|
+
|
|
591
|
+
const thumbUploadResult = await options.upload(thumbUpload.encWriteStream, {
|
|
592
|
+
fileEncSha256B64: thumbUpload.fileEncSha256.toString('base64'),
|
|
593
|
+
mediaType: 'thumbnail-sticker-pack',
|
|
594
|
+
timeoutMs: options.mediaUploadTimeoutMs
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
thumbnailDirectPath = thumbUploadResult.directPath;
|
|
598
|
+
thumbnailSha256 = thumbUpload.fileSha256;
|
|
599
|
+
thumbnailEncSha256 = thumbUpload.fileEncSha256;
|
|
600
|
+
imageDataHash = (0, crypto_2.sha256)(thumbnailBuffer).toString('base64');
|
|
601
|
+
} catch (e) {
|
|
602
|
+
options.logger?.warn?.(`Thumbnail generation failed: ${e}`);
|
|
603
|
+
}
|
|
604
|
+
|
|
605
|
+
m.stickerPackMessage = {
|
|
606
|
+
name: name,
|
|
607
|
+
publisher: publisher,
|
|
608
|
+
stickerPackId: stickerPackId,
|
|
609
|
+
packDescription: description,
|
|
610
|
+
stickerPackOrigin: WAProto_1.proto.Message.StickerPackMessage.StickerPackOrigin.USER_CREATED,
|
|
611
|
+
stickerPackSize: zipBuffer.length,
|
|
612
|
+
stickers: stickerMetadata,
|
|
613
|
+
fileSha256: stickerPackUpload.fileSha256,
|
|
614
|
+
fileEncSha256: stickerPackUpload.fileEncSha256,
|
|
615
|
+
mediaKey: stickerPackUpload.mediaKey,
|
|
616
|
+
directPath: stickerPackUploadResult.directPath,
|
|
617
|
+
fileLength: zipBuffer.length,
|
|
618
|
+
mediaKeyTimestamp: (0, generics_1.unixTimestampSeconds)(),
|
|
619
|
+
trayIconFileName: trayIconFileName,
|
|
620
|
+
imageDataHash,
|
|
621
|
+
thumbnailDirectPath,
|
|
622
|
+
thumbnailSha256,
|
|
623
|
+
thumbnailEncSha256,
|
|
624
|
+
thumbnailHeight: 252,
|
|
625
|
+
thumbnailWidth: 252
|
|
626
|
+
};
|
|
627
|
+
|
|
628
|
+
m.stickerPackMessage.contextInfo = {
|
|
629
|
+
...(message.contextInfo || {}),
|
|
630
|
+
...(message.mentions ? { mentionedJid: message.mentions } : {})
|
|
631
|
+
};
|
|
632
|
+
}
|
|
557
633
|
else if ('event' in message) {
|
|
558
634
|
m.eventMessage = {};
|
|
559
635
|
const startTime = Math.floor(message.event.startDate.getTime() / 1000);
|
|
@@ -699,6 +775,29 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
699
775
|
};
|
|
700
776
|
m = { listMessage };
|
|
701
777
|
}
|
|
778
|
+
if ('productList' in message && !!message.productList) {
|
|
779
|
+
const thumbnail = message.thumbnail ? await (0, messages_media_1.generateThumbnail)(message.thumbnail, 'image') : null;
|
|
780
|
+
const listMessage = {
|
|
781
|
+
title: message.title,
|
|
782
|
+
buttonText: message.buttonText,
|
|
783
|
+
footerText: message.footer,
|
|
784
|
+
description: message.text,
|
|
785
|
+
productListInfo: {
|
|
786
|
+
productSections: message.productList,
|
|
787
|
+
headerImage: {
|
|
788
|
+
productId: message.productList[0].products[0].productId,
|
|
789
|
+
jpegThumbnail: (thumbnail === null || thumbnail === void 0 ? void 0 : thumbnail.thumbnail) || null
|
|
790
|
+
},
|
|
791
|
+
businessOwnerJid: message.businessOwnerJid
|
|
792
|
+
},
|
|
793
|
+
listType: WAProto_1.proto.Message.ListMessage.ListType.PRODUCT_LIST
|
|
794
|
+
};
|
|
795
|
+
listMessage.contextInfo = {
|
|
796
|
+
...(message.contextInfo || {}),
|
|
797
|
+
...(message.mentions ? { mentionedJid: message.mentions } : {})
|
|
798
|
+
};
|
|
799
|
+
m = { listMessage };
|
|
800
|
+
}
|
|
702
801
|
if ('interactiveButtons' in message && !!message.interactiveButtons) {
|
|
703
802
|
const interactiveMessage = {
|
|
704
803
|
nativeFlowMessage: Types_1.WAProto.Message.InteractiveMessage.NativeFlowMessage.fromObject({
|
|
@@ -786,9 +885,180 @@ const generateWAMessageContent = async (message, options) => {
|
|
|
786
885
|
}
|
|
787
886
|
m = { interactiveMessage };
|
|
788
887
|
}
|
|
888
|
+
if ('nativeFlowMessage' in message && !!message.nativeFlowMessage) {
|
|
889
|
+
const { nativeFlowMessage } = message;
|
|
890
|
+
let paramsJson = nativeFlowMessage.messageParamsJson;
|
|
891
|
+
if (typeof paramsJson === 'object' && paramsJson !== null) {
|
|
892
|
+
paramsJson = JSON.stringify(paramsJson);
|
|
893
|
+
}
|
|
894
|
+
const interactiveMessage = {
|
|
895
|
+
nativeFlowMessage: Types_1.WAProto.Message.InteractiveMessage.NativeFlowMessage.fromObject({
|
|
896
|
+
buttons: nativeFlowMessage.buttons,
|
|
897
|
+
messageParamsJson: paramsJson
|
|
898
|
+
})
|
|
899
|
+
};
|
|
900
|
+
if ('text' in message) {
|
|
901
|
+
interactiveMessage.body = { text: message.text };
|
|
902
|
+
} else if ('caption' in message) {
|
|
903
|
+
interactiveMessage.body = { text: message.caption };
|
|
904
|
+
}
|
|
905
|
+
interactiveMessage.header = {
|
|
906
|
+
title: message.title || message.header,
|
|
907
|
+
subtitle: message.subtitle,
|
|
908
|
+
hasMediaAttachment: false
|
|
909
|
+
};
|
|
910
|
+
if ('footer' in message) {
|
|
911
|
+
interactiveMessage.footer = { text: message.footer };
|
|
912
|
+
}
|
|
913
|
+
if ('contextInfo' in message && !!message.contextInfo) {
|
|
914
|
+
interactiveMessage.contextInfo = message.contextInfo;
|
|
915
|
+
}
|
|
916
|
+
if ('mentions' in message && !!message.mentions) {
|
|
917
|
+
interactiveMessage.contextInfo = { ...interactiveMessage.contextInfo, mentionedJid: message.mentions };
|
|
918
|
+
}
|
|
919
|
+
const contentKeys = Object.keys(m);
|
|
920
|
+
if (contentKeys.length > 0) {
|
|
921
|
+
const mediaType = contentKeys[0];
|
|
922
|
+
interactiveMessage.header[mediaType] = m[mediaType];
|
|
923
|
+
interactiveMessage.header.hasMediaAttachment = true;
|
|
924
|
+
if (interactiveMessage.header[mediaType].contextInfo) {
|
|
925
|
+
}
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
m = { interactiveMessage };
|
|
929
|
+
}
|
|
930
|
+
else if ('collection' in message && !!message.collection) {
|
|
931
|
+
const interactiveMessage = {
|
|
932
|
+
collectionMessage: {
|
|
933
|
+
bizJid: message.collection.bizJid,
|
|
934
|
+
id: message.collection.id,
|
|
935
|
+
messageVersion: message?.collection?.version
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
if ('text' in message) {
|
|
940
|
+
interactiveMessage.body = {
|
|
941
|
+
text: message.text
|
|
942
|
+
},
|
|
943
|
+
interactiveMessage.header = {
|
|
944
|
+
title: message.title,
|
|
945
|
+
subtitle: message.subtitle,
|
|
946
|
+
hasMediaAttachment: false
|
|
947
|
+
}
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
else {
|
|
951
|
+
if ('caption' in message) {
|
|
952
|
+
interactiveMessage.body = {
|
|
953
|
+
text: message.caption
|
|
954
|
+
}
|
|
955
|
+
interactiveMessage.header = {
|
|
956
|
+
title: message.title,
|
|
957
|
+
subtitle: message.subtitle,
|
|
958
|
+
hasMediaAttachment: message.hasMediaAttachment ? message.hasMediaAttachment : false,
|
|
959
|
+
...Object.assign(interactiveMessage, m)
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
if ('footer' in message && !message.footer) {
|
|
965
|
+
interactiveMessage.footer = {
|
|
966
|
+
text: message.footer
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
|
|
970
|
+
interactiveMessage.contextInfo = {
|
|
971
|
+
...(message.contextInfo || {}),
|
|
972
|
+
...(message.mentions ? { mentionedJid: message.mentions } : {})
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
m = { interactiveMessage }
|
|
976
|
+
}
|
|
977
|
+
else if ('cards' in message && !!message.cards) {
|
|
978
|
+
const slides = await Promise.all(message.cards.map(async (slide) => {
|
|
979
|
+
const { image, video, product, title, body, footer, buttons } = slide
|
|
980
|
+
let header
|
|
981
|
+
|
|
982
|
+
if (product) {
|
|
983
|
+
const { imageMessage } = await prepareWAMessageMedia({ image: product.productImage, ...options }, options)
|
|
984
|
+
header = {
|
|
985
|
+
productMessage: {
|
|
986
|
+
product: {
|
|
987
|
+
...product,
|
|
988
|
+
productImage: imageMessage,
|
|
989
|
+
},
|
|
990
|
+
...slide
|
|
991
|
+
}
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
else if (image) {
|
|
996
|
+
header = await prepareWAMessageMedia({ image: image, ...options }, options)
|
|
997
|
+
}
|
|
998
|
+
|
|
999
|
+
else if (video) {
|
|
1000
|
+
header = await prepareWAMessageMedia({ video: video, ...options }, options)
|
|
1001
|
+
}
|
|
1002
|
+
|
|
1003
|
+
const msg = {
|
|
1004
|
+
header: {
|
|
1005
|
+
title,
|
|
1006
|
+
hasMediaAttachment: true,
|
|
1007
|
+
...header
|
|
1008
|
+
},
|
|
1009
|
+
body: {
|
|
1010
|
+
text: body
|
|
1011
|
+
},
|
|
1012
|
+
footer: {
|
|
1013
|
+
text: footer
|
|
1014
|
+
},
|
|
1015
|
+
nativeFlowMessage: {
|
|
1016
|
+
buttons,
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
|
|
1020
|
+
return msg
|
|
1021
|
+
}))
|
|
1022
|
+
|
|
1023
|
+
const interactiveMessage = {
|
|
1024
|
+
carouselMessage: {
|
|
1025
|
+
cards: slides
|
|
1026
|
+
}
|
|
1027
|
+
}
|
|
1028
|
+
|
|
1029
|
+
if ('text' in message) {
|
|
1030
|
+
interactiveMessage.body = {
|
|
1031
|
+
text: message.text
|
|
1032
|
+
},
|
|
1033
|
+
interactiveMessage.header = {
|
|
1034
|
+
title: message.title,
|
|
1035
|
+
subtitle: message.subtitle,
|
|
1036
|
+
hasMediaAttachment: false
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
if ('footer' in message && !!message.footer) {
|
|
1041
|
+
interactiveMessage.footer = {
|
|
1042
|
+
text: message.footer
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1046
|
+
interactiveMessage.contextInfo = {
|
|
1047
|
+
...(message.contextInfo || {}),
|
|
1048
|
+
...(message.mentions ? { mentionedJid: message.mentions } : {})
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
m = { interactiveMessage }
|
|
1052
|
+
}
|
|
1053
|
+
if ('ephemeral' in message && !!message.ephemeral) {
|
|
1054
|
+
m = { ephemeralMessage: { message: m } }
|
|
1055
|
+
}
|
|
789
1056
|
if ('viewOnce' in message && !!message.viewOnce) {
|
|
790
1057
|
m = { viewOnceMessage: { message: m } };
|
|
791
1058
|
}
|
|
1059
|
+
if ('viewOnceExt' in message && !!message.viewOnceExt) {
|
|
1060
|
+
m = { viewOnceMessageV2Extension: { message: m } }
|
|
1061
|
+
}
|
|
792
1062
|
if ('mentions' in message && ((_o = message.mentions) === null || _o === void 0 ? void 0 : _o.length)) {
|
|
793
1063
|
const [messageType] = Object.keys(m);
|
|
794
1064
|
m[messageType].contextInfo = m[messageType] || {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ILogger } from './logger';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { KeyPair } from '../Types';
|
|
4
|
+
import { BinaryNode } from '../WABinary';
|
|
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) => Buffer<ArrayBuffer>;
|
|
12
|
+
decrypt: (ciphertext: Uint8Array) => Buffer<ArrayBuffer>;
|
|
13
|
+
authenticate: (data: Uint8Array) => void;
|
|
14
|
+
mixIntoKey: (data: Uint8Array) => Promise<void>;
|
|
15
|
+
finishInit: () => Promise<void>;
|
|
16
|
+
processHandshake: ({ serverHello }: proto.HandshakeMessage, noiseKey: KeyPair) => Promise<Buffer<ArrayBuffer>>;
|
|
17
|
+
encodeFrame: (data: Buffer | Uint8Array) => Buffer<ArrayBuffer>;
|
|
18
|
+
decodeFrame: (newData: Buffer | Uint8Array, onFrame: (buff: Uint8Array | BinaryNode) => void) => Promise<void>;
|
|
19
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import { proto } from '../../WAProto';
|
|
3
|
+
import { AuthenticationCreds, BaileysEventEmitter, CacheStore, SignalKeyStoreWithTransaction, SocketConfig } from '../Types';
|
|
4
|
+
import { ILogger } from './logger';
|
|
5
|
+
type ProcessMessageContext = {
|
|
6
|
+
shouldProcessHistoryMsg: boolean;
|
|
7
|
+
placeholderResendCache?: CacheStore;
|
|
8
|
+
creds: AuthenticationCreds;
|
|
9
|
+
keyStore: SignalKeyStoreWithTransaction;
|
|
10
|
+
ev: BaileysEventEmitter;
|
|
11
|
+
getMessage: SocketConfig['getMessage'];
|
|
12
|
+
logger?: ILogger;
|
|
13
|
+
options: AxiosRequestConfig<{}>;
|
|
14
|
+
};
|
|
15
|
+
/** Cleans a received message to further processing */
|
|
16
|
+
export declare const cleanMessage: (message: proto.IWebMessageInfo, meId: string) => void;
|
|
17
|
+
export declare const isRealMessage: (message: proto.IWebMessageInfo, meId: string) => boolean | undefined;
|
|
18
|
+
export declare const shouldIncrementChatUnread: (message: proto.IWebMessageInfo) => boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Get the ID of the chat from the given key.
|
|
21
|
+
* Typically -- that'll be the remoteJid, but for broadcasts, it'll be the participant
|
|
22
|
+
*/
|
|
23
|
+
export declare const getChatId: ({ remoteJid, participant, fromMe }: proto.IMessageKey) => string;
|
|
24
|
+
type PollContext = {
|
|
25
|
+
/** normalised jid of the person that created the poll */
|
|
26
|
+
pollCreatorJid: string;
|
|
27
|
+
/** ID of the poll creation message */
|
|
28
|
+
pollMsgId: string;
|
|
29
|
+
/** poll creation message enc key */
|
|
30
|
+
pollEncKey: Uint8Array;
|
|
31
|
+
/** jid of the person that voted */
|
|
32
|
+
voterJid: string;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Decrypt a poll vote
|
|
36
|
+
* @param vote encrypted vote
|
|
37
|
+
* @param ctx additional info about the poll required for decryption
|
|
38
|
+
* @returns list of SHA256 options
|
|
39
|
+
*/
|
|
40
|
+
export declare function decryptPollVote({ encPayload, encIv }: proto.Message.IPollEncValue, { pollCreatorJid, pollMsgId, pollEncKey, voterJid, }: PollContext): proto.Message.PollVoteMessage;
|
|
41
|
+
declare const processMessage: (message: proto.IWebMessageInfo, { shouldProcessHistoryMsg, placeholderResendCache, ev, creds, keyStore, logger, options, getMessage }: ProcessMessageContext) => Promise<void>;
|
|
42
|
+
export default processMessage;
|