kage-baileys 25.3.7 → 25.3.9

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.
@@ -0,0 +1,4 @@
1
+ {
2
+ "private": true,
3
+ "type": "module"
4
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * TypeScript compatibility surface for the runtime-normalized WAProto export.
3
+ * The runtime protobuf constructors are generated from WAProto.proto; these
4
+ * declarations intentionally keep uncommon generated fields permissive so
5
+ * they do not claim a hand-maintained schema that can drift from the proto.
6
+ * For exact field-level types, use the checked-in WAProto.proto definitions.
7
+ */
8
+ export declare namespace proto {
9
+ export interface WebMessageInfo {
10
+ key?: any;
11
+ message?: Message;
12
+ messageTimestamp?: any;
13
+ messageStubType?: any;
14
+ [key: string]: any;
15
+ }
16
+ export namespace WebMessageInfo {
17
+ const Status: any;
18
+ const StubType: any;
19
+ }
20
+
21
+ export interface Message {
22
+ [key: string]: any;
23
+ }
24
+ export namespace Message {
25
+ export interface $Properties { [key: string]: any; }
26
+ export interface PollVoteMessage { [key: string]: any; }
27
+ export interface EventResponseMessage { [key: string]: any; }
28
+ export namespace ButtonsMessage {
29
+ const HeaderType: any;
30
+ export namespace Button { const Type: any; }
31
+ }
32
+ export namespace InteractiveMessage {
33
+ export namespace CarouselMessage { const CarouselCardType: any; }
34
+ }
35
+ export namespace ListMessage { const ListType: any; }
36
+ export namespace ProtocolMessage { const Type: any; }
37
+ }
38
+
39
+ export namespace MessageAssociation { const AssociationType: any; }
40
+ export namespace HistorySync { type HistorySyncType = any; }
41
+ export namespace SyncdMutation { type SyncdOperation = any; }
42
+ export interface SyncdMutations { [key: string]: any; }
43
+ export interface MediaRetryNotification { [key: string]: any; }
44
+ export interface ClientPayload { [key: string]: any; }
45
+ export interface ADVSignedDeviceIdentity { [key: string]: any; }
46
+ }
@@ -742,7 +742,7 @@ class AIRich extends BaseBuilder {
742
742
  this._noContextInfo = false;
743
743
  this._unifiedResponseData = undefined;
744
744
  this._messageSecret = false;
745
- this._bypassDownload = true;
745
+ this._bypassDownload = false;
746
746
  this._forwarded = true;
747
747
  this._includesUnifiedResponse = true;
748
748
  this._includesSubmessages = true;
@@ -1995,7 +1995,7 @@ class AIRich extends BaseBuilder {
1995
1995
  includesSubmessages = this._includesSubmessages,
1996
1996
  messageId,
1997
1997
  additionalNodes = [],
1998
- skipImageFallback = false,
1998
+ skipImageFallback = true,
1999
1999
  nativeEdit = false,
2000
2000
  ...options
2001
2001
  } = {}
@@ -1,7 +1,8 @@
1
1
  import crypto from 'node:crypto';
2
2
  import fs from 'node:fs';
3
- import baileys from '@whiskeysockets/baileys';
4
- const { generateWAMessageFromContent, prepareWAMessageMedia } = baileys;
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ const { generateWAMessageFromContent, prepareWAMessageMedia } = require('../../Utils/messages.js');
5
6
  import {
6
7
  a2uiText,
7
8
  a2uiImage,
@@ -2,7 +2,10 @@
2
2
 
3
3
  const VERSION = '4.7';
4
4
 
5
- import { generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2 } from '@whiskeysockets/baileys';
5
+ import { createRequire } from 'node:module';
6
+ const require = createRequire(import.meta.url);
7
+ const { generateWAMessageFromContent, prepareWAMessageMedia } = require('../../Utils/messages.js');
8
+ const { generateMessageIDV2 } = require('../../Utils/generics.js');
6
9
  import crypto from 'crypto';
7
10
  import sharp from 'sharp';
8
11
  import ffmpeg from 'fluent-ffmpeg';
@@ -1942,7 +1945,7 @@ class AIRich extends BaseBuilder {
1942
1945
 
1943
1946
  async build(
1944
1947
  jid,
1945
- { bypassDownload = true, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, quoted, quotedParticipant, messageId, ...options } = {}
1948
+ { bypassDownload = false, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, quoted, quotedParticipant, messageId, ...options } = {}
1946
1949
  ) {
1947
1950
  const forward = forwarded
1948
1951
  ? {
@@ -2080,7 +2083,7 @@ class AIRich extends BaseBuilder {
2080
2083
  return msgEdit;
2081
2084
  }
2082
2085
 
2083
- async send(jid, { bypassDownload = true, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, messageId, additionalNodes = [], ...options } = {}) {
2086
+ async send(jid, { bypassDownload = false, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, messageId, additionalNodes = [], ...options } = {}) {
2084
2087
  const msg = await this.build(jid, {
2085
2088
  forwarded,
2086
2089
  notification,
@@ -26,7 +26,7 @@ export function setAIRichClass(cls) {
26
26
  }
27
27
  export function getAIRichClass() {
28
28
  if (!_AIRichClass) {
29
- _AIRichClass = baileys.AIRich;
29
+ throw new Error('AIRich class is not initialized; import the Kage mbuilder entry point before using this helper');
30
30
  }
31
31
  return _AIRichClass;
32
32
  }
@@ -41,8 +41,9 @@ const AIRich = new Proxy(class {}, {
41
41
  return new cls(...args);
42
42
  }
43
43
  });
44
- import baileys from '@whiskeysockets/baileys';
45
- const { extractMessageContent, generateWAMessageFromContent, prepareWAMessageMedia } = baileys;
44
+ import { createRequire } from 'node:module';
45
+ const require = createRequire(import.meta.url);
46
+ const { extractMessageContent, generateWAMessageFromContent, prepareWAMessageMedia } = require('../../Utils/messages.js');
46
47
  import { checkHtmlApp } from './html-app.js'
47
48
 
48
49
  export const AI_RICH_LAYOUTS = Object.freeze([
@@ -427,7 +428,7 @@ export const htmlSection = (html, { trustedSources = [], height, typename = AI_R
427
428
  })
428
429
  }
429
430
 
430
- export const sendHtmlApp = async (sock, jid, html, { title = '', label, trustedSources, height, autoHeight: auto, scrollButtons, typename, id, bypassDownload = true, guard = 'warn', botJid = '867051314767696@bot', contextInfo = {}, ...options } = {}) => {
431
+ export const sendHtmlApp = async (sock, jid, html, { title = '', label, trustedSources, height, autoHeight: auto, scrollButtons, typename, id, bypassDownload = false, guard = 'warn', botJid = '867051314767696@bot', contextInfo = {}, ...options } = {}) => {
431
432
  if (!sock) {
432
433
  throw new TypeError('sendHtmlApp requires a socket as the first argument')
433
434
  }
@@ -1,11 +1,11 @@
1
1
  const VERSION = '4.7';
2
2
 
3
- import baileys from '@whiskeysockets/baileys';
4
- const { generateWAMessageFromContent, prepareWAMessageMedia, generateMessageIDV2 } = baileys;;
5
- import * as crypto from 'node:crypto';
6
- import { readFile } from 'node:fs/promises';
7
3
  import { createRequire } from 'node:module';
8
4
  const requireModule = createRequire(import.meta.url);
5
+ const { generateWAMessageFromContent, prepareWAMessageMedia } = requireModule('../../Utils/messages.js');
6
+ const { generateMessageIDV2 } = requireModule('../../Utils/generics.js');
7
+ import * as crypto from 'node:crypto';
8
+ import { readFile } from 'node:fs/promises';
9
9
  import { loadFfmpeg, loadSharp } from './optional-media.js';
10
10
  import { isParsableCertificateChain } from './bot-signature.js';
11
11
  import { PassThrough, Readable } from 'node:stream';
@@ -2332,7 +2332,7 @@ class AIRich extends BaseBuilder {
2332
2332
 
2333
2333
  async build(
2334
2334
  jid,
2335
- { bypassDownload = true, forwarded = true, forwardWrapper = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, botJid = AIRich.DEFAULT_BOT_JID, disclaimerText = '', verification = 'auto', quoted, quotedParticipant, messageId, ...options } = {}
2335
+ { bypassDownload = false, forwarded = true, forwardWrapper = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, botJid = AIRich.DEFAULT_BOT_JID, disclaimerText = '', verification = 'auto', quoted, quotedParticipant, messageId, ...options } = {}
2336
2336
  ) {
2337
2337
  const forward = forwarded
2338
2338
  ? {
@@ -2508,7 +2508,7 @@ class AIRich extends BaseBuilder {
2508
2508
  return msgEdit;
2509
2509
  }
2510
2510
 
2511
- async send(jid, { bypassDownload = true, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, messageId, additionalNodes = [], ...options } = {}) {
2511
+ async send(jid, { bypassDownload = false, forwarded = true, notification = false, includesUnifiedResponse = true, includesSubmessages = true, messageId, additionalNodes = [], ...options } = {}) {
2512
2512
  const msg = await this.build(jid, {
2513
2513
  forwarded,
2514
2514
  notification,
@@ -3694,6 +3694,7 @@ class ORich extends AIRich {}
3694
3694
 
3695
3695
  import { A2UI, sendA2UIWidget } from "./a2ui.js";
3696
3696
  import * as Extras from "./extras.js";
3697
+ Extras.setAIRichClass(AIRich);
3697
3698
  import * as MetaAI from "./metaai.js";
3698
3699
  import * as BotSignature from "./bot-signature.js";
3699
3700
  import * as HtmlApp from "./html-app.js";
@@ -1,7 +1,8 @@
1
1
  import { AIRich } from './index.js'
2
2
  import { AddonActionType } from './extras.js'
3
- import baileys from '@whiskeysockets/baileys';
4
- const { generateWAMessageFromContent } = baileys;
3
+ import { createRequire } from 'node:module';
4
+ const require = createRequire(import.meta.url);
5
+ const { generateWAMessageFromContent } = require('../../Utils/messages.js');
5
6
  import { BOT_SIGNATURE_USE_CASE_WA_BOT_MSG, verifyBotSignature } from './bot-signature.js'
6
7
 
7
8
  export const MapQueryStatus = Object.freeze({ FETCHING: 'FETCHING', FETCHED: 'FETCHED', FAILED: 'FAILED' })
@@ -359,5 +359,4 @@ for (const name of ['WA_CERT_DETAILS', 'MEDIA_PATH_MAP', 'MEDIA_HKDF_KEY_MAPPING
359
359
  exports.MEDIA_HKDF_KEY_MAPPING['product-catalog-image'] = 'Product Catalog Image';
360
360
  exports.MEDIA_KEYS = [...new Set([...exports.MEDIA_KEYS, ...Object.keys(exports.MEDIA_PATH_MAP)])];
361
361
 
362
- // Kage: AI bot JID used by AIRich forward/default target
363
- exports.DEFAULT_AI_BOT_JID = process.env.KAGE_AI_BOT_JID || '13135550002@s.whatsapp.net';
362
+ exports.DEFAULT_AI_BOT_JID = process.env.KAGE_AI_BOT_JID || "13135550002@s.whatsapp.net";
@@ -1,6 +1,9 @@
1
1
  "use strict";
2
2
  const layers = ['chats', 'newsletter', 'messages-send', 'business', 'community', 'socket'];
3
+ const INSTALL_KEY = Symbol.for('kage-baileys.extensions-installed');
3
4
  exports.installExtensions = (socket, config) => {
5
+ if (!socket || typeof socket !== 'object') throw new TypeError('installExtensions requiere un socket');
6
+ if (socket[INSTALL_KEY]) return socket;
4
7
  for (const layer of layers) {
5
8
  const additions = require('./' + layer).attach(socket, config);
6
9
  for (const key of Object.keys(additions)) {
@@ -17,7 +20,7 @@ exports.installExtensions = (socket, config) => {
17
20
  if(layer==='messages-send'){
18
21
  const originalSend=socket.sendMessage.bind(socket);
19
22
  socket.sendMessage=(jid,content,options={})=>{
20
- 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);
21
24
  return useAdvanced?additions.sendMessage(jid,content,options):originalSend(jid,content,options);
22
25
  };
23
26
  }
@@ -26,5 +29,7 @@ exports.installExtensions = (socket, config) => {
26
29
  socket.messageRetryManager?.clear?.();
27
30
  socket.signalRepository?.lidMapping?.close?.();
28
31
  });
32
+ try { Object.defineProperty(socket, INSTALL_KEY, { value: true, configurable: false }); }
33
+ catch { socket[INSTALL_KEY] = true; }
29
34
  return socket;
30
35
  };
@@ -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;
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ const { spawnSync } = require("child_process");
3
+ const { existsSync } = require("fs");
4
+ let overridePath = null;
5
+ let cached;
6
+ async function moduleProvidedPath() {
7
+ try {
8
+ const mod = await import("ffmpeg-static");
9
+ const p = mod?.default ?? mod;
10
+ if (typeof p === "string" && existsSync(p)) return p;
11
+ } catch {}
12
+ try {
13
+ const mod = await import("@ffmpeg-installer/ffmpeg");
14
+ const p = (mod?.default ?? mod)?.path;
15
+ if (typeof p === "string" && existsSync(p)) return p;
16
+ } catch {}
17
+ return null;
18
+ }
19
+ function systemHasFfmpeg() {
20
+ try {
21
+ const r = spawnSync("ffmpeg", ["-version"], { stdio: "ignore" });
22
+ return !r.error && r.status === 0;
23
+ } catch { return false; }
24
+ }
25
+ function setFfmpegPath(path) { overridePath = path || null; cached = undefined; }
26
+ async function resolveFfmpegPath() {
27
+ if (overridePath) return overridePath;
28
+ if (process.env.FFMPEG_PATH && existsSync(process.env.FFMPEG_PATH)) return process.env.FFMPEG_PATH;
29
+ if (cached !== undefined) return cached;
30
+ cached = (await moduleProvidedPath()) ?? (systemHasFfmpeg() ? "ffmpeg" : null);
31
+ return cached;
32
+ }
33
+ function ffmpegInstallHint() {
34
+ return "ffmpeg not found. Install: npm i ffmpeg-static OR system ffmpeg OR set FFMPEG_PATH";
35
+ }
36
+ async function requireFfmpegPath() {
37
+ const path = await resolveFfmpegPath();
38
+ if (path) return path;
39
+ throw new Error(ffmpegInstallHint());
40
+ }
41
+ module.exports = { setFfmpegPath, resolveFfmpegPath, requireFfmpegPath, ffmpegInstallHint, getFfmpegPath: resolveFfmpegPath };
42
+ exports.setFfmpegPath = setFfmpegPath;
43
+ exports.resolveFfmpegPath = resolveFfmpegPath;
44
+ exports.requireFfmpegPath = requireFfmpegPath;
45
+ exports.ffmpegInstallHint = ffmpegInstallHint;
46
+ exports.getFfmpegPath = resolveFfmpegPath;