@manybot/manybot 5.2.2 → 5.2.5

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.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  ![ManyBot Logo](logo.png)
4
4
 
5
- ![Node.js 20+](https://img.shields.io/badge/Node.js-20+-339933?logo=node.js&logoColor=white)
5
+ ![Node.js 24+](https://img.shields.io/badge/Node.js-20+-339933?logo=node.js&logoColor=white)
6
6
  ![npm 9+](https://img.shields.io/badge/npm-9+-CB3837?logo=npm&logoColor=white)
7
7
  ![GPL v3](https://img.shields.io/badge/License-GPL--v3-blue.svg)
8
8
  ![Linux](https://img.shields.io/badge/Linux%20%7C%20Windows-lightgrey)
@@ -16,7 +16,7 @@ Open-source framework for message automation, extensible via community plugins.
16
16
 
17
17
  ## Requirements
18
18
 
19
- - Node.js >= 20
19
+ - Node.js >= 24.17.0
20
20
  - npm
21
21
 
22
22
  ## Getting started
package/dist/config.js CHANGED
@@ -21,6 +21,7 @@ import os from "os";
21
21
  import path from "path";
22
22
  import { parse as parseToml } from "smol-toml";
23
23
  import { logger } from "#logger";
24
+ import { t } from "#i18n";
24
25
  // ---------------------------------------------------------------------------
25
26
  // Paths
26
27
  // ---------------------------------------------------------------------------
@@ -208,13 +209,6 @@ PHONE_NUMBER = ""
208
209
  # Leave blank to choose interactively on first run — the choice is then
209
210
  # saved here automatically.
210
211
  LOGIN_METHOD = ""
211
-
212
- # JID of a single chat where the bot is allowed to respond to messages
213
- # sent by yourself (fromMe) — useful for testing commands without
214
- # affecting other conversations. In every other chat, fromMe messages
215
- # are always ignored.
216
- # Example: TEST_CHAT = "5511999999999@c.us"
217
- TEST_CHAT = ""
218
212
  `;
219
213
  const DEFAULT_TOML_PT = `# Arquivo de configuração do ManyBot
220
214
  # Veja https://manybot.org/docs/config para saber mais
@@ -230,12 +224,6 @@ PHONE_NUMBER = ""
230
224
  # PHONE_NUMBER). Deixe em branco para escolher interativamente na primeira
231
225
  # execução — a escolha é salva aqui automaticamente.
232
226
  LOGIN_METHOD = ""
233
-
234
- # JID de um único chat onde o bot pode responder a mensagens enviadas por
235
- # você mesmo (fromMe) — útil para testar comandos sem afetar outras
236
- # conversas. Em qualquer outro chat, mensagens fromMe são sempre ignoradas.
237
- # Exemplo: TEST_CHAT = "5511999999999@c.us"
238
- TEST_CHAT = ""
239
227
  `;
240
228
  const DEFAULT_TOML = detectSystemLang() === "pt" ? DEFAULT_TOML_PT : DEFAULT_TOML_EN;
241
229
  await fs.mkdir(CONFIG_DIR, { recursive: true });
@@ -261,8 +249,9 @@ async function loadToml(file, label) {
261
249
  }
262
250
  catch (e) {
263
251
  const err = e instanceof Error ? e : new Error(String(e));
264
- logger.warn(`Error parsing ${label}: ${err.message}`);
265
- return {};
252
+ logger.error(t("errors.invalid_config", { file: label, error: err.message }));
253
+ logger.error(t("errors.fix_config", { file: label }));
254
+ process.exit(1);
266
255
  }
267
256
  }
268
257
  tomlLayer = {
@@ -277,7 +266,6 @@ const DEFAULTS = {
277
266
  LANGUAGE: "en",
278
267
  PHONE_NUMBER: null,
279
268
  PLATFORM: "whatsapp",
280
- TEST_CHAT: null,
281
269
  LOGIN_METHOD: null,
282
270
  };
283
271
  function normalize(cfg) {
@@ -285,8 +273,6 @@ function normalize(cfg) {
285
273
  // can always do a simple truthiness check regardless of config source.
286
274
  if (cfg.PHONE_NUMBER === "")
287
275
  cfg.PHONE_NUMBER = null;
288
- if (cfg.TEST_CHAT === "")
289
- cfg.TEST_CHAT = null;
290
276
  // Anything other than "phone"/"qr" is treated as "not configured yet",
291
277
  // so a typo or leftover garbage value falls back to the interactive
292
278
  // prompt instead of silently misbehaving.
@@ -327,7 +313,6 @@ export const PLUGINS = CONFIG.PLUGINS;
327
313
  export const LANGUAGE = CONFIG.LANGUAGE;
328
314
  export const PHONE_NUMBER = CONFIG.PHONE_NUMBER;
329
315
  export const PLATFORM = CONFIG.PLATFORM;
330
- export const TEST_CHAT = CONFIG.TEST_CHAT;
331
316
  export const LOGIN_METHOD = CONFIG.LOGIN_METHOD;
332
317
  /**
333
318
  * Writes a single value back to manybot.toml without rewriting the whole
@@ -42,6 +42,8 @@ function getMsgType(msg) {
42
42
  return "unknown";
43
43
  if (m.conversation || m.extendedTextMessage)
44
44
  return "chat";
45
+ if (m.buttonsResponseMessage || m.listResponseMessage)
46
+ return "chat";
45
47
  if (m.imageMessage)
46
48
  return "image";
47
49
  if (m.videoMessage)
@@ -56,6 +58,14 @@ function getMsgType(msg) {
56
58
  m.pollCreationMessageV2 ||
57
59
  m.pollCreationMessageV3)
58
60
  return "poll";
61
+ if (m.locationMessage || m.liveLocationMessage)
62
+ return "location";
63
+ if (m.contactMessage)
64
+ return "vcard";
65
+ if (m.contactsArrayMessage)
66
+ return "multi_vcard";
67
+ if (m.protocolMessage?.type === 0)
68
+ return "revoked"; // REVOKE
59
69
  return "unknown";
60
70
  }
61
71
  function msgHasMedia(msg) {
@@ -98,6 +108,29 @@ function getMsgMimetype(msg) {
98
108
  // on every single incoming message from the same group.
99
109
  const GROUP_NAME_CACHE_TTL_MS = 5 * 60 * 1000;
100
110
  const groupNameCache = new Map();
111
+ const GROUP_META_CACHE_TTL_MS = 5 * 60 * 1000;
112
+ const groupMetaCache = new Map();
113
+ async function getGroupMetadataCached(sock, jid) {
114
+ const cached = groupMetaCache.get(jid);
115
+ if (cached && Date.now() - cached.at < GROUP_META_CACHE_TTL_MS)
116
+ return cached.meta;
117
+ const meta = await sock.groupMetadata(jid);
118
+ groupMetaCache.set(jid, { meta, at: Date.now() });
119
+ return meta;
120
+ }
121
+ let groupMetaInvalidationBound = false;
122
+ function bindGroupMetaInvalidation(sock) {
123
+ if (groupMetaInvalidationBound)
124
+ return;
125
+ groupMetaInvalidationBound = true;
126
+ const ev = sock.ev;
127
+ ev.on("group-participants.update", (u) => groupMetaCache.delete(u.id));
128
+ ev.on("groups.update", (updates) => {
129
+ for (const u of updates)
130
+ if (u.id)
131
+ groupMetaCache.delete(u.id);
132
+ });
133
+ }
101
134
  /**
102
135
  * Build a WAChat adapter from a Baileys message + store.
103
136
  * Exposed for use in messageHandler.ts.
@@ -122,7 +155,7 @@ export async function buildChatFromMsg(msg, store, sock) {
122
155
  }
123
156
  else {
124
157
  try {
125
- const meta = await sock.groupMetadata(rawJid);
158
+ const meta = await getGroupMetadataCached(sock, rawJid);
126
159
  if (meta?.subject) {
127
160
  name = meta.subject;
128
161
  groupNameCache.set(rawJid, { name: meta.subject, at: Date.now() });
@@ -311,6 +344,12 @@ async function normalizeContact(jid, info, botJid, sock) {
311
344
  isWAAccount = false;
312
345
  }
313
346
  }
347
+ // No store record and no confirmed WhatsApp account (and not a group,
348
+ // which we can't verify this way) — nothing backs this contact.
349
+ // Matches the old whatsapp-web.js contract: getContactById() threw /
350
+ // resolved to null for an unknown ID instead of returning a hollow object.
351
+ if (!jid.endsWith("@g.us") && !isWAAccount)
352
+ return null;
314
353
  if (sock && !jid.endsWith("@g.us")) {
315
354
  try {
316
355
  isBusiness = Boolean(await sock.getBusinessProfile(jid));
@@ -485,7 +524,9 @@ export function buildMessageContext(msg, sock, store, guardOptions = {}) {
485
524
  },
486
525
  hasReply: !!(contextInfo?.quotedMessage),
487
526
  async getReply() {
488
- return quotedRaw;
527
+ if (!quotedRaw)
528
+ return null;
529
+ return buildMessageContext(quotedRaw, sock, store, { cooldown: false, jitter: false });
489
530
  },
490
531
  reply: makeSender(sock, store, rawJid, msg, { cooldown, jitter }),
491
532
  async react(emoji) {
@@ -500,6 +541,10 @@ export function buildMessageContext(msg, sock, store, guardOptions = {}) {
500
541
  logger.warn("[pluginApi] pin() is not supported with Baileys");
501
542
  },
502
543
  hasPrefix,
544
+ /**
545
+ * Normalized contact of the message sender.
546
+ * @returns {Promise<object|null>} null if the sender can't be confirmed as a real WhatsApp account.
547
+ */
503
548
  async getContact() {
504
549
  const info = store.contacts[sender]
505
550
  ?? store.contacts[store.resolveJid(msg.key.participant ?? "")];
@@ -1126,6 +1171,7 @@ function buildBaseApi(sock, store, pluginRegistry, pluginName) {
1126
1171
  * @param {string} pluginName
1127
1172
  */
1128
1173
  export function buildSetupApi(sock, store, pluginRegistry, pluginName) {
1174
+ bindGroupMetaInvalidation(sock);
1129
1175
  return {
1130
1176
  ...buildBaseApi(sock, store, pluginRegistry, pluginName),
1131
1177
  ...buildSetupSendApi(sock, store),
@@ -1161,6 +1207,7 @@ export function buildApi({ msg, chat, sock, store, pluginRegistry, pluginName, g
1161
1207
  const sender = getMsgSender(msg, store);
1162
1208
  const cooldown = (guardOptions.cooldown ?? true);
1163
1209
  const jitter = (guardOptions.jitter ?? true);
1210
+ bindGroupMetaInvalidation(sock);
1164
1211
  // Sender for quoted messages
1165
1212
  const contextInfo = getContextInfo(msg);
1166
1213
  const quotedRaw = contextInfo?.quotedMessage
@@ -1213,7 +1260,7 @@ export function buildApi({ msg, chat, sock, store, pluginRegistry, pluginName, g
1213
1260
  if (!chat.isGroup)
1214
1261
  return [];
1215
1262
  try {
1216
- const meta = await sock.groupMetadata(rawJid);
1263
+ const meta = await getGroupMetadataCached(sock, rawJid);
1217
1264
  return meta.participants.map(p => ({
1218
1265
  id: normalizeJid(p.id),
1219
1266
  isAdmin: p.admin === "admin" || p.admin === "superadmin",
@@ -1233,7 +1280,7 @@ export function buildApi({ msg, chat, sock, store, pluginRegistry, pluginName, g
1233
1280
  if (!chat.isGroup)
1234
1281
  return false;
1235
1282
  try {
1236
- const meta = await sock.groupMetadata(rawJid);
1283
+ const meta = await getGroupMetadataCached(sock, rawJid);
1237
1284
  return meta.participants.some(p => matchesParticipant([contactId], p.id) && (p.admin === "admin" || p.admin === "superadmin"));
1238
1285
  }
1239
1286
  catch {
@@ -1248,7 +1295,7 @@ export function buildApi({ msg, chat, sock, store, pluginRegistry, pluginName, g
1248
1295
  if (!chat.isGroup)
1249
1296
  return false;
1250
1297
  try {
1251
- const meta = await sock.groupMetadata(rawJid);
1298
+ const meta = await getGroupMetadataCached(sock, rawJid);
1252
1299
  const rawSenderParticipant = msg.key.participant ?? msg.key.remoteJid ?? "";
1253
1300
  return meta.participants.some(p => matchesParticipant([sender, rawSenderParticipant], p.id) && (p.admin === "admin" || p.admin === "superadmin"));
1254
1301
  }
@@ -1268,7 +1315,7 @@ export function buildApi({ msg, chat, sock, store, pluginRegistry, pluginName, g
1268
1315
  if (!botCandidates.some(Boolean))
1269
1316
  return false;
1270
1317
  try {
1271
- const meta = await sock.groupMetadata(rawJid);
1318
+ const meta = await getGroupMetadataCached(sock, rawJid);
1272
1319
  return meta.participants.some(p => matchesParticipant(botCandidates, p.id) && (p.admin === "admin" || p.admin === "superadmin"));
1273
1320
  }
1274
1321
  catch {
@@ -123,9 +123,9 @@ export const whatsappDriver = {
123
123
  * it's your own message or someone else's — prints the normalized
124
124
  * JID and the chat name (if any), and exits.
125
125
  *
126
- * Intentionally does not go through the CHATS/fromMe/dedup filters of
126
+ * Intentionally does not go through the CHATS/dedup filters of
127
127
  * handleMessage: the only goal here is to discover the JID so you can
128
- * configure CHATS/TEST_CHAT afterward, so there's no reason to filter
128
+ * configure CHATS afterward, so there's no reason to filter
129
129
  * anything out yet.
130
130
  */
131
131
  async getId() {
@@ -151,7 +151,7 @@ export const whatsappDriver = {
151
151
  logger.success(`[getid] JID: ${jid}`);
152
152
  if (name)
153
153
  logger.info(`[getid] Chat/sender: ${name}`);
154
- logger.info("[getid] Paste this value into CHATS or TEST_CHAT in manybot.toml.");
154
+ logger.info("[getid] Paste this value into CHATS in manybot.toml.");
155
155
  resolve();
156
156
  });
157
157
  });
@@ -11,7 +11,7 @@
11
11
  *
12
12
  * Each plugin decides whether to act or ignore.
13
13
  */
14
- import { CHATS, TEST_CHAT } from "#config";
14
+ import { CHATS } from "#config";
15
15
  import { buildApi, buildChatFromMsg } from "./api/index.js";
16
16
  import { pluginRegistry } from "#kernel/pluginLoader.js";
17
17
  import { runPlugin } from "#kernel/pluginGuard.js";
@@ -58,10 +58,6 @@ export async function handleMessage(msg, sock, store) {
58
58
  if (CHATS.length > 0 && !CHATS.includes(jid)) {
59
59
  return;
60
60
  }
61
- const isTestChat = !!TEST_CHAT && jid === normalizeJid(TEST_CHAT);
62
- if (msg.key.fromMe && !isTestChat) {
63
- return;
64
- }
65
61
  if (alreadyProcessed(msg.key.id)) {
66
62
  return;
67
63
  }
@@ -42,14 +42,41 @@ function loadLocale(lang) {
42
42
  }
43
43
  }
44
44
  /**
45
- * Gets configured language or default
45
+ * Detects the OS locale without depending on a single env var, since LANG
46
+ * isn't reliably set on macOS GUI sessions or Windows. Used as a fallback
47
+ * when CONFIG.LANGUAGE isn't available yet (e.g. circular import during
48
+ * config bootstrap) or isn't set.
49
+ */
50
+ function detectSystemLang() {
51
+ try {
52
+ const locale = Intl.DateTimeFormat().resolvedOptions().locale;
53
+ if (locale)
54
+ return locale.split("-")[0].toLowerCase();
55
+ }
56
+ catch {
57
+ // Intl unavailable — fall through to env vars
58
+ }
59
+ const envLocale = process.env.LC_ALL || process.env.LC_MESSAGES || process.env.LANG || process.env.LANGUAGE;
60
+ if (envLocale)
61
+ return envLocale.split(/[_.]/)[0].toLowerCase();
62
+ return DEFAULT_LANG;
63
+ }
64
+ /**
65
+ * Gets configured language or falls back to system locale, then English.
46
66
  * @returns {string}
47
67
  */
48
68
  function getConfiguredLang() {
49
- const lang = CONFIG.LANGUAGE?.trim().toLowerCase();
50
- if (!lang)
51
- return DEFAULT_LANG;
52
- // Check if file exists
69
+ let lang;
70
+ try {
71
+ lang = CONFIG.LANGUAGE?.trim().toLowerCase();
72
+ }
73
+ catch {
74
+ // CONFIG not initialized yet (e.g. this module was pulled in via a
75
+ // circular import while #config is still bootstrapping)
76
+ }
77
+ if (!lang) {
78
+ lang = detectSystemLang();
79
+ }
53
80
  const filePath = path.join(LOCALES_DIR, `${lang}.json`);
54
81
  if (!fs.existsSync(filePath)) {
55
82
  console.warn(`[i18n] Language "${lang}" not found, falling back to "${DEFAULT_LANG}"`);
@@ -20,7 +20,7 @@
20
20
  * }
21
21
  */
22
22
  import cron from "node-cron";
23
- import Database from "better-sqlite3";
23
+ import { DatabaseSync } from "node:sqlite";
24
24
  import path from "path";
25
25
  import { mkdirSync } from "fs";
26
26
  import { logger } from "#logger";
@@ -30,8 +30,8 @@ import { CONFIG_DIR } from "#config";
30
30
  const tasks = new Map();
31
31
  // ── Persistence (metadata only — fn can't be serialized) ────────────────────
32
32
  mkdirSync(CONFIG_DIR, { recursive: true });
33
- const db = new Database(path.join(CONFIG_DIR, "scheduler.db"));
34
- db.pragma("journal_mode = WAL");
33
+ const db = new DatabaseSync(path.join(CONFIG_DIR, "scheduler.db"));
34
+ db.exec("PRAGMA journal_mode = WAL");
35
35
  db.exec(`
36
36
  CREATE TABLE IF NOT EXISTS scheduled_tasks (
37
37
  plugin_name TEXT NOT NULL,
@@ -10,16 +10,16 @@
10
10
  *
11
11
  * Plugins never touch the DB directly — only through buildSettingsApi().
12
12
  */
13
- import Database from "better-sqlite3";
13
+ import { DatabaseSync } from "node:sqlite";
14
14
  import path from "path";
15
15
  import { mkdirSync } from "fs";
16
16
  import { CONFIG_DIR } from "#config";
17
17
  // ── DB init ───────────────────────────────────────────────────────────────────
18
18
  const DB_PATH = path.join(CONFIG_DIR, "settings.db");
19
19
  mkdirSync(path.dirname(DB_PATH), { recursive: true });
20
- const db = new Database(DB_PATH);
21
- db.pragma("journal_mode = WAL");
22
- db.pragma("foreign_keys = ON");
20
+ const db = new DatabaseSync(DB_PATH);
21
+ db.exec("PRAGMA journal_mode = WAL");
22
+ db.exec("PRAGMA foreign_keys = ON");
23
23
  db.exec(`
24
24
  CREATE TABLE IF NOT EXISTS plugin_settings (
25
25
  plugin_name TEXT NOT NULL,
@@ -34,7 +34,9 @@
34
34
  "sessionExpired": "Session expired or logged out — removing local session and restarting..."
35
35
  },
36
36
  "errors": {
37
- "stack": "Stack"
37
+ "stack": "Stack",
38
+ "invalid_config": "Invalid config file {{file}}: {{error}}",
39
+ "fix_config": "Fix the syntax in {{file}} before starting the bot."
38
40
  },
39
41
  "onboarding": {
40
42
  "intro": "ManyBot — first login",
@@ -34,7 +34,9 @@
34
34
  "sessionExpired": "Sesión expirada o cerrada — eliminando sesión local y reiniciando..."
35
35
  },
36
36
  "errors": {
37
- "stack": "Stack"
37
+ "stack": "Stack",
38
+ "invalid_config": "Archivo de configuración inválido {{file}}: {{error}}",
39
+ "fix_config": "Corrige la sintaxis en {{file}} antes de iniciar el bot."
38
40
  },
39
41
  "onboarding": {
40
42
  "intro": "ManyBot — primer inicio de sesión",
@@ -34,7 +34,9 @@
34
34
  "sessionExpired": "Sessão expirada ou desconectada — removendo sessão local e reiniciando..."
35
35
  },
36
36
  "errors": {
37
- "stack": "Stack"
37
+ "stack": "Stack",
38
+ "invalid_config": "Arquivo de configuração inválido {{file}}: {{error}}",
39
+ "fix_config": "Corrija a sintaxe em {{file}} antes de iniciar o bot."
38
40
  },
39
41
  "onboarding": {
40
42
  "intro": "ManyBot — primeiro login",
package/dist/main.js CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env node
1
2
  /**
2
3
  * main.ts
3
4
  *
@@ -54,7 +55,7 @@ process.on("SIGINT", () => shutdown("SIGINT"));
54
55
  // ── --getid mode (provisional) ───────────────────────────────────────────
55
56
  // Usage: npm run start -- --getid
56
57
  // Connects, waits for the next message to arrive from any chat, and prints
57
- // the JID to the console, to paste into CHATS/TEST_CHAT in manybot.toml.
58
+ // the JID to the console, to paste into CHATS in manybot.toml.
58
59
  // Does not enter the normal bot flow (plugins are not loaded).
59
60
  if (process.argv.includes("--getid")) {
60
61
  if (!activeDriver.getId) {
package/package.json CHANGED
@@ -5,11 +5,11 @@
5
5
  "name": "SyntaxError!",
6
6
  "email": "me@stxerr.dev"
7
7
  },
8
- "version": "5.2.2",
8
+ "version": "5.2.5",
9
9
  "license": "GPL-3.0-only",
10
10
  "private": false,
11
11
  "engines": {
12
- "node": ">=20"
12
+ "node": ">=24.17.0"
13
13
  },
14
14
  "repository": {
15
15
  "type": "git",
@@ -30,16 +30,14 @@
30
30
  "typecheck": "tsc --noEmit"
31
31
  },
32
32
  "devDependencies": {
33
- "@types/better-sqlite3": "^7.6.12",
34
33
  "@types/node": "^22.0.0",
35
34
  "tsx": "^4.19.2",
36
35
  "typescript": "^5.7.3"
37
36
  },
38
37
  "dependencies": {
39
- "@clack/prompts": "^0.10.0",
38
+ "@clack/prompts": "^0.10.1",
40
39
  "@hapi/boom": "^10.0.1",
41
40
  "@whiskeysockets/baileys": "^6.7.23",
42
- "better-sqlite3": "^12.11.1",
43
41
  "node-cron": "^4.6.0",
44
42
  "node-webpmux": "^3.2.1",
45
43
  "pino": "^10.3.1",