@prototypevip/baileys 0.0.1 → 0.0.3

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.
@@ -975,15 +975,20 @@ export const generateWAMessageContent = async (message, options) => {
975
975
  } else {
976
976
  m = await prepareWAMessageMedia(message, options);
977
977
  }
978
- if (hasOptionalProperty(message, "viewOnce") && !!message.viewOnce) {
978
+ if (
979
+ hasOptionalProperty(message, "viewOnce") &&
980
+ !!message.viewOnce &&
981
+ !m.viewOnceMessage
982
+ ) {
979
983
  m = { viewOnceMessage: { message: m } };
980
984
  }
981
985
  if (
982
986
  (hasOptionalProperty(message, "mentions") && message.mentions?.length) ||
983
987
  (hasOptionalProperty(message, "mentionAll") && message.mentionAll)
984
988
  ) {
985
- const messageType = Object.keys(m)[0];
986
- const key = m[messageType];
989
+ const target = m.viewOnceMessage ? m.viewOnceMessage.message : m;
990
+ const messageType = Object.keys(target)[0];
991
+ const key = target[messageType];
987
992
  if (key && "contextInfo" in key) {
988
993
  key.contextInfo = key.contextInfo || {};
989
994
  if (message.mentions?.length) {
@@ -1431,4 +1436,4 @@ export const assertMediaContent = (content) => {
1431
1436
  });
1432
1437
  }
1433
1438
  return mediaContent;
1434
- };
1439
+ };
@@ -5,13 +5,24 @@ import { LRUCache } from "lru-cache";
5
5
  import fs from "fs";
6
6
  import path from "path";
7
7
 
8
- export const usePrototypeAuthState = async (config = {}) => {
9
- const folder = config.folder || "./auth";
10
- if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
8
+ // Reuse ONE Database connection per auth.db file across every session
9
+ // (sub-bot) in this process, instead of opening a brand-new connection
10
+ // per call. Multiple connections hammering the same WAL-mode file is the
11
+ // most likely cause of the occasional "freeze" — a read/write can end up
12
+ // waiting on SQLITE_BUSY behind another connection's lock, which stalls
13
+ // whatever baileys handler triggered it (looks like the bot hung).
14
+ // This also lets us checkpoint + close cleanly on shutdown, so a killed
15
+ // process doesn't leave the WAL file in a state that causes the next
16
+ // boot to stall while SQLite recovers it.
17
+ const dbPool = new Map();
18
+ let exitHandlersRegistered = false;
11
19
 
12
- const session = config.session || "default";
13
- const db = new config.Database(path.join(folder, "auth.db"));
20
+ const getDb = (folder, DatabaseCtor) => {
21
+ const dbPath = path.resolve(folder, "auth.db");
22
+ let db = dbPool.get(dbPath);
23
+ if (db) return db;
14
24
 
25
+ db = new DatabaseCtor(dbPath);
15
26
  db.pragma("foreign_keys = ON");
16
27
  db.pragma("journal_mode = WAL");
17
28
  db.pragma("synchronous = NORMAL");
@@ -19,6 +30,38 @@ export const usePrototypeAuthState = async (config = {}) => {
19
30
  db.pragma("cache_size = -128000");
20
31
  db.pragma("mmap_size = 524288000");
21
32
  db.pragma("busy_timeout = 5000");
33
+ dbPool.set(dbPath, db);
34
+
35
+ if (!exitHandlersRegistered) {
36
+ exitHandlersRegistered = true;
37
+ const closeAll = () => {
38
+ for (const conn of dbPool.values()) {
39
+ try {
40
+ conn.pragma("wal_checkpoint(TRUNCATE)");
41
+ conn.close();
42
+ } catch {}
43
+ }
44
+ };
45
+ process.once("SIGINT", () => {
46
+ closeAll();
47
+ process.exit(0);
48
+ });
49
+ process.once("SIGTERM", () => {
50
+ closeAll();
51
+ process.exit(0);
52
+ });
53
+ process.once("beforeExit", closeAll);
54
+ }
55
+
56
+ return db;
57
+ };
58
+
59
+ export const usePrototypeAuthState = async (config = {}) => {
60
+ const folder = config.folder || "./auth";
61
+ if (!fs.existsSync(folder)) fs.mkdirSync(folder, { recursive: true });
62
+
63
+ const session = config.session || "default";
64
+ const db = getDb(folder, config.Database);
22
65
 
23
66
  db.prepare(
24
67
  "CREATE TABLE IF NOT EXISTS baileys_metadata (name TEXT PRIMARY KEY)",
@@ -145,7 +145,11 @@ const MIXED_NATIVE_FLOW = {
145
145
  };
146
146
  export const getBizBinaryNode = (message, addBizAttributes) => {
147
147
  const bizAttributes = {};
148
- const flowMsg = message.interactiveMessage?.nativeFlowMessage;
148
+ const flowMsg =
149
+ message.interactiveMessage?.nativeFlowMessage ||
150
+ message.interactiveMessage?.carouselMessage?.cards?.find(
151
+ (card) => card?.nativeFlowMessage?.buttons?.length
152
+ )?.nativeFlowMessage;
149
153
  const firstButtonName = flowMsg?.buttons?.[0]?.name;
150
154
  const qualityContent = {
151
155
  tag: "quality_control",
@@ -199,4 +203,4 @@ export const getBizBinaryNode = (message, addBizAttributes) => {
199
203
  };
200
204
  }
201
205
  return { tag: "biz", attrs: bizAttributes, content: [qualityContent] };
202
- };
206
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@prototypevip/baileys",
3
- "version": "0.0.1",
3
+ "version": "0.0.3",
4
4
  "description": "A simple fork of Baileys for WhatsApp automation",
5
5
  "main": "lib/index.js",
6
6
  "type": "module",
@@ -45,6 +45,7 @@
45
45
  "@hapi/boom": "^9.1.3",
46
46
  "async-mutex": "^0.5.0",
47
47
  "fflate": "^0.8.2",
48
+ "fluent-ffmpeg": "^2.1.3",
48
49
  "libsignal": "github:WhiskeySockets/libsignal-wasm#master",
49
50
  "lru-cache": "^11.2.6",
50
51
  "music-metadata": "^11.7.0",