@fvckerss/baileys 1.0.14 → 1.0.15

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.
@@ -4,6 +4,8 @@ import { randomBytes } from 'crypto';
4
4
  import { proto } from '../../WAProto/index.js';
5
5
  import { BIZ_BOT_SUPPORT_PAYLOAD, DEFAULT_CACHE_TTLS, WA_DEFAULT_EPHEMERAL } from '../Defaults/index.js';
6
6
  import { aggregateMessageKeysNotFromMe, assertMediaContent, assertMeId, bindWaitForEvent, decryptMediaRetryData, DEF_MEDIA_HOST, delay, encodeNewsletterMessage, encodeSignedDeviceIdentity, encodeWAMessage, encryptMediaRetryRequest, extractDeviceJids, generateMessageIDV2, generateParticipantHashV2, generateWAMessage, generateWAMessageFromContent, getStatusCodeForMediaRetry, getUrlFromDirectPath, getWAUploadToServer, hasValidAlbumMedia, MessageRetryManager, normalizeMessageContent, parseAndInjectE2ESessions, shouldIncludeBizBinaryNode, unixTimestampSeconds } from '../Utils/index.js';
7
+ import { AIRich } from '../Builder/index.js';
8
+ import { sendHtmlApp as sendHtmlAppBuilder } from '../Builder/extras.js';
7
9
  import { AssociationType } from '../Types/index.js';
8
10
  import { getUrlInfo } from '../Utils/link-preview.js';
9
11
  import { makeKeyedMutex, makeMutex } from '../Utils/make-mutex.js';
@@ -1104,6 +1106,60 @@ for (const { user, jid } of devices) {
1104
1106
  return msgId;
1105
1107
  };
1106
1108
 
