@itsliaaa/baileys 0.2.6 → 0.3.0-rc.1
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 +1 -0
- package/WAProto/index.d.ts +377 -2465
- package/WAProto/index.js +12992 -3569
- package/lib/Defaults/index.d.ts +2 -2
- package/lib/Defaults/index.d.ts.map +1 -1
- package/lib/Defaults/index.js +7 -7
- package/lib/Defaults/index.js.map +1 -1
- package/lib/Signal/Group/ciphertext-message.d.ts.map +1 -1
- package/lib/Signal/Group/ciphertext-message.js.map +1 -1
- package/lib/Signal/Group/group-session-builder.d.ts.map +1 -1
- package/lib/Signal/Group/group-session-builder.js.map +1 -1
- package/lib/Signal/Group/group_cipher.d.ts.map +1 -1
- package/lib/Signal/Group/group_cipher.js.map +1 -1
- package/lib/Signal/Group/index.d.ts.map +1 -1
- package/lib/Signal/Group/index.js.map +1 -1
- package/lib/Signal/Group/keyhelper.d.ts.map +1 -1
- package/lib/Signal/Group/keyhelper.js.map +1 -1
- package/lib/Signal/Group/sender-chain-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-chain-key.js.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-distribution-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-message.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-message.js.map +1 -1
- package/lib/Signal/Group/sender-key-name.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-name.js.map +1 -1
- package/lib/Signal/Group/sender-key-record.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-record.js.map +1 -1
- package/lib/Signal/Group/sender-key-state.d.ts.map +1 -1
- package/lib/Signal/Group/sender-key-state.js.map +1 -1
- package/lib/Signal/Group/sender-message-key.d.ts.map +1 -1
- package/lib/Signal/Group/sender-message-key.js.map +1 -1
- package/lib/Signal/libsignal.d.ts +0 -1
- package/lib/Signal/libsignal.d.ts.map +1 -1
- package/lib/Signal/libsignal.js +0 -4
- package/lib/Signal/libsignal.js.map +1 -1
- package/lib/Signal/lid-mapping.d.ts +0 -4
- package/lib/Signal/lid-mapping.d.ts.map +1 -1
- package/lib/Signal/lid-mapping.js +0 -6
- package/lib/Signal/lid-mapping.js.map +1 -1
- package/lib/Socket/Client/index.d.ts.map +1 -1
- package/lib/Socket/Client/index.js.map +1 -1
- package/lib/Socket/Client/types.d.ts.map +1 -1
- package/lib/Socket/Client/types.js.map +1 -1
- package/lib/Socket/Client/websocket.d.ts.map +1 -1
- package/lib/Socket/Client/websocket.js.map +1 -1
- package/lib/Socket/business.d.ts +6 -46
- package/lib/Socket/business.d.ts.map +1 -1
- package/lib/Socket/business.js.map +1 -1
- package/lib/Socket/chats.d.ts +4 -3
- package/lib/Socket/chats.d.ts.map +1 -1
- package/lib/Socket/chats.js +23 -48
- package/lib/Socket/chats.js.map +1 -1
- package/lib/Socket/communities.d.ts +7 -47
- package/lib/Socket/communities.d.ts.map +1 -1
- package/lib/Socket/communities.js.map +1 -1
- package/lib/Socket/groups.d.ts +5 -36
- package/lib/Socket/groups.d.ts.map +1 -1
- package/lib/Socket/groups.js +16 -4
- package/lib/Socket/groups.js.map +1 -1
- package/lib/Socket/index.d.ts +6 -46
- package/lib/Socket/index.d.ts.map +1 -1
- package/lib/Socket/index.js.map +1 -1
- package/lib/Socket/messages-recv.d.ts +6 -46
- package/lib/Socket/messages-recv.d.ts.map +1 -1
- package/lib/Socket/messages-recv.js +46 -192
- package/lib/Socket/messages-recv.js.map +1 -1
- package/lib/Socket/messages-send.d.ts +6 -40
- package/lib/Socket/messages-send.d.ts.map +1 -1
- package/lib/Socket/messages-send.js +11 -29
- package/lib/Socket/messages-send.js.map +1 -1
- package/lib/Socket/mex.d.ts.map +1 -1
- package/lib/Socket/mex.js.map +1 -1
- package/lib/Socket/newsletter.d.ts +6 -40
- package/lib/Socket/newsletter.d.ts.map +1 -1
- package/lib/Socket/newsletter.js +14 -56
- package/lib/Socket/newsletter.js.map +1 -1
- package/lib/Socket/socket.d.ts +1 -3
- package/lib/Socket/socket.d.ts.map +1 -1
- package/lib/Socket/socket.js +1 -16
- package/lib/Socket/socket.js.map +1 -1
- package/lib/Store/index.d.ts.map +1 -1
- package/lib/Store/index.js.map +1 -1
- package/lib/Store/make-in-memory-store.d.ts.map +1 -1
- package/lib/Store/make-in-memory-store.js.map +1 -1
- package/lib/Store/make-ordered-dictionary.d.ts.map +1 -1
- package/lib/Store/make-ordered-dictionary.js.map +1 -1
- package/lib/Store/object-repository.d.ts.map +1 -1
- package/lib/Store/object-repository.js.map +1 -1
- package/lib/Types/Auth.d.ts.map +1 -1
- package/lib/Types/Auth.js.map +1 -1
- package/lib/Types/Bussines.d.ts.map +1 -1
- package/lib/Types/Bussines.js.map +1 -1
- package/lib/Types/Call.d.ts.map +1 -1
- package/lib/Types/Call.js.map +1 -1
- package/lib/Types/Chat.d.ts.map +1 -1
- package/lib/Types/Chat.js.map +1 -1
- package/lib/Types/Contact.d.ts.map +1 -1
- package/lib/Types/Contact.js.map +1 -1
- package/lib/Types/Events.d.ts.map +1 -1
- package/lib/Types/Events.js.map +1 -1
- package/lib/Types/GroupMetadata.d.ts.map +1 -1
- package/lib/Types/GroupMetadata.js.map +1 -1
- package/lib/Types/Label.d.ts.map +1 -1
- package/lib/Types/Label.js.map +1 -1
- package/lib/Types/LabelAssociation.d.ts.map +1 -1
- package/lib/Types/LabelAssociation.js.map +1 -1
- package/lib/Types/Message.d.ts.map +1 -1
- package/lib/Types/Message.js.map +1 -1
- package/lib/Types/Newsletter.d.ts.map +1 -1
- package/lib/Types/Newsletter.js +4 -3
- package/lib/Types/Newsletter.js.map +1 -1
- package/lib/Types/Product.d.ts.map +1 -1
- package/lib/Types/Product.js.map +1 -1
- package/lib/Types/RichType.d.ts.map +1 -1
- package/lib/Types/RichType.js.map +1 -1
- package/lib/Types/Signal.d.ts.map +1 -1
- package/lib/Types/Signal.js.map +1 -1
- package/lib/Types/Socket.d.ts.map +1 -1
- package/lib/Types/Socket.js.map +1 -1
- package/lib/Types/State.d.ts.map +1 -1
- package/lib/Types/State.js.map +1 -1
- package/lib/Types/USync.d.ts.map +1 -1
- package/lib/Types/USync.js.map +1 -1
- package/lib/Types/index.d.ts.map +1 -1
- package/lib/Types/index.js.map +1 -1
- package/lib/Utils/auth-utils.d.ts +1 -0
- package/lib/Utils/auth-utils.d.ts.map +1 -1
- package/lib/Utils/auth-utils.js +12 -0
- package/lib/Utils/auth-utils.js.map +1 -1
- package/lib/Utils/browser-utils.d.ts +0 -1
- package/lib/Utils/browser-utils.d.ts.map +1 -1
- package/lib/Utils/browser-utils.js +1 -2
- package/lib/Utils/browser-utils.js.map +1 -1
- package/lib/Utils/business.d.ts.map +1 -1
- package/lib/Utils/business.js.map +1 -1
- package/lib/Utils/chat-utils.d.ts +4 -4
- package/lib/Utils/chat-utils.d.ts.map +1 -1
- package/lib/Utils/chat-utils.js +23 -24
- package/lib/Utils/chat-utils.js.map +1 -1
- package/lib/Utils/companion-reg-client-utils.d.ts +1 -12
- package/lib/Utils/companion-reg-client-utils.d.ts.map +1 -1
- package/lib/Utils/companion-reg-client-utils.js +20 -13
- package/lib/Utils/companion-reg-client-utils.js.map +1 -1
- package/lib/Utils/crypto.d.ts.map +1 -1
- package/lib/Utils/crypto.js.map +1 -1
- package/lib/Utils/decode-wa-message.d.ts.map +1 -1
- package/lib/Utils/decode-wa-message.js +9 -1
- package/lib/Utils/decode-wa-message.js.map +1 -1
- package/lib/Utils/event-buffer.d.ts +0 -1
- package/lib/Utils/event-buffer.d.ts.map +1 -1
- package/lib/Utils/event-buffer.js +1 -17
- package/lib/Utils/event-buffer.js.map +1 -1
- package/lib/Utils/generics.d.ts.map +1 -1
- package/lib/Utils/generics.js +4 -4
- package/lib/Utils/generics.js.map +1 -1
- package/lib/Utils/history.d.ts.map +1 -1
- package/lib/Utils/history.js.map +1 -1
- package/lib/Utils/identity-change-handler.d.ts.map +1 -1
- package/lib/Utils/identity-change-handler.js.map +1 -1
- package/lib/Utils/index.d.ts +1 -1
- package/lib/Utils/index.d.ts.map +1 -1
- package/lib/Utils/index.js +1 -1
- package/lib/Utils/index.js.map +1 -1
- package/lib/Utils/link-preview.d.ts.map +1 -1
- package/lib/Utils/link-preview.js.map +1 -1
- package/lib/Utils/logger.d.ts.map +1 -1
- package/lib/Utils/logger.js.map +1 -1
- package/lib/Utils/lt-hash.d.ts.map +1 -1
- package/lib/Utils/lt-hash.js.map +1 -1
- package/lib/Utils/make-mutex.d.ts.map +1 -1
- package/lib/Utils/make-mutex.js.map +1 -1
- package/lib/Utils/message-retry-manager.d.ts +0 -1
- package/lib/Utils/message-retry-manager.d.ts.map +1 -1
- package/lib/Utils/message-retry-manager.js +1 -18
- package/lib/Utils/message-retry-manager.js.map +1 -1
- package/lib/Utils/messages-media.d.ts.map +1 -1
- package/lib/Utils/messages-media.js +6 -3
- package/lib/Utils/messages-media.js.map +1 -1
- package/lib/Utils/messages.d.ts +3 -12
- package/lib/Utils/messages.d.ts.map +1 -1
- package/lib/Utils/messages.js +184 -189
- package/lib/Utils/messages.js.map +1 -1
- package/lib/Utils/noise-handler.d.ts.map +1 -1
- package/lib/Utils/noise-handler.js.map +1 -1
- package/lib/Utils/offline-node-processor.d.ts.map +1 -1
- package/lib/Utils/offline-node-processor.js.map +1 -1
- package/lib/Utils/pre-key-manager.d.ts.map +1 -1
- package/lib/Utils/pre-key-manager.js.map +1 -1
- package/lib/Utils/process-message.d.ts.map +1 -1
- package/lib/Utils/process-message.js +18 -2
- package/lib/Utils/process-message.js.map +1 -1
- package/lib/Utils/reporting-utils.d.ts.map +1 -1
- package/lib/Utils/reporting-utils.js.map +1 -1
- package/lib/Utils/rich-message-utils.d.ts +8 -3
- package/lib/Utils/rich-message-utils.d.ts.map +1 -1
- package/lib/Utils/rich-message-utils.js +1 -1
- package/lib/Utils/rich-message-utils.js.map +1 -1
- package/lib/Utils/signal.d.ts +1 -1
- package/lib/Utils/signal.d.ts.map +1 -1
- package/lib/Utils/signal.js.map +1 -1
- package/lib/Utils/stanza-ack.d.ts.map +1 -1
- package/lib/Utils/stanza-ack.js.map +1 -1
- package/lib/Utils/sync-action-utils.d.ts.map +1 -1
- package/lib/Utils/sync-action-utils.js.map +1 -1
- package/lib/Utils/tc-token-utils.d.ts.map +1 -1
- package/lib/Utils/tc-token-utils.js +0 -1
- package/lib/Utils/tc-token-utils.js.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-multi-file-auth-state.js.map +1 -1
- package/lib/Utils/use-single-file-auth-state.d.ts.map +1 -1
- package/lib/Utils/use-single-file-auth-state.js.map +1 -1
- package/lib/Utils/validate-connection.d.ts +1 -1
- package/lib/Utils/validate-connection.d.ts.map +1 -1
- package/lib/Utils/validate-connection.js +2 -9
- package/lib/Utils/validate-connection.js.map +1 -1
- package/lib/WABinary/constants.d.ts.map +1 -1
- package/lib/WABinary/constants.js.map +1 -1
- package/lib/WABinary/decode.d.ts.map +1 -1
- package/lib/WABinary/decode.js.map +1 -1
- package/lib/WABinary/encode.d.ts.map +1 -1
- package/lib/WABinary/encode.js.map +1 -1
- package/lib/WABinary/generic-utils.d.ts +1 -3
- package/lib/WABinary/generic-utils.d.ts.map +1 -1
- package/lib/WABinary/generic-utils.js +6 -7
- package/lib/WABinary/generic-utils.js.map +1 -1
- package/lib/WABinary/index.d.ts.map +1 -1
- package/lib/WABinary/index.js.map +1 -1
- package/lib/WABinary/jid-utils.d.ts.map +1 -1
- package/lib/WABinary/jid-utils.js.map +1 -1
- package/lib/WABinary/types.d.ts.map +1 -1
- package/lib/WABinary/types.js.map +1 -1
- package/lib/WAM/BinaryInfo.d.ts.map +1 -1
- package/lib/WAM/BinaryInfo.js.map +1 -1
- package/lib/WAM/constants.d.ts.map +1 -1
- package/lib/WAM/constants.js.map +1 -1
- package/lib/WAM/encode.d.ts.map +1 -1
- package/lib/WAM/encode.js.map +1 -1
- package/lib/WAM/index.d.ts.map +1 -1
- package/lib/WAM/index.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncContactProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +3 -1
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js.map +1 -1
- package/lib/WAUSync/Protocols/index.d.ts.map +1 -1
- package/lib/WAUSync/Protocols/index.js.map +1 -1
- package/lib/WAUSync/USyncQuery.d.ts.map +1 -1
- package/lib/WAUSync/USyncQuery.js.map +1 -1
- package/lib/WAUSync/USyncUser.d.ts.map +1 -1
- package/lib/WAUSync/USyncUser.js.map +1 -1
- package/lib/WAUSync/index.d.ts.map +1 -1
- package/lib/WAUSync/index.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/package.json +2 -2
package/lib/Utils/messages.js
CHANGED
|
@@ -5,7 +5,7 @@ import { promises as fs } from 'fs';
|
|
|
5
5
|
import { proto } from '../../WAProto/index.js';
|
|
6
6
|
import { CALL_AUDIO_PREFIX, CALL_VIDEO_PREFIX, DONATE_URL, LIBRARY_NAME, MEDIA_KEYS, URL_REGEX, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
|
|
7
7
|
import { AssociationType, ButtonHeaderType, ButtonType, CarouselCardType, ListType, ProtocolType, WAMessageStatus, WAProto } from '../Types/index.js';
|
|
8
|
-
import {
|
|
8
|
+
import { isLidUser, isPnUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast, jidNormalizedUser } from '../WABinary/index.js';
|
|
9
9
|
import { sha256 } from './crypto.js';
|
|
10
10
|
import { generateMessageIDV2, getKeyAuthor, unixTimestampSeconds } from './generics.js';
|
|
11
11
|
import { downloadContentFromMessage, encryptedStream, generateThumbnail, getAudioDuration, getAudioWaveform, getImageProcessingLibrary, getRawMediaUploadData, getStream, toBuffer } from './messages-media.js';
|
|
@@ -82,26 +82,33 @@ const assertColor = async (color) => {
|
|
|
82
82
|
return assertedColor;
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
|
-
// Lia@Changes 21-04-26 --- Refactor prepareWAMessageMedia function
|
|
86
85
|
export const prepareWAMessageMedia = async (message, options) => {
|
|
87
86
|
const logger = options.logger;
|
|
88
|
-
|
|
87
|
+
let mediaType;
|
|
88
|
+
for (const key of MEDIA_KEYS) {
|
|
89
|
+
if (key in message) {
|
|
90
|
+
mediaType = key;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
89
93
|
if (!mediaType) {
|
|
90
94
|
throw new Boom('Invalid media type', { statusCode: 400 });
|
|
91
95
|
}
|
|
92
|
-
const uploadData = {
|
|
93
|
-
|
|
96
|
+
const uploadData = {
|
|
97
|
+
...message,
|
|
98
|
+
media: message[mediaType]
|
|
99
|
+
};
|
|
94
100
|
delete uploadData[mediaType];
|
|
95
101
|
if (uploadData.image || uploadData.video) {
|
|
96
102
|
uploadData.annotations = mediaAnnotation;
|
|
97
103
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
104
|
+
// check if cacheable + generate cache key
|
|
105
|
+
const cacheableKey = typeof uploadData.media === 'object' &&
|
|
106
|
+
'url' in uploadData.media &&
|
|
107
|
+
!!uploadData.media.url &&
|
|
101
108
|
!!options.mediaCache &&
|
|
102
|
-
|
|
109
|
+
mediaType + ':' + uploadData.media.url.toString();
|
|
103
110
|
if (mediaType === 'document' && !uploadData.fileName) {
|
|
104
|
-
uploadData.fileName =
|
|
111
|
+
uploadData.fileName = 'file';
|
|
105
112
|
}
|
|
106
113
|
if (!uploadData.mimetype) {
|
|
107
114
|
uploadData.mimetype = MIMETYPE_MAP[mediaType];
|
|
@@ -112,149 +119,133 @@ export const prepareWAMessageMedia = async (message, options) => {
|
|
|
112
119
|
logger?.debug({ cacheableKey }, 'got media cache hit');
|
|
113
120
|
const obj = proto.Message.decode(mediaBuff);
|
|
114
121
|
const key = `${mediaType}Message`;
|
|
115
|
-
Object.assign(obj[key], uploadData);
|
|
122
|
+
Object.assign(obj[key], { ...uploadData, media: undefined });
|
|
116
123
|
return obj;
|
|
117
124
|
}
|
|
118
125
|
}
|
|
119
|
-
const isNewsletter = isJidNewsletter(options.jid);
|
|
120
|
-
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
121
|
-
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData.jpegThumbnail === 'undefined';
|
|
122
|
-
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
|
|
123
|
-
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
124
|
-
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation || requiresWaveformProcessing;
|
|
125
|
-
let mediaUrl, directPath, thumbnailDirectPath, thumbnailSha256, fileSha256, fileLength, mediaKey, fileEncSha256;
|
|
126
|
-
// Lia@Changes 06-02-26 --- Add few support for sending media to newsletter (≧▽≦)
|
|
126
|
+
const isNewsletter = !!options.jid && isJidNewsletter(options.jid);
|
|
127
127
|
if (isNewsletter) {
|
|
128
128
|
logger?.info({ key: cacheableKey }, 'Preparing raw media for newsletter');
|
|
129
|
-
const
|
|
130
|
-
fileSha256 = rawData.fileSha256;
|
|
131
|
-
fileLength = rawData.fileLength;
|
|
132
|
-
const filePath = rawData.filePath;
|
|
129
|
+
const { filePath, fileSha256, fileLength } = await getRawMediaUploadData(uploadData.media, options.mediaTypeOverride || mediaType, logger);
|
|
133
130
|
const fileSha256B64 = fileSha256.toString('base64');
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
newsletter: true
|
|
140
|
-
}),
|
|
141
|
-
(async () => {
|
|
142
|
-
try {
|
|
143
|
-
if (requiresThumbnailComputation) {
|
|
144
|
-
const { thumbnail } = await generateThumbnail(filePath, mediaType, options);
|
|
145
|
-
uploadData.jpegThumbnail = thumbnail;
|
|
146
|
-
}
|
|
147
|
-
if (requiresDurationComputation) {
|
|
148
|
-
uploadData.seconds = await getAudioDuration(filePath);
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
logger?.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
153
|
-
}
|
|
154
|
-
})()
|
|
155
|
-
]);
|
|
156
|
-
// todo: add more support here
|
|
157
|
-
mediaUrl = uploadResult.mediaUrl;
|
|
158
|
-
directPath = uploadResult.directPath;
|
|
159
|
-
thumbnailDirectPath = uploadResult.thumbnailDirectPath;
|
|
160
|
-
thumbnailSha256 = uploadResult.thumbnailSha256;
|
|
161
|
-
fs.unlink(filePath).catch(() => logger?.warn('failed to remove tmp file'));
|
|
162
|
-
}
|
|
163
|
-
else {
|
|
164
|
-
const encryptedData = await encryptedStream(mediaPayload, options.mediaTypeOverride || mediaType, {
|
|
165
|
-
logger,
|
|
166
|
-
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
167
|
-
opts: options.options
|
|
131
|
+
const { mediaUrl, directPath, thumbnailDirectPath, thumbnailSha256 } = await options.upload(filePath, {
|
|
132
|
+
fileEncSha256B64: fileSha256B64,
|
|
133
|
+
mediaType: mediaType,
|
|
134
|
+
timeoutMs: options.mediaUploadTimeoutMs,
|
|
135
|
+
newsletter: isNewsletter
|
|
168
136
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
137
|
+
await fs.unlink(filePath);
|
|
138
|
+
const obj = WAProto.Message.fromObject({
|
|
139
|
+
// todo: add more support here
|
|
140
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
141
|
+
url: mediaUrl,
|
|
142
|
+
directPath,
|
|
143
|
+
fileSha256,
|
|
144
|
+
fileLength,
|
|
145
|
+
thumbnailDirectPath,
|
|
146
|
+
thumbnailSha256,
|
|
147
|
+
...uploadData,
|
|
148
|
+
media: undefined
|
|
149
|
+
})
|
|
150
|
+
});
|
|
151
|
+
if (uploadData.ptv) {
|
|
152
|
+
obj.ptvMessage = obj.videoMessage;
|
|
153
|
+
delete obj.videoMessage;
|
|
154
|
+
}
|
|
155
|
+
if (obj.stickerMessage) {
|
|
156
|
+
obj.stickerMessage.stickerSentTs = Date.now();
|
|
157
|
+
}
|
|
158
|
+
if (cacheableKey) {
|
|
159
|
+
logger?.debug({ cacheableKey }, 'set cache');
|
|
160
|
+
await options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
161
|
+
}
|
|
162
|
+
return obj;
|
|
163
|
+
}
|
|
164
|
+
const requiresDurationComputation = mediaType === 'audio' && typeof uploadData.seconds === 'undefined';
|
|
165
|
+
const requiresThumbnailComputation = (mediaType === 'image' || mediaType === 'video') && typeof uploadData['jpegThumbnail'] === 'undefined';
|
|
166
|
+
const requiresWaveformProcessing = mediaType === 'audio' && uploadData.ptt === true && typeof uploadData.waveform === 'undefined';
|
|
167
|
+
const requiresAudioBackground = options.backgroundColor && mediaType === 'audio' && uploadData.ptt === true;
|
|
168
|
+
const requiresOriginalForSomeProcessing = requiresDurationComputation || requiresThumbnailComputation;
|
|
169
|
+
const { mediaKey, encFilePath, originalFilePath, fileEncSha256, fileSha256, fileLength } = await encryptedStream(uploadData.media, options.mediaTypeOverride || mediaType, {
|
|
170
|
+
logger,
|
|
171
|
+
saveOriginalFileIfRequired: requiresOriginalForSomeProcessing,
|
|
172
|
+
opts: options.options
|
|
173
|
+
});
|
|
174
|
+
const fileEncSha256B64 = fileEncSha256.toString('base64');
|
|
175
|
+
const [{ mediaUrl, directPath }] = await Promise.all([
|
|
176
|
+
(async () => {
|
|
177
|
+
const result = await options.upload(encFilePath, {
|
|
178
178
|
fileEncSha256B64,
|
|
179
179
|
mediaType,
|
|
180
180
|
timeoutMs: options.mediaUploadTimeoutMs
|
|
181
|
-
})
|
|
182
|
-
(
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
if (requiresWaveformProcessing) {
|
|
196
|
-
uploadData.waveform = await getAudioWaveform(originalFilePath, logger);
|
|
197
|
-
}
|
|
198
|
-
if (requiresAudioBackground) {
|
|
199
|
-
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
181
|
+
});
|
|
182
|
+
logger?.debug({ mediaType, cacheableKey }, 'uploaded media');
|
|
183
|
+
return result;
|
|
184
|
+
})(),
|
|
185
|
+
(async () => {
|
|
186
|
+
try {
|
|
187
|
+
if (requiresThumbnailComputation) {
|
|
188
|
+
const { thumbnail, originalImageDimensions } = await generateThumbnail(originalFilePath, mediaType, options);
|
|
189
|
+
uploadData.jpegThumbnail = thumbnail;
|
|
190
|
+
if (!uploadData.width && originalImageDimensions) {
|
|
191
|
+
uploadData.width = originalImageDimensions.width;
|
|
192
|
+
uploadData.height = originalImageDimensions.height;
|
|
193
|
+
logger?.debug('set dimensions');
|
|
200
194
|
}
|
|
195
|
+
logger?.debug('generated thumbnail');
|
|
201
196
|
}
|
|
202
|
-
|
|
203
|
-
|
|
197
|
+
if (requiresDurationComputation) {
|
|
198
|
+
uploadData.seconds = await getAudioDuration(originalFilePath);
|
|
199
|
+
logger?.debug('computed audio duration');
|
|
204
200
|
}
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
201
|
+
if (requiresWaveformProcessing) {
|
|
202
|
+
uploadData.waveform = await getAudioWaveform(originalFilePath, logger);
|
|
203
|
+
logger?.debug('processed waveform');
|
|
204
|
+
}
|
|
205
|
+
if (requiresAudioBackground) {
|
|
206
|
+
uploadData.backgroundArgb = await assertColor(options.backgroundColor);
|
|
207
|
+
logger?.debug('computed backgroundColor audio status');
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
catch (error) {
|
|
211
|
+
logger?.warn({ trace: error.stack }, 'failed to obtain extra info');
|
|
212
|
+
}
|
|
213
|
+
})()
|
|
214
|
+
]).finally(async () => {
|
|
215
|
+
try {
|
|
216
|
+
await fs.unlink(encFilePath);
|
|
217
|
+
if (originalFilePath) {
|
|
218
|
+
await fs.unlink(originalFilePath);
|
|
219
|
+
}
|
|
220
|
+
logger?.debug('removed tmp files');
|
|
221
|
+
}
|
|
222
|
+
catch (error) {
|
|
223
|
+
logger?.warn('failed to remove tmp file');
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
const obj = WAProto.Message.fromObject({
|
|
227
|
+
[`${mediaType}Message`]: MessageTypeProto[mediaType].fromObject({
|
|
228
|
+
url: mediaUrl,
|
|
229
|
+
directPath,
|
|
230
|
+
mediaKey,
|
|
231
|
+
fileEncSha256,
|
|
232
|
+
fileSha256,
|
|
233
|
+
fileLength,
|
|
234
|
+
mediaKeyTimestamp: unixTimestampSeconds(),
|
|
235
|
+
...uploadData,
|
|
236
|
+
media: undefined
|
|
237
|
+
})
|
|
230
238
|
});
|
|
231
239
|
if (uploadData.ptv) {
|
|
232
240
|
obj.ptvMessage = obj.videoMessage;
|
|
233
241
|
delete obj.videoMessage;
|
|
234
242
|
}
|
|
235
|
-
if (obj.stickerMessage) {
|
|
236
|
-
obj.stickerMessage.stickerSentTs = Date.now();
|
|
237
|
-
}
|
|
238
243
|
if (cacheableKey) {
|
|
239
|
-
logger?.debug({ cacheableKey }, 'set cache
|
|
240
|
-
options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
244
|
+
logger?.debug({ cacheableKey }, 'set cache');
|
|
245
|
+
await options.mediaCache.set(cacheableKey, WAProto.Message.encode(obj).finish());
|
|
241
246
|
}
|
|
242
247
|
return obj;
|
|
243
248
|
};
|
|
244
|
-
export const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
245
|
-
ephemeralExpiration = ephemeralExpiration || 0;
|
|
246
|
-
const content = {
|
|
247
|
-
ephemeralMessage: {
|
|
248
|
-
message: {
|
|
249
|
-
protocolMessage: {
|
|
250
|
-
type: ProtocolType.EPHEMERAL_SETTING,
|
|
251
|
-
ephemeralExpiration
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
};
|
|
256
|
-
return content;
|
|
257
|
-
};
|
|
258
249
|
// Lia@Changes 31-01-26 --- Extract product message into a standalone function so it can also be reused as the header for interactive messages
|
|
259
250
|
const prepareProductMessage = async (message, options) => {
|
|
260
251
|
if (!message.businessOwnerJid) {
|
|
@@ -562,13 +553,27 @@ const prepareNativeFlowButtons = (message) => {
|
|
|
562
553
|
messageVersion: 1
|
|
563
554
|
};
|
|
564
555
|
};
|
|
556
|
+
export const prepareDisappearingMessageSettingContent = (ephemeralExpiration) => {
|
|
557
|
+
ephemeralExpiration = ephemeralExpiration || 0;
|
|
558
|
+
const content = {
|
|
559
|
+
ephemeralMessage: {
|
|
560
|
+
message: {
|
|
561
|
+
protocolMessage: {
|
|
562
|
+
type: WAProto.Message.ProtocolMessage.Type.EPHEMERAL_SETTING,
|
|
563
|
+
ephemeralExpiration
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
};
|
|
568
|
+
return WAProto.Message.fromObject(content);
|
|
569
|
+
};
|
|
565
570
|
/**
|
|
566
571
|
* Generate forwarded message content like WA does
|
|
567
572
|
* @param message the message to forward
|
|
568
573
|
* @param options.forceForward will show the message as forwarded even if it is from you
|
|
569
574
|
*/
|
|
570
575
|
export const generateForwardMessageContent = (message, forceForward) => {
|
|
571
|
-
let content = message.message
|
|
576
|
+
let content = message.message;
|
|
572
577
|
if (!content) {
|
|
573
578
|
throw new Boom('no content in message', { statusCode: 400 });
|
|
574
579
|
}
|
|
@@ -584,24 +589,12 @@ export const generateForwardMessageContent = (message, forceForward) => {
|
|
|
584
589
|
key = 'extendedTextMessage';
|
|
585
590
|
}
|
|
586
591
|
const key_ = content?.[key];
|
|
587
|
-
const contextInfo = {};
|
|
588
592
|
if (score > 0) {
|
|
589
|
-
contextInfo
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
// so the server knows where to find the original media
|
|
594
|
-
const remoteJid = message.key?.remoteJid;
|
|
595
|
-
if (remoteJid && isJidNewsletter(remoteJid)) {
|
|
596
|
-
contextInfo.forwardedNewsletterMessageInfo = {
|
|
597
|
-
newsletterJid: remoteJid,
|
|
598
|
-
serverMessageId: message.key?.server_id ? parseInt(message.key.server_id) : null,
|
|
599
|
-
newsletterName: null
|
|
600
|
-
};
|
|
601
|
-
// strip messageContextInfo (contains messageSecret etc.) as WA Web does
|
|
602
|
-
delete content.messageContextInfo;
|
|
593
|
+
key_.contextInfo = { forwardingScore: score, isForwarded: true };
|
|
594
|
+
}
|
|
595
|
+
else {
|
|
596
|
+
key_.contextInfo = {};
|
|
603
597
|
}
|
|
604
|
-
key_.contextInfo = contextInfo;
|
|
605
598
|
return content;
|
|
606
599
|
};
|
|
607
600
|
export const hasNonNullishProperty = (message, key) => {
|
|
@@ -702,25 +695,25 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
702
695
|
throw new Boom('require atleast 1 contact', { statusCode: 400 });
|
|
703
696
|
}
|
|
704
697
|
if (contactLen === 1) {
|
|
705
|
-
m.contactMessage = message.contacts.contacts[0];
|
|
698
|
+
m.contactMessage = WAProto.Message.ContactMessage.create(message.contacts.contacts[0]);
|
|
706
699
|
}
|
|
707
700
|
else {
|
|
708
|
-
m.contactsArrayMessage = message.contacts;
|
|
701
|
+
m.contactsArrayMessage = WAProto.Message.ContactsArrayMessage.create(message.contacts);
|
|
709
702
|
}
|
|
710
703
|
}
|
|
711
704
|
else if (hasNonNullishProperty(message, 'location')) {
|
|
712
|
-
m.locationMessage = message.location;
|
|
705
|
+
m.locationMessage = WAProto.Message.LocationMessage.create(message.location);
|
|
713
706
|
}
|
|
714
707
|
else if (hasNonNullishProperty(message, 'react')) {
|
|
715
708
|
if (!message.react.senderTimestampMs) {
|
|
716
709
|
message.react.senderTimestampMs = Date.now();
|
|
717
710
|
}
|
|
718
|
-
m.reactionMessage = message.react;
|
|
711
|
+
m.reactionMessage = WAProto.Message.ReactionMessage.create(message.react);
|
|
719
712
|
}
|
|
720
713
|
else if (hasNonNullishProperty(message, 'delete')) {
|
|
721
714
|
m.protocolMessage = {
|
|
722
715
|
key: message.delete,
|
|
723
|
-
type:
|
|
716
|
+
type: WAProto.Message.ProtocolMessage.Type.REVOKE
|
|
724
717
|
};
|
|
725
718
|
}
|
|
726
719
|
else if (hasNonNullishProperty(message, 'forward')) {
|
|
@@ -922,25 +915,6 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
922
915
|
vote: message.pollUpdate.vote
|
|
923
916
|
};
|
|
924
917
|
}
|
|
925
|
-
else if (hasNonNullishProperty(message, 'sharePhoneNumber')) {
|
|
926
|
-
m.protocolMessage = {
|
|
927
|
-
type: ProtocolType.SHARE_PHONE_NUMBER
|
|
928
|
-
};
|
|
929
|
-
}
|
|
930
|
-
else if (hasNonNullishProperty(message, 'requestPhoneNumber')) {
|
|
931
|
-
m.requestPhoneNumberMessage = {};
|
|
932
|
-
}
|
|
933
|
-
else if (hasNonNullishProperty(message, 'limitSharing')) {
|
|
934
|
-
m.protocolMessage = {
|
|
935
|
-
type: ProtocolType.LIMIT_SHARING,
|
|
936
|
-
limitSharing: {
|
|
937
|
-
sharingLimited: message.limitSharing === true,
|
|
938
|
-
trigger: 1,
|
|
939
|
-
limitSharingSettingTimestamp: Date.now(),
|
|
940
|
-
initiatedByMe: true
|
|
941
|
-
}
|
|
942
|
-
};
|
|
943
|
-
}
|
|
944
918
|
// Lia@Changes 01-02-26 --- Add payment invite message
|
|
945
919
|
else if (hasNonNullishProperty(message, 'paymentInviteServiceType')) {
|
|
946
920
|
m.paymentInviteMessage = {
|
|
@@ -992,6 +966,25 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
992
966
|
expectedVideoCount: videoCount
|
|
993
967
|
};
|
|
994
968
|
}
|
|
969
|
+
else if (hasNonNullishProperty(message, 'sharePhoneNumber')) {
|
|
970
|
+
m.protocolMessage = {
|
|
971
|
+
type: proto.Message.ProtocolMessage.Type.SHARE_PHONE_NUMBER
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
else if (hasNonNullishProperty(message, 'requestPhoneNumber')) {
|
|
975
|
+
m.requestPhoneNumberMessage = {};
|
|
976
|
+
}
|
|
977
|
+
else if (hasNonNullishProperty(message, 'limitSharing')) {
|
|
978
|
+
m.protocolMessage = {
|
|
979
|
+
type: proto.Message.ProtocolMessage.Type.LIMIT_SHARING,
|
|
980
|
+
limitSharing: {
|
|
981
|
+
sharingLimited: message.limitSharing === true,
|
|
982
|
+
trigger: 1,
|
|
983
|
+
limitSharingSettingTimestamp: Date.now(),
|
|
984
|
+
initiatedByMe: true
|
|
985
|
+
}
|
|
986
|
+
};
|
|
987
|
+
}
|
|
995
988
|
else {
|
|
996
989
|
m = await prepareWAMessageMedia(message, options);
|
|
997
990
|
}
|
|
@@ -1315,18 +1308,21 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1315
1308
|
(hasOptionalProperty(message, 'mentionAll') && message.mentionAll)) {
|
|
1316
1309
|
const messageType = Object.keys(m)[0];
|
|
1317
1310
|
const key = m[messageType];
|
|
1318
|
-
if ('contextInfo' in key
|
|
1319
|
-
key.contextInfo
|
|
1311
|
+
if (key && 'contextInfo' in key) {
|
|
1312
|
+
key.contextInfo = key.contextInfo || {};
|
|
1313
|
+
if (message.mentions?.length) {
|
|
1314
|
+
key.contextInfo.mentionedJid = message.mentions;
|
|
1315
|
+
}
|
|
1316
|
+
if (message.mentionAll) {
|
|
1317
|
+
key.contextInfo.nonJidMentions = 1;
|
|
1318
|
+
}
|
|
1320
1319
|
}
|
|
1321
1320
|
else if (key) {
|
|
1322
1321
|
key.contextInfo = {
|
|
1323
|
-
mentionedJid: message.mentions
|
|
1322
|
+
mentionedJid: message.mentions,
|
|
1323
|
+
nonJidMentions: message.mentionAll ? 1 : 0
|
|
1324
1324
|
};
|
|
1325
1325
|
}
|
|
1326
|
-
if (message.mentionAll) {
|
|
1327
|
-
key.contextInfo.mentionedJid = [];
|
|
1328
|
-
key.contextInfo.nonJidMentions = 1;
|
|
1329
|
-
}
|
|
1330
1326
|
}
|
|
1331
1327
|
if (hasOptionalProperty(message, 'contextInfo') && !!message.contextInfo) {
|
|
1332
1328
|
const messageType = Object.keys(m)[0];
|
|
@@ -1390,7 +1386,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1390
1386
|
key: message.edit,
|
|
1391
1387
|
editedMessage: m,
|
|
1392
1388
|
timestampMs: Date.now(),
|
|
1393
|
-
type:
|
|
1389
|
+
type: WAProto.Message.ProtocolMessage.Type.MESSAGE_EDIT
|
|
1394
1390
|
}
|
|
1395
1391
|
};
|
|
1396
1392
|
}
|
|
@@ -1400,7 +1396,7 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
1400
1396
|
m.messageContextInfo.messageSecret = randomBytes(32);
|
|
1401
1397
|
}
|
|
1402
1398
|
}
|
|
1403
|
-
return
|
|
1399
|
+
return WAProto.Message.create(m);
|
|
1404
1400
|
};
|
|
1405
1401
|
export const generateWAMessageFromContent = (jid, message, options) => {
|
|
1406
1402
|
// set timestamp to now
|
|
@@ -1408,8 +1404,8 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
1408
1404
|
if (!options.timestamp) {
|
|
1409
1405
|
options.timestamp = Date.now();
|
|
1410
1406
|
}
|
|
1411
|
-
const messageContextInfo = message.messageContextInfo;
|
|
1412
1407
|
const innerMessage = normalizeMessageContent(message);
|
|
1408
|
+
const messageContextInfo = message.messageContextInfo;
|
|
1413
1409
|
const key = getContentType(innerMessage);
|
|
1414
1410
|
const timestamp = unixTimestampSeconds(options.timestamp);
|
|
1415
1411
|
const isNewsletter = isJidNewsletter(jid);
|
|
@@ -1464,7 +1460,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
1464
1460
|
};
|
|
1465
1461
|
messageContextInfo.deviceListMetadataVersion = 2;
|
|
1466
1462
|
}
|
|
1467
|
-
message =
|
|
1463
|
+
message = WAProto.Message.create(message);
|
|
1468
1464
|
const messageJSON = {
|
|
1469
1465
|
key: {
|
|
1470
1466
|
remoteJid: jid,
|
|
@@ -1479,14 +1475,11 @@ export const generateWAMessageFromContent = (jid, message, options) => {
|
|
|
1479
1475
|
};
|
|
1480
1476
|
return WAProto.WebMessageInfo.fromObject(messageJSON);
|
|
1481
1477
|
};
|
|
1482
|
-
export const generateWAMessage = async (jid, content, options
|
|
1478
|
+
export const generateWAMessage = async (jid, content, options) => {
|
|
1483
1479
|
// ensure msg ID is with every log
|
|
1484
1480
|
options.logger = options?.logger?.child({ msgId: options.messageId });
|
|
1485
1481
|
// Pass jid in the options to generateWAMessageContent
|
|
1486
|
-
|
|
1487
|
-
options.jid = jid;
|
|
1488
|
-
}
|
|
1489
|
-
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, options), options);
|
|
1482
|
+
return generateWAMessageFromContent(jid, await generateWAMessageContent(content, { ...options, jid }), options);
|
|
1490
1483
|
};
|
|
1491
1484
|
/** Get the key to access the true type of content */
|
|
1492
1485
|
export const getContentType = (content) => {
|
|
@@ -1515,7 +1508,6 @@ export const normalizeMessageContent = (content) => {
|
|
|
1515
1508
|
content = inner.message;
|
|
1516
1509
|
}
|
|
1517
1510
|
return content;
|
|
1518
|
-
// Lia@Changes 03-02-26 --- Add all futureProofMessage into getFutureProofMessage()
|
|
1519
1511
|
function getFutureProofMessage(message) {
|
|
1520
1512
|
return (message?.associatedChildMessage ||
|
|
1521
1513
|
message?.botForwardedMessage ||
|
|
@@ -1531,10 +1523,13 @@ export const normalizeMessageContent = (content) => {
|
|
|
1531
1523
|
message?.groupStatusMessageV2 ||
|
|
1532
1524
|
message?.limitSharingMessage ||
|
|
1533
1525
|
message?.lottieStickerMessage ||
|
|
1526
|
+
message?.newsletterAdminProfileMessage ||
|
|
1527
|
+
message?.newsletterAdminProfileMessageV2 ||
|
|
1534
1528
|
message?.pollCreationMessageV4 ||
|
|
1535
1529
|
message?.pollCreationOptionImageMessage ||
|
|
1536
1530
|
message?.questionMessage ||
|
|
1537
1531
|
message?.questionReplyMessage ||
|
|
1532
|
+
message?.spoilerMessage ||
|
|
1538
1533
|
message?.statusAddYours ||
|
|
1539
1534
|
message?.statusMentionMessage ||
|
|
1540
1535
|
message?.viewOnceMessage ||
|