@kanaraa/baileys 3.4.0 → 3.5.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.
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectRepository = void 0;
4
+ class ObjectRepository {
5
+ constructor(entities = {}) {
6
+ this.entityMap = new Map(Object.entries(entities));
7
+ }
8
+ findById(id) {
9
+ return this.entityMap.get(id);
10
+ }
11
+ findAll() {
12
+ return Array.from(this.entityMap.values());
13
+ }
14
+ upsertById(id, entity) {
15
+ return this.entityMap.set(id, { ...entity });
16
+ }
17
+ deleteById(id) {
18
+ return this.entityMap.delete(id);
19
+ }
20
+ count() {
21
+ return this.entityMap.size;
22
+ }
23
+ toJSON() {
24
+ return this.findAll();
25
+ }
26
+ }
27
+ exports.ObjectRepository = ObjectRepository;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.XWAPaths = exports.MexOperations = void 0;
4
+ var MexOperations;
5
+ (function (MexOperations) {
6
+ MexOperations["PROMOTE"] = "NotificationNewsletterAdminPromote";
7
+ MexOperations["DEMOTE"] = "NotificationNewsletterAdminDemote";
8
+ MexOperations["UPDATE"] = "NotificationNewsletterUpdate";
9
+ })(MexOperations || (exports.MexOperations = MexOperations = {}));
10
+ var XWAPaths;
11
+ (function (XWAPaths) {
12
+ XWAPaths["PROMOTE"] = "xwa2_notify_newsletter_admin_promote";
13
+ XWAPaths["DEMOTE"] = "xwa2_notify_newsletter_admin_demote";
14
+ XWAPaths["ADMIN_COUNT"] = "xwa2_newsletter_admin";
15
+ XWAPaths["CREATE"] = "xwa2_newsletter_create";
16
+ XWAPaths["NEWSLETTER"] = "xwa2_newsletter";
17
+ XWAPaths["METADATA_UPDATE"] = "xwa2_notify_newsletter_on_metadata_update";
18
+ })(XWAPaths || (exports.XWAPaths = XWAPaths = {}));
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.readAndEmitEventStream = exports.captureEventStream = void 0;
7
+ const events_1 = __importDefault(require("events"));
8
+ const fs_1 = require("fs");
9
+ const promises_1 = require("fs/promises");
10
+ const readline_1 = require("readline");
11
+ const generics_1 = require("./generics");
12
+ const make_mutex_1 = require("./make-mutex");
13
+ /**
14
+ * Captures events from a wileys event emitter & stores them in a file
15
+ * @param ev The event emitter to read events from
16
+ * @param filename File to save to
17
+ */
18
+ const captureEventStream = (ev, filename) => {
19
+ const oldEmit = ev.emit;
20
+ // write mutex so data is appended in order
21
+ const writeMutex = (0, make_mutex_1.makeMutex)();
22
+ // monkey patch eventemitter to capture all events
23
+ ev.emit = function (...args) {
24
+ const content = JSON.stringify({ timestamp: Date.now(), event: args[0], data: args[1] }) + '\n';
25
+ const result = oldEmit.apply(ev, args);
26
+ writeMutex.mutex(async () => {
27
+ await (0, promises_1.writeFile)(filename, content, { flag: 'a' });
28
+ });
29
+ return result;
30
+ };
31
+ };
32
+ exports.captureEventStream = captureEventStream;
33
+ /**
34
+ * Read event file and emit events from there
35
+ * @param filename filename containing event data
36
+ * @param delayIntervalMs delay between each event emit
37
+ */
38
+ const readAndEmitEventStream = (filename, delayIntervalMs = 0) => {
39
+ const ev = new events_1.default();
40
+ const fireEvents = async () => {
41
+ // from: https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
42
+ const fileStream = (0, fs_1.createReadStream)(filename);
43
+ const rl = (0, readline_1.createInterface)({
44
+ input: fileStream,
45
+ crlfDelay: Infinity
46
+ });
47
+ // Note: we use the crlfDelay option to recognize all instances of CR LF
48
+ // ('\r\n') in input.txt as a single line break.
49
+ for await (const line of rl) {
50
+ if (line) {
51
+ const { event, data } = JSON.parse(line);
52
+ ev.emit(event, data);
53
+ delayIntervalMs && await (0, generics_1.delay)(delayIntervalMs);
54
+ }
55
+ }
56
+ fileStream.close();
57
+ };
58
+ return {
59
+ ev,
60
+ task: fireEvents()
61
+ };
62
+ };
63
+ exports.readAndEmitEventStream = readAndEmitEventStream;
@@ -1658,6 +1658,32 @@ export const generateWAMessageContent = async (message, options) => {
1658
1658
  sections.push(newLayout(layout, suggest.length === 1 ? suggest[0] : suggest));
1659
1659
  }
1660
1660
 
