@langitdeveloper/baileys 2.0.6 → 2.0.8

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.
@@ -105,6 +105,21 @@ function makeLibSignalRepository(auth) {
105
105
  const cipher = new libsignal.SessionBuilder(storage, jidToSignalProtocolAddress(jid));
106
106
  await cipher.initOutgoing(session);
107
107
  },
108
+ async validateSession(jid) {
109
+ try {
110
+ const addr = jidToSignalProtocolAddress(jid);
111
+ const session = await storage.loadSession(addr.toString());
112
+ if (!session) {
113
+ return { exists: false, reason: 'no session' };
114
+ }
115
+ if (!session.haveOpenSession()) {
116
+ return { exists: false, reason: 'no open session' };
117
+ }
118
+ return { exists: true };
119
+ } catch (error) {
120
+ return { exists: false, reason: 'validation error' };
121
+ }
122
+ },
108
123
  jidToSignalProtocolAddress(jid) {
109
124
  return jidToSignalProtocolAddress(jid).toString();
110
125
  }
@@ -68,6 +68,7 @@ const makeGroupsSocket = (config) => {
68
68
  });
69
69
  return {
70
70
  ...sock,
71
+ groupQuery,
71
72
  groupMetadata,
72
73
  groupCreate: async (subject, participants) => {
73
74
  const key = (0, Utils_1.generateMessageID)();
@@ -7,3 +7,4 @@ Object.defineProperty(exports, "WAProto", { enumerable: true, get: function () {
7
7
  exports.WAMessageStubType = WAProto_1.proto.WebMessageInfo.StubType;
8
8
  // eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
9
9
  exports.WAMessageStatus = WAProto_1.proto.WebMessageInfo.Status;
10
+ exports.WAMessageAddressingMode = { PN: 'pn', LID: 'lid' };
@@ -178,6 +178,12 @@ exports.generateMessageIDV2 = generateMessageIDV2;
178
178
  // generate a random ID to attach to a message
179
179
  const generateMessageID = () => 'ILSYM-' + (0, crypto_1.randomBytes)(6).toString('hex').toUpperCase();
180
180
  exports.generateMessageID = generateMessageID;
181
+ const generateParticipantHashV2 = (participants) => {
182
+ participants.sort();
183
+ const sha256Hash = (0, crypto_1.createHash)('sha256').update(Buffer.from(participants.join(''))).digest('base64');
184
+ return '2:' + sha256Hash.slice(0, 6);
185
+ };
186
+ exports.generateParticipantHashV2 = generateParticipantHashV2;
181
187
  function bindWaitForEvent(ev, event) {
182
188
  return async (check, timeoutMs) => {
183
189
  let listener;
@@ -565,6 +565,66 @@ const generateWAMessage = async (jid, content, options) => {
565
565
  return (0, exports.generateWAMessageFromContent)(jid, await (0, exports.generateWAMessageContent)(content, { newsletter: (0, WABinary_1.isJidNewsLetter)(jid), ...options }), options);
566
566
  };
567
567
  exports.generateWAMessage = generateWAMessage;
568
+ const prepareAlbumMessageContent = async (jid, albums, options) => {
569
+ if (!Array.isArray(albums)) {
570
+ throw new Error("albums must be an array containing media objects.");
571
+ }
572
+ if (albums.length === 0) {
573
+ throw new Error("albums cannot be empty. At least one media item is required.");
574
+ }
575
+ const validCount = albums.filter((m) => 'image' in m || 'video' in m).length;
576
+ if (validCount === 0) {
577
+ throw new Error("albums contains no valid media. Use 'image' or 'video' keys.");
578
+ }
579
+ let mediaHandle;
580
+ let mediaMsg;
581
+ const message = [];
582
+ const albumMsg = generateWAMessageFromContent(jid, {
583
+ albumMessage: {
584
+ expectedImageCount: albums.filter((item) => 'image' in item).length,
585
+ expectedVideoCount: albums.filter((item) => 'video' in item).length,
586
+ },
587
+ }, options);
588
+ await options.conn.relayMessage(jid, albumMsg.message, {
589
+ messageId: albumMsg.key.id,
590
+ });
591
+ for (const media of albums) {
592
+ let content = {};
593
+ if ('image' in media) {
594
+ content = { image: media.image };
595
+ }
596
+ else if ('video' in media) {
597
+ content = { video: media.video };
598
+ }
599
+ else {
600
+ continue;
601
+ }
602
+ mediaMsg = await generateWAMessage(jid, { ...content, ...media }, {
603
+ userJid: options.userJid,
604
+ upload: async (encFilePath, opts) => {
605
+ const up = await options.conn.waUploadToServer(encFilePath, {
606
+ ...opts,
607
+ newsletter: (0, WABinary_1.isJidNewsLetter)(jid),
608
+ });
609
+ mediaHandle = up.handle;
610
+ return up;
611
+ },
612
+ ...options,
613
+ });
614
+ if (mediaMsg) {
615
+ mediaMsg.message.messageContextInfo = {
616
+ messageSecret: crypto_1.randomBytes(32),
617
+ messageAssociation: {
618
+ associationType: WAProto_1.proto.MessageAssociation.AssociationType.MEDIA_ALBUM,
619
+ parentMessageKey: albumMsg.key,
620
+ },
621
+ };
622
+ }
623
+ message.push(mediaMsg);
624
+ }
625
+ return message;
626
+ };
627
+ exports.prepareAlbumMessageContent = prepareAlbumMessageContent;
568
628
  /** Get the key to access the true type of content */
569
629
  const getContentType = (content) => {
570
630
  if (content) {
@@ -196,3 +196,15 @@ const getAdditionalNode = (name) => {
196
196
  }
197
197
  }
198
198
  exports.getAdditionalNode = getAdditionalNode;
199
+ const getBinaryFilteredButtons = (nodeContent) => {
200
+ if (!Array.isArray(nodeContent)) return false;
201
+ return nodeContent.some((a) => ['native_flow'].includes(a?.content?.[0]?.content?.[0]?.tag) ||
202
+ ['interactive', 'buttons', 'list'].includes(a?.content?.[0]?.tag) ||
203
+ ['hsm', 'biz'].includes(a?.tag));
204
+ };
205
+ exports.getBinaryFilteredButtons = getBinaryFilteredButtons;
206
+ const getBinaryFilteredBizBot = (nodeContent) => {
207
+ if (!Array.isArray(nodeContent)) return false;
208
+ return nodeContent.some((b) => ['bot'].includes(b?.tag) && b?.attrs?.biz_bot === '1');
209
+ };
210
+ exports.getBinaryFilteredBizBot = getBinaryFilteredBizBot;
@@ -60,3 +60,10 @@ const jidNormalizedUser = (jid) => {
60
60
  return (0, exports.jidEncode)(user, server === 'c.us' ? 's.whatsapp.net' : server);
61
61
  };
62
62
  exports.jidNormalizedUser = jidNormalizedUser;
63
+ exports.WAJIDDomains = { WHATSAPP: 0, LID: 1, HOSTED: 128, HOSTED_LID: 129 };
64
+ exports.isPnUser = isJidUser;
65
+ exports.isJidNewsletter = isJidNewsLetter;
66
+ const isHostedPnUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@hosted'));
67
+ exports.isHostedPnUser = isHostedPnUser;
68
+ const isHostedLidUser = (jid) => (jid === null || jid === void 0 ? void 0 : jid.endsWith('@hosted.lid'));
69
+ exports.isHostedLidUser = isHostedLidUser;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langitdeveloper/baileys",
3
- "version": "2.0.6",
3
+ "version": "2.0.8",
4
4
  "description": "WhatsApp API Modification By Langit",
5
5
  "keywords": [
6
6
  "whatsapp",
@@ -54,7 +54,8 @@
54
54
  "protobufjs": "^7.2.4",
55
55
  "uuid": "^9.0.0",
56
56
  "ws": "^8.13.0",
57
- "p-queue": "^6.6.2"
57
+ "p-queue": "^6.6.2",
58
+ "lru-cache": "^10.0.0"
58
59
  },
59
60
  "devDependencies": {
60
61
  "@adiwajshing/eslint-config": "github:adiwajshing/eslint-config",