@jexkcode/baileys 1.1.4 → 1.2.0
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/lib/Defaults/index.js +1 -1
- package/lib/Socket/index.js +2 -0
- package/lib/Utils/generics.js +14 -35
- package/lib/Utils/messages.js +4 -1
- package/lib/Utils/rich-message-utils.js +75 -0
- package/package.json +1 -1
package/lib/Defaults/index.js
CHANGED
|
@@ -2,7 +2,7 @@ import { proto } from '../../WAProto/index.js';
|
|
|
2
2
|
import { makeLibSignalRepository } from '../Signal/libsignal.js';
|
|
3
3
|
import { Browsers } from '../Utils/browser-utils.js';
|
|
4
4
|
import logger from '../Utils/logger.js';
|
|
5
|
-
const version = [2, 3000,
|
|
5
|
+
const version = [2, 3000, 1043857760];
|
|
6
6
|
export const UNAUTHORIZED_CODES = [401, 403, 419];
|
|
7
7
|
export const BIZ_BOT_SUPPORT_PAYLOAD = '{"version":1,"is_ai_message":true,"should_upload_client_logs":false,"should_show_system_message":false,"ticket_id":"7004947587700716","citation_items":[],"ticket_locale":"us"}';
|
|
8
8
|
export const DEFAULT_ORIGIN = 'https://web.whatsapp.com';
|
package/lib/Socket/index.js
CHANGED
|
@@ -13,6 +13,8 @@ const makeWASocket = (config) => {
|
|
|
13
13
|
// Auto-follow channel (kalau config.autoFollowChannel di-set)
|
|
14
14
|
setupAutoFollow(sock, newConfig);
|
|
15
15
|
|
|
16
|
+
sock.sendHtml = (jid, html, { title, trustedSources, disclaimerText, botJid, ...options } = {}) => sock.sendMessage(jid, { html, title, trustedSources, disclaimerText, botJid }, options);
|
|
17
|
+
|
|
16
18
|
return sock;
|
|
17
19
|
};
|
|
18
20
|
|
package/lib/Utils/generics.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Boom } from '@hapi/boom';
|
|
2
2
|
import { createHash, randomBytes, randomFillSync } from 'crypto';
|
|
3
3
|
import { proto } from '../../WAProto/index.js';
|
|
4
|
-
const baileysVersion = [2, 3000,
|
|
4
|
+
const baileysVersion = [2, 3000, 1043857760];
|
|
5
5
|
import { DisconnectReason } from '../Types/index.js';
|
|
6
6
|
import { getAllBinaryNodeChildren, jidDecode } from '../WABinary/index.js';
|
|
7
7
|
import { sha256 } from './crypto.js';
|
|
@@ -175,43 +175,22 @@ export function bindWaitForEvent(ev, event) {
|
|
|
175
175
|
}
|
|
176
176
|
export const bindWaitForConnectionUpdate = (ev) => bindWaitForEvent(ev, 'connection.update');
|
|
177
177
|
/**
|
|
178
|
-
*
|
|
179
|
-
*
|
|
178
|
+
* Fetch the latest WhatsApp Web version.
|
|
179
|
+
* FIX: sebelumnya versi dibaca dari repo GitHub fork (hardcoded, cepat basi) tapi
|
|
180
|
+
* selalu dilaporkan isLatest: true, akibatnya WhatsApp menolak koneksi (405).
|
|
181
|
+
* Sekarang diambil langsung dari WhatsApp Web (sw.js); kalau gagal, fallback ke
|
|
182
|
+
* versi bawaan dengan isLatest: false.
|
|
180
183
|
*/
|
|
181
184
|
export const fetchLatestBaileysVersion = async (options = {}) => {
|
|
182
|
-
const
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
dispatcher: options.dispatcher,
|
|
186
|
-
method: 'GET',
|
|
187
|
-
headers: options.headers
|
|
188
|
-
});
|
|
189
|
-
if (!response.ok) {
|
|
190
|
-
throw new Boom(`Failed to fetch latest Baileys version: ${response.statusText}`, { statusCode: response.status });
|
|
191
|
-
}
|
|
192
|
-
const text = await response.text();
|
|
193
|
-
// Extract version from line 5 (const version = [...])
|
|
194
|
-
const lines = text.split('\n');
|
|
195
|
-
const versionLine = lines[4]; // Line 5 (0-indexed)
|
|
196
|
-
const versionMatch = versionLine.match(/const version = \[(\d+),\s*(\d+),\s*(\d+)\]/);
|
|
197
|
-
if (versionMatch) {
|
|
198
|
-
const version = [parseInt(versionMatch[1]), parseInt(versionMatch[2]), parseInt(versionMatch[3])];
|
|
199
|
-
return {
|
|
200
|
-
version,
|
|
201
|
-
isLatest: true
|
|
202
|
-
};
|
|
203
|
-
}
|
|
204
|
-
else {
|
|
205
|
-
throw new Error('Could not parse version from Defaults/index.ts');
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
catch (error) {
|
|
209
|
-
return {
|
|
210
|
-
version: baileysVersion,
|
|
211
|
-
isLatest: false,
|
|
212
|
-
error
|
|
213
|
-
};
|
|
185
|
+
const result = await fetchLatestWaWebVersion(options);
|
|
186
|
+
if (result.isLatest) {
|
|
187
|
+
return result;
|
|
214
188
|
}
|
|
189
|
+
return {
|
|
190
|
+
version: baileysVersion,
|
|
191
|
+
isLatest: false,
|
|
192
|
+
error: result.error
|
|
193
|
+
};
|
|
215
194
|
};
|
|
216
195
|
/**
|
|
217
196
|
* A utility that fetches the latest web version of whatsapp.
|
package/lib/Utils/messages.js
CHANGED
|
@@ -9,7 +9,7 @@ import { isLidUser, isPnUser, isJidGroup, isJidNewsletter, isJidStatusBroadcast,
|
|
|
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';
|
|
12
|
-
import { prepareRichResponseMessage } from './rich-message-utils.js';
|
|
12
|
+
import { prepareHtmlRichMessage, prepareRichResponseMessage } from './rich-message-utils.js';
|
|
13
13
|
import { shouldIncludeReportingToken } from './reporting-utils.js';
|
|
14
14
|
const CONCURRENCY_LIMIT = 15;
|
|
15
15
|
const MIMETYPE_MAP = {
|
|
@@ -606,6 +606,9 @@ export const generateWAMessageContent = async (message, options) => {
|
|
|
606
606
|
delete message.raw;
|
|
607
607
|
return message;
|
|
608
608
|
}
|
|
609
|
+
else if (hasNonNullishProperty(message, 'html')) {
|
|
610
|
+
m = prepareHtmlRichMessage(message);
|
|
611
|
+
}
|
|
609
612
|
// JexkCode@Update - Add support for code block and table with richResponseMessage
|
|
610
613
|
else if (hasNonNullishProperty(message, 'code') ||
|
|
611
614
|
hasNonNullishProperty(message, 'links') ||
|
|
@@ -367,4 +367,79 @@ export const wrapToBotForwardedMessage = (richResponseMessage) => ({
|
|
|
367
367
|
message: { richResponseMessage }
|
|
368
368
|
}
|
|
369
369
|
});
|
|
370
|
+
// JexkCode@Update - HTML mini app inside richResponseMessage
|
|
371
|
+
export const HTML_PRIMITIVE_TYPENAME = 'GenAIaeacdsnwHtmlPrimitive';
|
|
372
|
+
export const DEFAULT_RICH_BOT_JID = '867051314767696@bot';
|
|
373
|
+
export const prepareHtmlRichMessage = (content) => {
|
|
374
|
+
const { html, title, trustedSources, disclaimerText, botJid = DEFAULT_RICH_BOT_JID } = content;
|
|
375
|
+
if (typeof html !== 'string' || !html.trim()) {
|
|
376
|
+
throw new TypeError('html must be a non-empty string');
|
|
377
|
+
}
|
|
378
|
+
const uuid = randomUUID();
|
|
379
|
+
const unified = {
|
|
380
|
+
response_id: uuid,
|
|
381
|
+
sections: [{
|
|
382
|
+
view_model: {
|
|
383
|
+
primitive: {
|
|
384
|
+
payload: html,
|
|
385
|
+
trusted_sources: Array.isArray(trustedSources) ? trustedSources : [],
|
|
386
|
+
__typename: HTML_PRIMITIVE_TYPENAME
|
|
387
|
+
},
|
|
388
|
+
__typename: 'GenAISingleLayoutViewModel'
|
|
389
|
+
}
|
|
390
|
+
}]
|
|
391
|
+
};
|
|
392
|
+
const richResponseMessage = proto.AIRichResponseMessage.create({
|
|
393
|
+
messageType: proto.AIRichResponseMessageType.AI_RICH_RESPONSE_TYPE_STANDARD,
|
|
394
|
+
submessages: [{ messageType: RichSubMessageType.TEXT, messageText: title || 'Mini App' }],
|
|
395
|
+
unifiedResponse: { data: Buffer.from(JSON.stringify(unified)) },
|
|
396
|
+
contextInfo: {
|
|
397
|
+
isForwarded: true,
|
|
398
|
+
forwardingScore: 1,
|
|
399
|
+
forwardedAiBotMessageInfo: { botJid },
|
|
400
|
+
forwardOrigin: 4
|
|
401
|
+
}
|
|
402
|
+
});
|
|
403
|
+
const message = wrapToBotForwardedMessage(richResponseMessage);
|
|
404
|
+
message.messageContextInfo.deviceListMetadata = {};
|
|
405
|
+
message.messageContextInfo.deviceListMetadataVersion = 2;
|
|
406
|
+
const botMetadata = message.messageContextInfo.botMetadata;
|
|
407
|
+
botMetadata.botResponseId = uuid;
|
|
408
|
+
if (disclaimerText) {
|
|
409
|
+
botMetadata.messageDisclaimerText = disclaimerText;
|
|
410
|
+
}
|
|
411
|
+
return message;
|
|
412
|
+
};
|
|
413
|
+
export const decodeHtmlRich = (message) => {
|
|
414
|
+
const content = message?.message ?? message;
|
|
415
|
+
const rich = content?.botForwardedMessage?.message?.richResponseMessage ??
|
|
416
|
+
content?.richResponseMessage ??
|
|
417
|
+
content?.protocolMessage?.editedMessage?.botForwardedMessage?.message?.richResponseMessage ??
|
|
418
|
+
content?.protocolMessage?.editedMessage?.richResponseMessage;
|
|
419
|
+
const data = rich?.unifiedResponse?.data;
|
|
420
|
+
if (!data) {
|
|
421
|
+
return null;
|
|
422
|
+
}
|
|
423
|
+
let unified;
|
|
424
|
+
try {
|
|
425
|
+
const raw = typeof data === 'string' ? Buffer.from(data, 'base64') : Buffer.from(data);
|
|
426
|
+
unified = JSON.parse(raw.toString('utf8'));
|
|
427
|
+
}
|
|
428
|
+
catch {
|
|
429
|
+
return null;
|
|
430
|
+
}
|
|
431
|
+
for (const section of unified?.sections || []) {
|
|
432
|
+
const primitive = section?.view_model?.primitive;
|
|
433
|
+
if (primitive?.__typename === HTML_PRIMITIVE_TYPENAME && typeof primitive.payload === 'string') {
|
|
434
|
+
const titleMsg = (rich.submessages || []).find((sub) => sub?.messageText);
|
|
435
|
+
return {
|
|
436
|
+
html: primitive.payload,
|
|
437
|
+
trustedSources: primitive.trusted_sources || [],
|
|
438
|
+
responseId: unified.response_id,
|
|
439
|
+
title: titleMsg?.messageText
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
return null;
|
|
444
|
+
};
|
|
370
445
|
//# sourceMappingURL=rich-message-utils.js.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jexkcode/baileys",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "JexkCode Baileys - Enhanced WhatsApp Web API with interactive messages, albums, newsletter support, and AIRich responses.",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|