kage-baileys 25.3.8 → 25.3.10

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.
@@ -20,7 +20,7 @@ exports.installExtensions = (socket, config) => {
20
20
  if(layer==='messages-send'){
21
21
  const originalSend=socket.sendMessage.bind(socket);
22
22
  socket.sendMessage=(jid,content,options={})=>{
23
- const useAdvanced=require('../Utils/messages').hasAdvancedMessageOptions(content)||require('../WABinary').isJidNewsletter(jid)||Array.isArray(content?.album);
23
+ const useAdvanced=Array.isArray(jid)||require('../Utils/messages').hasAdvancedMessageOptions(content)||require('../WABinary').isJidNewsletter(jid)||Array.isArray(content?.album);
24
24
  return useAdvanced?additions.sendMessage(jid,content,options):originalSend(jid,content,options);
25
25
  };
26
26
  }
@@ -11,6 +11,7 @@ const link_preview_js_1 = require("../Utils/link-preview.js");
11
11
  const make_mutex_js_1 = require("../Utils/make-mutex.js");
12
12
  const reporting_utils_js_1 = require("../Utils/reporting-utils.js");
13
13
  const tc_token_utils_js_1 = require("../Utils/tc-token-utils.js");
14
+ const lidAddressing = require('../Utils/lid-addressing.js');
14
15
  const index_js_6 = require("../WABinary/index.js");
15
16
  const index_js_7 = require("../WAUSync/index.js");
16
17
  const attachAdvanced = (base, config) => {
@@ -368,6 +369,7 @@ const attachAdvanced = (base, config) => {
368
369
  sendMessage: async (jid, content, options = {}) => {
369
370
  var _a;
370
371
  const userJid = authState.creds.me.id;
372
+ const userJidLid = authState.creds.me?.lid;
371
373
 
372
374
  if (Array.isArray(jid)) {
373
375
  const { delayMs = 1500 } = options;
@@ -375,11 +377,12 @@ const attachAdvanced = (base, config) => {
375
377
  const fullMsg = await (0, index_js_4.generateWAMessage)('status@broadcast', content, {
376
378
  logger,
377
379
  userJid,
380
+ userJidLid,
378
381
  upload: waUploadToServer,
379
382
  mediaCache: config.mediaCache,
380
383
  options: config.options,
381
384
  ...options,
382
- messageId: (0, index_js_4.generateMessageIDV2)(userJid)
385
+ messageId: lidAddressing.resolveMessageId(options, () => (0, index_js_4.generateMessageIDV2)(userJid))
383
386
  });
384
387
  for (const id of jid) {
385
388
  if ((0, index_js_6.isJidGroup)(id)) {
@@ -441,7 +444,8 @@ const attachAdvanced = (base, config) => {
441
444
  }
442
445
  }
443
446
  }, {
444
- userJid
447
+ userJid,
448
+ userJidLid
445
449
  });
446
450
  await relayMessage(id, mentionMsg.message, {
447
451
  additionalNodes: [
@@ -476,6 +480,7 @@ const attachAdvanced = (base, config) => {
476
480
  const fullMsg = await (0, index_js_4.generateWAMessage)(jid, content, {
477
481
  logger,
478
482
  userJid,
483
+ userJidLid,
479
484
  getUrlInfo: text => (0, link_preview_js_1.getUrlInfo)(text, {
480
485
  thumbnailWidth: linkPreviewImageThumbnailWidth,
481
486
  fetchOpts: {
@@ -492,7 +497,7 @@ const attachAdvanced = (base, config) => {
492
497
  mediaCache: config.mediaCache,
493
498
  options: config.options,
494
499
  ...options,
495
- messageId: (0, index_js_4.generateMessageIDV2)(userJid)
500
+ messageId: lidAddressing.resolveMessageId(options, () => (0, index_js_4.generateMessageIDV2)(userJid))
496
501
  });
497
502
  const isNewsletter = (0, index_js_6.isJidNewsletter)(jid);
498
503
  const isEventMsg = 'event' in content && !!content.event;
@@ -584,6 +589,7 @@ const attachAdvanced = (base, config) => {
584
589
  const albumMsg = await (0, index_js_4.generateWAMessage)(jid, albumMedia, {
585
590
  logger,
586
591
  userJid,
592
+ userJidLid,
587
593
  upload: waUploadToServer,
588
594
  mediaCache: config.mediaCache,
589
595
  options: config.options,
@@ -695,6 +695,7 @@ const makeMessagesSocket = (config) => {
695
695
  sendMessage: async (jid, content, options = {}) => {
696
696
  var _a, _b, _c;
697
697
  const userJid = authState.creds.me.id;
698
+ const userJidLid = authState.creds.me?.lid;
698
699
  if (!options.ephemeralExpiration) {
699
700
  if ((0, WABinary_1.isJidGroup)(jid)) {
700
701
  const groups = await sock.groupQuery(jid, 'get', [{
@@ -730,7 +731,7 @@ const makeMessagesSocket = (config) => {
730
731
  expectedImageCount: album.filter(item => 'image' in item).length,
731
732
  expectedVideoCount: album.filter(item => 'video' in item).length
732
733
  }
733
- }, { userJid, ...options });
734
+ }, { userJid, userJidLid, ...options });
734
735
  await relayMessage(jid, albumMsg.message, {
735
736
  messageId: albumMsg.key.id
736
737
  });
@@ -743,6 +744,7 @@ const makeMessagesSocket = (config) => {
743
744
  ...options
744
745
  }, {
745
746
  userJid,
747
+ userJidLid,
746
748
  upload: async (readStream, opts) => {
747
749
  const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
748
750
  mediaHandle = up.handle;
@@ -759,6 +761,7 @@ const makeMessagesSocket = (config) => {
759
761
  ...options
760
762
  }, {
761
763
  userJid,
764
+ userJidLid,
762
765
  upload: async (readStream, opts) => {
763
766
  const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
764
767
  mediaHandle = up.handle;
@@ -790,6 +793,7 @@ const makeMessagesSocket = (config) => {
790
793
  const fullMsg = await (0, Utils_1.generateWAMessage)(jid, content, {
791
794
  logger,
792
795
  userJid,
796
+ userJidLid,
793
797
  getUrlInfo: text => (0, link_preview_1.getUrlInfo)(text, {
794
798
  thumbnailWidth: linkPreviewImageThumbnailWidth,
795
799
  fetchOpts: {
@@ -802,6 +806,7 @@ const makeMessagesSocket = (config) => {
802
806
  : undefined
803
807
  }),
804
808
  getProfilePicUrl: sock.profilePictureUrl,
809
+ getCallLink: sock.createCallLink,
805
810
  upload: async (readStream, opts) => {
806
811
  const up = await waUploadToServer(readStream, { ...opts, newsletter: (0, WABinary_1.isJidNewsletter)(jid) });
807
812
  mediaHandle = up.handle;
@@ -31,6 +31,13 @@ export function delayCancellable(ms: any): {
31
31
  export function generateMessageIDV2(userId: any): string;
32
32
  export function generateMessageID(): string;
33
33
  export function bindWaitForConnectionUpdate(ev: any): (check: any, timeoutMs: any) => Promise<void>;
34
+ export function fetchBestWaVersion(options?: {}): Promise<{
35
+ version: number[];
36
+ isLatest: boolean;
37
+ source: "wa-web" | "baileys-upstream" | "hardcoded-fallback";
38
+ error?: unknown;
39
+ webError?: unknown;
40
+ }>;
34
41
  export function fetchLatestBaileysVersion(options?: {}): Promise<{
35
42
  version: number[];
36
43
  isLatest: boolean;
@@ -285,7 +285,34 @@ const fetchLatestKageVersion = async (options = {}) => {
285
285
  exports.fetchLatestKageVersion = fetchLatestKageVersion;
286
286
 
287
287
 
288
- const fetchLatestBaileysVersion = async (options = {}) => fetchLatestWaWebVersion(options);
288
+ const fetchLatestBaileysVersion = async (options = {}) => {
289
+ const URL = 'https://raw.githubusercontent.com/WhiskeySockets/Baileys/master/src/Defaults/index.ts';
290
+ try {
291
+ const { timeoutMs = 15000, ...fetchOptions } = options || {};
292
+ const response = await fetch(URL, {
293
+ ...fetchOptions,
294
+ method: 'GET',
295
+ headers: options?.headers,
296
+ signal: fetchOptions.signal || AbortSignal.timeout(timeoutMs)
297
+ });
298
+ if (!response.ok) {
299
+ throw new Error(`Failed to fetch upstream Baileys version: ${response.status} ${response.statusText || ''}`.trim());
300
+ }
301
+ const text = await response.text();
302
+ const match = text.match(/const\s+version\s*=\s*\[(\d+),\s*(\d+),\s*(\d+)\]/);
303
+ if (!match) {
304
+ throw new Error('Could not parse upstream Baileys version');
305
+ }
306
+ const version = match.slice(1).map(Number);
307
+ const fallbackVersion = kageVersionJson.version;
308
+ if (version[0] !== fallbackVersion[0] || version[1] < fallbackVersion[1]) {
309
+ throw new Error(`Rejected incompatible upstream version ${version.join('.')}`);
310
+ }
311
+ return { version, isLatest: true };
312
+ } catch (error) {
313
+ return { version: kageVersionJson.version, isLatest: false, error };
314
+ }
315
+ };
289
316
  exports.fetchLatestBaileysVersion = fetchLatestBaileysVersion;
290
317
 
291
318
 
@@ -1395,3 +1422,25 @@ for (const key of Object.keys(__kageModule169)) {
1395
1422
  if (key !== '__esModule' && !Object.prototype.hasOwnProperty.call(exports,key)) Object.defineProperty(exports,key,{enumerable:true,configurable:true,get:()=>__kageModule169[key]});
1396
1423
  }
1397
1424
  Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule169, configurable:true});
1425
+
1426
+
1427
+ // Compatibility export required by lib/Framework/Bot.js.
1428
+ // Kage exposes fetchLatestWaWebVersion already; use it once and label the
1429
+ // result so Bot can log the source without making a duplicate network call.
1430
+ exports.fetchBestWaVersion = async function fetchBestWaVersion(options = {}) {
1431
+ const webResult = await exports.fetchLatestWaWebVersion(options);
1432
+ if (webResult?.isLatest) {
1433
+ return { ...webResult, source: 'wa-web' };
1434
+ }
1435
+
1436
+ const baileysResult = await exports.fetchLatestBaileysVersion(options);
1437
+ if (baileysResult?.isLatest) {
1438
+ return { ...baileysResult, source: 'baileys-upstream', webError: webResult?.error };
1439
+ }
1440
+
1441
+ return {
1442
+ ...baileysResult,
1443
+ source: 'hardcoded-fallback',
1444
+ error: baileysResult?.error || webResult?.error
1445
+ };
1446
+ };
@@ -10,6 +10,7 @@
10
10
  const crypto = require('crypto');
11
11
  const messages = require('./messages.js');
12
12
  const generics = require('./generics.js');
13
+ const lidAddressing = require('./lid-addressing.js');
13
14
  const { resolvePublicImageUrl, resolveRichImage, DEFAULT_IMAGE } = require('./kage-media-resolve.js');
14
15
 
15
16
  const genFromContent = messages.generateWAMessageFromContent;
@@ -256,11 +257,15 @@ class KageAIRich {
256
257
  mentions,
257
258
  messageId,
258
259
  userJid,
260
+ userJidLid,
259
261
  timestamp,
260
262
  ephemeralExpiration,
261
263
  } = {}) {
262
264
  await this.#resolveProducts();
263
265
 
266
+ const me = this.sock?.authState?.creds?.me || {};
267
+ const resolvedUserJid = userJid || this.sock?.user?.id || me.id;
268
+ const resolvedUserJidLid = userJidLid || this.sock?.user?.lid || me.lid;
264
269
  const sections = [...this._sections];
265
270
  const submessages = [...this._submessages];
266
271
 
@@ -283,9 +288,8 @@ class KageAIRich {
283
288
  }
284
289
 
285
290
  if (quoted?.key) {
286
- const participant = quoted.key.fromMe
287
- ? userJid || quoted.key.participant || quoted.key.remoteJid
288
- : quoted.key.participant || quoted.participant || quoted.key.remoteJid;
291
+ const participant = lidAddressing.getQuotedParticipant(quoted, jid, resolvedUserJid, resolvedUserJidLid)
292
+ || quoted.key.participant || quoted.participant || quoted.key.remoteJid;
289
293
  contextInfo.stanzaId = quoted.key.id;
290
294
  contextInfo.participant = participant;
291
295
  contextInfo.quotedType = 0;
@@ -350,7 +354,8 @@ class KageAIRich {
350
354
  // This keeps normal and HTML responses consistent with the installed WAProto.
351
355
  return genFromContent(jid, content, {
352
356
  messageId: messageId || genId(),
353
- userJid,
357
+ userJid: resolvedUserJid,
358
+ userJidLid: resolvedUserJidLid,
354
359
  timestamp,
355
360
  ephemeralExpiration,
356
361
  });
@@ -364,6 +369,7 @@ class KageAIRich {
364
369
  additionalNodes = [],
365
370
  messageId,
366
371
  userJid,
372
+ userJidLid,
367
373
  timestamp,
368
374
  ephemeralExpiration,
369
375
  ...relayOptions
@@ -378,6 +384,7 @@ class KageAIRich {
378
384
  mentions,
379
385
  messageId,
380
386
  userJid,
387
+ userJidLid,
381
388
  timestamp,
382
389
  ephemeralExpiration,
383
390
  });
@@ -0,0 +1,34 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * Address selection copied in spirit from @this-xys/baileys 2.0.0.
5
+ * WhatsApp may identify the local account by PN or LID depending on the
6
+ * destination. Keep the local participant in the same addressing namespace.
7
+ */
8
+ function isLidUser(jid) {
9
+ return typeof jid === 'string' && jid.endsWith('@lid');
10
+ }
11
+
12
+ function getMeParticipant(targetJid, userJid, userJidLid) {
13
+ return isLidUser(targetJid) && userJidLid ? userJidLid : userJid;
14
+ }
15
+
16
+ function getQuotedParticipant(quoted, jid, userJid, userJidLid) {
17
+ if (!quoted || !quoted.key) return undefined;
18
+ if (quoted.key.fromMe) {
19
+ return getMeParticipant(quoted.key.remoteJid || jid, userJid, userJidLid);
20
+ }
21
+ return quoted.participant || quoted.key.participant || quoted.key.remoteJid;
22
+ }
23
+
24
+ function resolveMessageId(options, generate) {
25
+ const supplied = options && options.messageId;
26
+ return supplied || generate();
27
+ }
28
+
29
+ module.exports = {
30
+ isLidUser,
31
+ getMeParticipant,
32
+ getQuotedParticipant,
33
+ resolveMessageId,
34
+ };
@@ -27,6 +27,7 @@ export function hasOptionalProperty(obj: any, key: any): boolean;
27
27
  export function hasValidAlbumMedia(message: any): boolean;
28
28
  export function hasValidInteractiveHeader(message: any): boolean;
29
29
  export function hasValidCarouselHeader(message: any): boolean;
30
+ export function hasAdvancedMessageOptions(message: any): boolean;
30
31
  export function generateWAMessageContent(message: any, options: any): Promise<any>;
31
32
  export function generateWAMessageFromContent(jid: any, message: any, options: any): proto.WebMessageInfo;
32
33
  export function generateWAMessage(jid: any, content: any, options: any): Promise<proto.WebMessageInfo>;
@@ -15,6 +15,7 @@ const Types_1 = require("../Types");
15
15
  const WABinary_1 = require("../WABinary");
16
16
  const crypto_2 = require("./crypto");
17
17
  const generics_1 = require("./generics");
18
+ const lid_addressing_1 = require("./lid-addressing");
18
19
  const messages_media_1 = require("./messages-media");
19
20
  const MIMETYPE_MAP = {
20
21
  image: 'image/jpeg',
@@ -697,10 +698,10 @@ const generateWAMessageFromContent = (jid, message, options) => {
697
698
  const innerMessage = (0, exports.normalizeMessageContent)(message);
698
699
  const key = (0, exports.getContentType)(innerMessage);
699
700
  const timestamp = (0, generics_1.unixTimestampSeconds)(options.timestamp);
700
- const { quoted, userJid } = options;
701
+ const { quoted, userJid, userJidLid } = options;
701
702
 
702
703
  if (quoted && !(0, WABinary_1.isJidNewsletter)(jid)) {
703
- let participant = quoted.key.fromMe ? userJid : (quoted.participant || quoted.key.participant || quoted.key.remoteJid);
704
+ let participant = (0, lid_addressing_1.getQuotedParticipant)(quoted, jid, userJid, userJidLid);
704
705
  // Prefer PN over LID for quoted participant (avoids LID confusion in replies)
705
706
  try {
706
707
  if (participant && typeof participant === 'string' && participant.endsWith('@lid')) {
@@ -747,6 +748,14 @@ const generateWAMessageFromContent = (jid, message, options) => {
747
748
 
748
749
  };
749
750
  }
751
+ const messageContextInfo = message.messageContextInfo;
752
+ if (messageContextInfo?.messageSecret && ((0, WABinary_1.isJidUser)(jid) || (0, WABinary_1.isLidUser)(jid))) {
753
+ messageContextInfo.deviceListMetadata = {
754
+ recipientKeyHash: (0, crypto_1.randomBytes)(10),
755
+ recipientTimestamp: (0, generics_1.unixTimestampSeconds)()
756
+ };
757
+ messageContextInfo.deviceListMetadataVersion = 2;
758
+ }
750
759
  message = Types_1.WAProto.Message.fromObject(message);
751
760
  const messageJSON = {
752
761
  key: {
@@ -757,7 +766,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
757
766
  message: message,
758
767
  messageTimestamp: timestamp,
759
768
  messageStubParameters: [],
760
- participant: (0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidStatusBroadcast)(jid) ? userJid : undefined,
769
+ participant: (0, WABinary_1.isJidGroup)(jid) || (0, WABinary_1.isJidStatusBroadcast)(jid) ? (0, lid_addressing_1.getMeParticipant)(jid, userJid, userJidLid) : undefined,
761
770
  status: Types_1.WAMessageStatus.PENDING
762
771
  };
763
772
  return Types_1.WAProto.WebMessageInfo.fromObject(messageJSON);
@@ -2920,6 +2929,7 @@ const index_js_5 = require("../WABinary/index.js");
2920
2929
  const crypto_js_1 = require("./crypto.js");
2921
2930
  const generics_js_1 = require("./generics.js");
2922
2931
  const messages_media_js_1 = require("./messages-media.js");
2932
+ const lid_addressing_js_1 = require("./lid-addressing.js");
2923
2933
  const rich_message_utils_js_1 = require("./rich-message-utils.js");
2924
2934
  const reporting_utils_js_1 = require("./reporting-utils.js");
2925
2935
  const MIMETYPE_MAP = {
@@ -4336,11 +4346,9 @@ const generateWAMessageFromContent = (jid, message, options) => {
4336
4346
  const key = (0, exports.getContentType)(innerMessage);
4337
4347
  const timestamp = (0, generics_js_1.unixTimestampSeconds)(options.timestamp);
4338
4348
  const isNewsletter = (0, index_js_5.isJidNewsletter)(jid);
4339
- const { quoted, userJid } = options;
4349
+ const { quoted, userJid, userJidLid } = options;
4340
4350
  if (quoted) {
4341
- const participant = quoted.key.fromMe
4342
- ? userJid
4343
- : quoted.participant || quoted.key.participant || quoted.key.remoteJid;
4351
+ const participant = (0, lid_addressing_js_1.getQuotedParticipant)(quoted, jid, userJid, userJidLid);
4344
4352
  let quotedMsg = (0, exports.normalizeMessageContent)(quoted.message);
4345
4353
  const msgType = (0, exports.getContentType)(quotedMsg);
4346
4354
 
@@ -4396,7 +4404,7 @@ const generateWAMessageFromContent = (jid, message, options) => {
4396
4404
  message: ensureMessageProto(message),
4397
4405
  messageTimestamp: timestamp,
4398
4406
  messageStubParameters: [],
4399
- participant: (0, index_js_5.isJidGroup)(jid) || (0, index_js_5.isJidStatusBroadcast)(jid) ? userJid : undefined,
4407
+ participant: (0, index_js_5.isJidGroup)(jid) || (0, index_js_5.isJidStatusBroadcast)(jid) ? (0, lid_addressing_js_1.getMeParticipant)(jid, userJid, userJidLid) : undefined,
4400
4408
  status: index_js_4.WAMessageStatus.PENDING
4401
4409
  });
4402
4410
  };
@@ -4795,7 +4803,7 @@ Object.defineProperty(exports, Symbol.for('kage.advanced'), {value:__kageModule1
4795
4803
  const advanced=exports[Symbol.for('kage.advanced')];
4796
4804
  const originalContent=exports.generateWAMessageContent;
4797
4805
  const originalMedia=exports.prepareWAMessageMedia;
4798
- const advancedKeys=['raw','code','links','table','richResponse','stickers','flowReply','buttonReply','listReply','nativeFlow','cards','paymentInviteServiceType','orderText','requestPaymentFrom','invoiceNote','groupStatus','spoiler','isLottie','viewOnceV2','viewOnceV2Extension','interactiveAsTemplate','secureMetaServiceLabel','mentionAll','pollResult','pollUpdate','limitSharing','favicon'];
4806
+ const advancedKeys=['raw','code','links','table','richResponse','stickers','flowReply','buttonReply','listReply','nativeFlow','cards','paymentInviteServiceType','orderText','requestPaymentFrom','invoiceNote','groupStatus','spoiler','isLottie','viewOnceV2','viewOnceV2Extension','interactiveAsTemplate','secureMetaServiceLabel','mentionAll','pollResult','pollUpdate','limitSharing','favicon','event','poll','ai'];
4799
4807
  exports.hasAdvancedMessageOptions=message=>!!message&&advancedKeys.some(k=>message[k]!=null);
4800
4808
  exports.generateWAMessageContent=async(message,options={})=>{
4801
4809
  if(exports.hasAdvancedMessageOptions(message)){
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kage-baileys",
3
- "version": "25.3.8",
3
+ "version": "25.3.10",
4
4
  "description": "Kage Baileys full merge — Builders + mbuilder + Framework + advanced sticker packs + KAGE pairing + extended WAProto + full TypeScript defs (.d.ts + maps) from elray + path utils. Multi-device ready.",
5
5
  "keywords": [
6
6
  "kage-baileys",