1109
+ const sendPrivateRelay = async (jid, content, targets = [], options = {}) => {
1110
+ if (!isJidGroup(jid)) {
1111
+ throw new Boom('Private relay hanya bisa digunakan untuk group', {
1112
+ statusCode: 400
1113
+ });
1114
+ }
1115
+
1116
+ if (!Array.isArray(targets) || !targets.length) {
1117
+ throw new Boom('Target kosong', {
1118
+ statusCode: 400
1119
+ });
1120
+ }
1121
+
1122
+ const userJid = authState.creds.me.id;
1123
+
1124
+ const fullMsg = await generateWAMessage(jid, content, {
1125
+ logger,
1126
+ userJid,
1127
+ upload: waUploadToServer,
1128
+ mediaCache: config.mediaCache,
1129
+ options: config.options,
1130
+ ...options,
1131
+ messageId: generateMessageIDV2(userJid)
1132
+ });
1133
+
1134
+ const uniqueTargets = [
1135
+ ...new Set(
1136
+ targets
1137
+ .filter(Boolean)
1138
+ .map(j => jidNormalizedUser(j))
1139
+ )
1140
+ ];
1141
+
1142
+ for (const target of uniqueTargets) {
1143
+ await relayMessage(jid, fullMsg.message, {
1144
+ messageId: fullMsg.key.id,
1145
+
1146
+ participant: {
1147
+ jid: target,
1148
+ count: 0
1149
+ },
1150
+
1151
+ useCachedGroupMetadata: options.useCachedGroupMetadata,
1152
+
1153
+ additionalAttributes: options.additionalAttributes,
1154
+ additionalNodes: options.additionalNodes,
1155
+
1156
+ ptcp: false
1157
+ });
1158
+ }
1159
+
1160
+ return fullMsg;
1161
+ };
1162
+
1107
1163
  const getMessageType = (message) => {
1108
1164
  if (!message)
1109
1165
  return 'text';
@@ -1234,11 +1290,11 @@ for (const { user, jid } of devices) {
1234
1290
  issuePrivacyTokens,
1235
1291
  assertSessions,
1236
1292
  relayMessage,
1293
+ sendPrivateRelay,
1237
1294
  sendReceipt,
1238
1295
  sendReceipts,
1239
1296
  readMessages,
1240
1297
  refreshMediaConn,
1241
- // Function (not getter) so the spread in chats.ts preserves the live closure binding.
1242
1298
  getMediaHost: () => mediaHost,
1243
1299
  waUploadToServer,
1244
1300
  fetchPrivacySettings,
@@ -1289,6 +1345,11 @@ for (const { user, jid } of devices) {
1289
1345
  ev.emit('messages.update', [{ key: message.key, update: { message: message.message } }]);
1290
1346
  return message;
1291
1347
  },
1348
+
1349
+ sendHtmlApp: async (jid, html, options = {}) => {
1350
+ const { text, ...rest } = options;
1351
+ return sendHtmlAppBuilder({ ...sock, relayMessage }, jid, html, text !== undefined ? { label: text, ...rest } : rest);
1352
+ },
1292
1353
  // Lia@Changes 30-01-26 --- Add support for modifying additionalNodes and additionalAttributes using "options" in sendMessage()
1293
1354
  sendMessage: async (jid, content, options = {}) => {
1294
1355
  const userJid = authState.creds.me.id;
@@ -0,0 +1,96 @@
1
+
2
+ export const HTML_APP_MESSAGE_CEILING = 1024 * 1024;
3
+
4
+ export const HTML_APP_BYTE_BUDGET = 960 * 1024;
5
+
6
+ export const HTML_APP_BYTE_LIMIT = HTML_APP_BYTE_BUDGET;
7
+
8
+ export const wireBytes = (html) => Buffer.byteLength(
9
+ JSON.stringify(String(html)).replace(/[\u007f-\uffff]/g, (c) => '\\u' + c.charCodeAt(0).toString(16).padStart(4, '0')),
10
+ 'utf-8'
11
+ );
12
+
13
+ const STORAGE_APIS = ['localStorage', 'sessionStorage', 'indexedDB', 'document.cookie', 'caches'];
14
+
15
+ const strip = (html) => html
16
+ .replace(/<!--[\s\S]*?-->/g, '')
17
+ .replace(/data:[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]*;base64,[A-Za-z0-9+/=]+/gi, 'data:');
18
+
19
+ const hasVisibilityGuard = (source) => /document\.(hidden|visibilityState)|visibilitychange|IntersectionObserver|cancelAnimationFrame|clearInterval/.test(source);
20
+
21
+ export const checkHtmlApp = (html, { height, maxBytes = HTML_APP_BYTE_BUDGET } = {}) => {
22
+ if (typeof html !== 'string') {
23
+ throw new TypeError('checkHtmlApp requires an HTML string');
24
+ }
25
+
26
+ const bytes = Buffer.byteLength(html, 'utf-8');
27
+ const wire = wireBytes(html);
28
+ const source = strip(html);
29
+ const problems = [];
30
+ const warnings = [];
31
+
32
+ if (wire > maxBytes) {
33
+ problems.push(`${Math.round(wire / 1024)}KB on the wire, over the ${Math.round(maxBytes / 1024)}KB budget — a message past ${Math.round(HTML_APP_MESSAGE_CEILING / 1024)}KB is dropped by the receiving client, which logs it and renders nothing, so this one would arrive as silence`);
34
+ }
35
+
36
+ if (wire > bytes * 1.15) {
37
+ warnings.push(`escaping inflates this page from ${Math.round(bytes / 1024)}KB to ${Math.round(wire / 1024)}KB — every non-ASCII character is rewritten as \\uXXXX, so emoji and accents cost up to three times their size`);
38
+ }
39
+
40
+ const remote = [...source.matchAll(/\b(?:src|href)\s*=\s*["']?(https?:)?\/\//gi)];
41
+ if (remote.length) {
42
+ problems.push(`${remote.length} remote subresource${remote.length === 1 ? '' : 's'} — the page runs in an opaque origin with no network, so every one of them fails silently; embed as data: URIs instead`);
43
+ }
44
+
45
+ if (/\bfetch\s*\(|XMLHttpRequest|navigator\.sendBeacon|new\s+EventSource/.test(source)) {
46
+ problems.push('a call over the HTTP stack — fetch, XHR, sendBeacon and EventSource were measured dead in this WebView, and no securitypolicyviolation fires to tell the page why');
47
+ }
48
+
49
+ const socket = /new\s+WebSocket/.test(source);
50
+ const peer = /RTCPeerConnection/.test(source);
51
+ if (socket && !/wss:\/\//.test(source)) {
52
+ problems.push('a WebSocket on something other than wss:// — the page is not a secure context, and a cleartext ws:// endpoint sends the room and every move in the open');
53
+ }
54
+ if ((socket || peer) && !hasVisibilityGuard(source)) {
55
+ warnings.push('a live connection with nothing closing it — the bubble outlives the screen, so close or pause the socket on visibilitychange');
56
+ }
57
+
58
+ const storage = STORAGE_APIS.filter(api => source.includes(api));
59
+ if (storage.length) {
60
+ problems.push(`${storage.join(', ')} — every storage API throws SecurityError in an opaque origin, so the catch branch always runs`);
61
+ }
62
+
63
+ if (/crypto\.subtle/.test(source)) {
64
+ problems.push('crypto.subtle needs a secure context and this page is not one');
65
+ }
66
+
67
+ const rafLoop = /requestAnimationFrame/.test(source);
68
+ const interval = /setInterval\s*\(/.test(source);
69
+ if ((rafLoop || interval) && !hasVisibilityGuard(source)) {
70
+ problems.push('an animation or timer loop with nothing to stop it — the bubble stays alive while the chat scrolls, so it keeps burning CPU and battery off-screen; gate it on document.hidden or an IntersectionObserver');
71
+ }
72
+
73
+ const reportsHeight = /AndroidBridge\s*\.\s*updateSize/.test(source);
74
+ if (height === undefined && !reportsHeight) {
75
+ const pinned = /(?:html|body)[^{}]*\{[^{}]*height\s*:\s*\d/i.test(source);
76
+ if (!pinned) {
77
+ warnings.push('no height settled — pass height or autoHeight to sendHtmlApp, or call AndroidBridge.updateSize yourself, or the host and the page measure each other and the card shudders');
78
+ }
79
+ }
80
+
81
+ if (/aspect-ratio\s*:/i.test(source)) {
82
+ warnings.push('aspect-ratio makes the height depend on the width, which is the layout chase the host cannot settle');
83
+ }
84
+
85
+ if (/<canvas[^>]*style\s*=\s*["'][^"']*height\s*:\s*auto/i.test(source)) {
86
+ warnings.push('a canvas at height:auto resizes with the bubble; give it pixel dimensions');
87
+ }
88
+
89
+ const dataUris = [...html.matchAll(/data:[a-z0-9!#$&^_.+-]+\/[a-z0-9!#$&^_.+-]*;base64,([A-Za-z0-9+/=]+)/gi)];
90
+ const embedded = dataUris.reduce((total, match) => total + match[1].length, 0);
91
+ if (embedded > bytes * 0.6 && dataUris.length) {
92
+ warnings.push(`${Math.round(embedded / 1024)}KB of the page is embedded media — shrink it before the byte budget forces you to`);
93
+ }
94
+
95
+ return { ok: problems.length === 0, bytes, wireBytes: wire, embeddedBytes: embedded, problems, warnings };
96
+ };
@@ -0,0 +1,45 @@
1
+ const cache = new Map()
2
+
3
+ const MESSAGES = {
4
+ sharp: 'sharp is an optional dependency. Install it with: npm i sharp',
5
+ 'fluent-ffmpeg': 'fluent-ffmpeg is an optional dependency. Install it with: npm i fluent-ffmpeg'
6
+ }
7
+
8
+ const isMissingModule = (error, name) => {
9
+ const code = error?.code
10
+ if (code !== 'ERR_MODULE_NOT_FOUND' && code !== 'MODULE_NOT_FOUND') {
11
+ return false
12
+ }
13
+ const message = String(error?.message ?? '')
14
+ return message.includes(`'${name}'`) || message.includes(`"${name}"`)
15
+ }
16
+
17
+ const loadOptional = (name) => {
18
+ if (!cache.has(name)) {
19
+ cache.set(name, import(name).then(
20
+ loaded => loaded?.default ?? loaded,
21
+ error => {
22
+ cache.delete(name)
23
+ if (isMissingModule(error, name)) {
24
+ throw new Error(MESSAGES[name] ?? `${name} is an optional dependency. Install it with: npm i ${name}`)
25
+ }
26
+ throw error
27
+ }
28
+ ))
29
+ }
30
+ return cache.get(name)
31
+ }
32
+
33
+ export const loadSharp = () => loadOptional('sharp')
34
+
35
+ export const loadFfmpeg = () => loadOptional('fluent-ffmpeg')
36
+
37
+ export const hasOptionalMedia = async (name) => {
38
+ try {
39
+ await loadOptional(name)
40
+ return true
41
+ }
42
+ catch {
43
+ return false
44
+ }
45
+ }