1661
+ if (rich.widget) {
1662
+ const w = rich.widget;
1663
+ sections.push(newLayout('Single', {
1664
+ title: w.title ?? '',
1665
+ sections: w.sections ?? [],
1666
+ actions: (w.actions ?? []).map(a => ({
1667
+ label: a.label ?? '',
1668
+ kind: a.kind ?? 'OTHER',
1669
+ state: a.state ?? 'PENDING',
1670
+ id: a.id ?? ''
1671
+ })),
1672
+ __typename: 'GenAIWidgetCardPrimitive'
1673
+ }));
1674
+ }
1675
+
1676
+ if (rich.footerAction || rich.footerBtn) {
1677
+ const fa = rich.footerAction || rich.footerBtn;
1678
+ sections.push(newLayout('Single', {
1679
+ action: {
1680
+ text: fa.text ?? '',
1681
+ url: fa.url ?? ''
1682
+ },
1683
+ __typename: 'GenAIFooterActionPrimitive'
1684
+ }));
1685
+ }
1686
+
1661
1687
  if (rich.footer) {
1662
1688
  sections.push(newLayout('Single', { text: rich.footer, __typename: 'GenAIMetadataTextPrimitive' }));
1663
1689
  }
@@ -1673,17 +1699,53 @@ export const generateWAMessageContent = async (message, options) => {
1673
1699
  }));
1674
1700
  }
1675
1701
 
1702
+ if (rich.customSections && Array.isArray(rich.customSections)) {
1703
+ sections.push(...rich.customSections);
1704
+ }
1705
+
1706
+ const generateVerificationMetadata = () => {
1707
+ const signatureMaterial = Buffer.from(
1708
+ 'NIXEL.MessageBuilderV4.7-VerificationSignature.Metadata'
1709
+ );
1710
+ const certificateMaterial = Buffer.from(
1711
+ 'NIXEL.MessageBuilderV4.7-CertificateChain.Metadata'
1712
+ );
1713
+ const signature = Buffer.concat([
1714
+ signatureMaterial,
1715
+ randomBytes(64 - signatureMaterial.length)
1716
+ ]).toString('base64');
1717
+ const certificateChain = [
1718
+ Buffer.concat([certificateMaterial, randomBytes(684 - certificateMaterial.length)]).toString('base64'),
1719
+ Buffer.concat([certificateMaterial, randomBytes(892 - certificateMaterial.length)]).toString('base64')
1720
+ ];
1721
+ return {
1722
+ proofs: [
1723
+ {
1724
+ version: 1,
1725
+ useCase: 1,
1726
+ signature,
1727
+ certificateChain
1728
+ }
1729
+ ]
1730
+ };
1731
+ };
1732
+
1676
1733
  const [resolvedSections, resolvedSubmessages] = await Promise.all([
1677
1734
  Toolkit.waitAllPromises(sections),
1678
1735
  Toolkit.waitAllPromises(submessages)
1679
1736
  ]);
1680
1737
 
1738
+ const unifiedJsonStr = JSON.stringify({ response_id: randomUUID(), sections: resolvedSections });
1739
+ const unifiedDataBase64 = Buffer.from(unifiedJsonStr).toString('base64');
1740
+
1681
1741
  m = {
1682
1742
  messageContextInfo: {
1683
1743
  deviceListMetadata: {},
1684
1744
  deviceListMetadataVersion: 2,
1685
1745
  botMetadata: {
1686
1746
  messageDisclaimerText: rich.title ?? '',
1747
+ verificationMetadata: generateVerificationMetadata(),
1748
+ botResponseId: randomUUID(),
1687
1749
  richResponseSourcesMetadata: { sources: richResponseSources }
1688
1750
  }
1689
1751
  },
@@ -1693,12 +1755,12 @@ export const generateWAMessageContent = async (message, options) => {
1693
1755
  messageType: 1,
1694
1756
  submessages: resolvedSubmessages,
1695
1757
  unifiedResponse: {
1696
- data: Buffer.from(JSON.stringify({ response_id: randomUUID(), sections: resolvedSections })).toString('base64')
1758
+ data: unifiedDataBase64
1697
1759
  },
1698
1760
  contextInfo: {
1699
1761
  forwardingScore: 1,
1700
1762
  isForwarded: true,
1701
- forwardedAiBotMessageInfo: { botJid: '0@bot' },
1763
+ forwardedAiBotMessageInfo: { botJid: '867051314767696@bot' },
1702
1764
  forwardOrigin: 4,
1703
1765
  ...(rich.contextInfo ?? {})
1704
1766
  }
@@ -1991,7 +2053,7 @@ export const generateWAMessageFromContent = (jid, message, options) => {
1991
2053
  }
1992
2054
  }
1993
2055
 
1994
- if (key !== "protocolMessage" && key !== "ephemeralMessage" && !isJidNewsletter(jid)) {
2056
+ if (key !== "protocolMessage" && key !== "ephemeralMessage" && key !== "botForwardedMessage" && !isJidNewsletter(jid)) {
1995
2057
  message.messageContextInfo = {
1996
2058
  threadId: threadId.length > 0 ? threadId : [],
1997
2059
  messageSecret: randomBytes(32),
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@kanaraa/baileys",
3
3
  "type": "module",
4
- "version": "3.4.0",
4
+ "version": "3.5.0",
5
5
  "description": "Modded Baileys v7, Rebuilt on top of official @whiskeysockets/baileys 7.0.0-rc13, with the interactive & rich-message content types (buttons, lists, carousel, cards, shop/collection, native flow, AI rich response, sticker packs, admin invite, payments, etc.).",
6
6
  "keywords": [
7
7
  "whatsapp",