alvin-bot 5.6.2 → 5.8.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.
- package/CHANGELOG.md +29 -0
- package/README.md +1 -1
- package/dist/claude.js +1 -102
- package/dist/config.js +1 -96
- package/dist/engine.js +1 -90
- package/dist/find-claude-binary.js +1 -98
- package/dist/handlers/async-agent-chunk-handler.js +1 -50
- package/dist/handlers/background-bypass.js +1 -75
- package/dist/handlers/commands.js +1 -2336
- package/dist/handlers/cron-progress.js +1 -52
- package/dist/handlers/document.js +1 -194
- package/dist/handlers/message.js +1 -959
- package/dist/handlers/photo.js +1 -154
- package/dist/handlers/platform-message.js +1 -360
- package/dist/handlers/stuck-timer.js +1 -54
- package/dist/handlers/video.js +1 -237
- package/dist/handlers/voice.js +1 -148
- package/dist/i18n.js +1 -805
- package/dist/index.js +1 -697
- package/dist/init-data-dir.js +1 -98
- package/dist/middleware/auth.js +1 -233
- package/dist/migrate.js +1 -162
- package/dist/paths.js +1 -146
- package/dist/platforms/discord.js +1 -175
- package/dist/platforms/index.js +1 -130
- package/dist/platforms/signal.js +1 -205
- package/dist/platforms/slack-slash-parser.js +1 -32
- package/dist/platforms/slack.js +1 -501
- package/dist/platforms/telegram.js +1 -111
- package/dist/platforms/types.js +1 -8
- package/dist/platforms/whatsapp-auth-helpers.js +1 -53
- package/dist/platforms/whatsapp.js +1 -707
- package/dist/providers/claude-sdk-provider.js +1 -565
- package/dist/providers/codex-cli-provider.js +1 -134
- package/dist/providers/index.js +1 -7
- package/dist/providers/ollama-provider.js +1 -32
- package/dist/providers/openai-compatible.js +1 -406
- package/dist/providers/registry.js +1 -352
- package/dist/providers/runtime-header.js +1 -45
- package/dist/providers/tool-executor.js +1 -475
- package/dist/providers/types.js +1 -227
- package/dist/services/access.js +1 -144
- package/dist/services/allowed-users-gate.js +1 -56
- package/dist/services/alvin-dispatch.js +1 -130
- package/dist/services/alvin-mcp-tools.js +1 -104
- package/dist/services/asset-index.js +1 -224
- package/dist/services/async-agent-parser.js +1 -418
- package/dist/services/async-agent-watcher.js +1 -443
- package/dist/services/auto-diagnostic.js +1 -228
- package/dist/services/broadcast.js +1 -52
- package/dist/services/browser-manager.js +1 -562
- package/dist/services/browser-webfetch.js +1 -127
- package/dist/services/browser.js +1 -121
- package/dist/services/cdp-bootstrap.js +1 -357
- package/dist/services/compaction.js +1 -144
- package/dist/services/critical-notify.js +1 -203
- package/dist/services/cron-resolver.js +1 -58
- package/dist/services/cron-scheduling.js +1 -310
- package/dist/services/cron.js +1 -861
- package/dist/services/custom-tools.js +1 -317
- package/dist/services/delivery-queue.js +1 -173
- package/dist/services/delivery-registry.js +1 -21
- package/dist/services/disk-cleanup.js +1 -203
- package/dist/services/elevenlabs.js +1 -58
- package/dist/services/embeddings/auto-detect.js +1 -74
- package/dist/services/embeddings/fts5.js +1 -108
- package/dist/services/embeddings/gemini.js +1 -65
- package/dist/services/embeddings/index.js +1 -496
- package/dist/services/embeddings/ollama.js +1 -78
- package/dist/services/embeddings/openai.js +1 -49
- package/dist/services/embeddings/provider.js +1 -22
- package/dist/services/embeddings/vector-base.js +1 -113
- package/dist/services/embeddings-migration.js +1 -193
- package/dist/services/embeddings.js +1 -9
- package/dist/services/env-file.js +1 -50
- package/dist/services/exec-guard.js +1 -71
- package/dist/services/fallback-order.js +1 -154
- package/dist/services/file-permissions.js +1 -93
- package/dist/services/heartbeat-file.js +1 -65
- package/dist/services/heartbeat.js +1 -313
- package/dist/services/hooks.js +1 -44
- package/dist/services/imagegen.js +1 -72
- package/dist/services/language-detect.js +1 -154
- package/dist/services/markdown.js +1 -63
- package/dist/services/mcp.js +1 -263
- package/dist/services/memory-extractor.js +1 -178
- package/dist/services/memory-inject-mode.js +1 -43
- package/dist/services/memory-layers.js +1 -156
- package/dist/services/memory.js +1 -146
- package/dist/services/ollama-manager.js +1 -339
- package/dist/services/permissions-wizard.js +1 -291
- package/dist/services/personality.js +1 -376
- package/dist/services/plugins.js +1 -171
- package/dist/services/preflight.js +1 -292
- package/dist/services/process-manager.js +1 -291
- package/dist/services/release-highlights.js +1 -79
- package/dist/services/reminders.js +1 -97
- package/dist/services/restart.js +1 -48
- package/dist/services/security-audit.js +1 -74
- package/dist/services/self-diagnosis.js +1 -272
- package/dist/services/self-search.js +1 -129
- package/dist/services/session-persistence.js +1 -237
- package/dist/services/session.js +1 -282
- package/dist/services/skills.js +1 -290
- package/dist/services/ssrf-guard.js +1 -162
- package/dist/services/standing-orders.js +1 -29
- package/dist/services/steer-channel.js +1 -46
- package/dist/services/stop-controller.js +1 -52
- package/dist/services/subagent-dedup.js +1 -0
- package/dist/services/subagent-delivery.js +1 -452
- package/dist/services/subagent-stats.js +1 -123
- package/dist/services/subagents.js +1 -814
- package/dist/services/sudo.js +1 -329
- package/dist/services/telegram.js +1 -158
- package/dist/services/timing-safe-bearer.js +1 -51
- package/dist/services/tool-discovery.js +1 -214
- package/dist/services/trends.js +1 -580
- package/dist/services/updater.js +1 -291
- package/dist/services/usage-tracker.js +1 -144
- package/dist/services/users.js +1 -271
- package/dist/services/voice.js +1 -104
- package/dist/services/watchdog-brake.js +1 -154
- package/dist/services/watchdog.js +1 -311
- package/dist/services/workspaces.js +1 -276
- package/dist/tui/index.js +1 -667
- package/dist/util/console-formatter.js +1 -109
- package/dist/util/debounce.js +1 -24
- package/dist/util/telegram-error-filter.js +1 -62
- package/dist/version.js +1 -24
- package/dist/web/bind-strategy.js +1 -42
- package/dist/web/canvas.js +1 -30
- package/dist/web/doctor-api.js +1 -604
- package/dist/web/openai-compat.js +1 -252
- package/dist/web/server.js +1 -1831
- package/dist/web/setup-api.js +1 -1101
- package/package.json +5 -2
- package/dist/.metadata_never_index +0 -0
|
@@ -1,707 +1 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* WhatsApp Platform Adapter — Baileys Edition
|
|
3
|
-
*
|
|
4
|
-
* Uses @whiskeysockets/baileys (pure WebSocket, no Puppeteer/Chrome).
|
|
5
|
-
* Optional dependency — only loaded if WHATSAPP_ENABLED=true.
|
|
6
|
-
*
|
|
7
|
-
* Features:
|
|
8
|
-
* - Self-chat (Note to Self) as AI notepad
|
|
9
|
-
* - Group chat with per-group + per-contact whitelist
|
|
10
|
-
* - Voice/audio transcription, photo/document processing
|
|
11
|
-
* - Persistent auth via multi-file auth state
|
|
12
|
-
* - Auto-reconnect with backoff
|
|
13
|
-
*
|
|
14
|
-
* Setup:
|
|
15
|
-
* 1. Set WHATSAPP_ENABLED=true in .env (or via Web UI → Platforms)
|
|
16
|
-
* 2. Open Web UI → Platforms → scan the QR code with your phone
|
|
17
|
-
* 3. Start chatting in your "Saved Messages" / self-chat
|
|
18
|
-
*/
|
|
19
|
-
import fs from "fs";
|
|
20
|
-
import { dirname, join } from "path";
|
|
21
|
-
import { WHATSAPP_AUTH as AUTH_DIR, WA_GROUPS as GROUP_CONFIG_FILE, WA_MEDIA_DIR } from "../paths.js";
|
|
22
|
-
import { makeResilientSaveCreds } from "./whatsapp-auth-helpers.js";
|
|
23
|
-
function loadGroupConfig() {
|
|
24
|
-
try {
|
|
25
|
-
return JSON.parse(fs.readFileSync(GROUP_CONFIG_FILE, "utf-8"));
|
|
26
|
-
}
|
|
27
|
-
catch {
|
|
28
|
-
return { groups: [] };
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
function saveGroupConfig(config) {
|
|
32
|
-
const dir = dirname(GROUP_CONFIG_FILE);
|
|
33
|
-
if (!fs.existsSync(dir))
|
|
34
|
-
fs.mkdirSync(dir, { recursive: true });
|
|
35
|
-
fs.writeFileSync(GROUP_CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
36
|
-
}
|
|
37
|
-
export function getGroupRule(groupId) {
|
|
38
|
-
return loadGroupConfig().groups.find(g => g.groupId === groupId);
|
|
39
|
-
}
|
|
40
|
-
export function getGroupRules() {
|
|
41
|
-
return loadGroupConfig().groups;
|
|
42
|
-
}
|
|
43
|
-
export function upsertGroupRule(rule) {
|
|
44
|
-
const config = loadGroupConfig();
|
|
45
|
-
const existing = config.groups.find(g => g.groupId === rule.groupId);
|
|
46
|
-
if (existing) {
|
|
47
|
-
Object.assign(existing, rule, { updatedAt: Date.now() });
|
|
48
|
-
saveGroupConfig(config);
|
|
49
|
-
return existing;
|
|
50
|
-
}
|
|
51
|
-
const newRule = {
|
|
52
|
-
groupId: rule.groupId,
|
|
53
|
-
groupName: rule.groupName || "Unknown Group",
|
|
54
|
-
enabled: rule.enabled ?? false,
|
|
55
|
-
allowedParticipants: rule.allowedParticipants || [],
|
|
56
|
-
participantNames: rule.participantNames || {},
|
|
57
|
-
requireMention: rule.requireMention ?? true,
|
|
58
|
-
allowMedia: rule.allowMedia ?? true,
|
|
59
|
-
requireApproval: rule.requireApproval ?? true,
|
|
60
|
-
updatedAt: Date.now(),
|
|
61
|
-
};
|
|
62
|
-
config.groups.push(newRule);
|
|
63
|
-
saveGroupConfig(config);
|
|
64
|
-
return newRule;
|
|
65
|
-
}
|
|
66
|
-
export function deleteGroupRule(groupId) {
|
|
67
|
-
const config = loadGroupConfig();
|
|
68
|
-
const before = config.groups.length;
|
|
69
|
-
config.groups = config.groups.filter(g => g.groupId !== groupId);
|
|
70
|
-
if (config.groups.length < before) {
|
|
71
|
-
saveGroupConfig(config);
|
|
72
|
-
return true;
|
|
73
|
-
}
|
|
74
|
-
return false;
|
|
75
|
-
}
|
|
76
|
-
const _pendingApprovals = new Map();
|
|
77
|
-
let _approvalRequestFn = null;
|
|
78
|
-
export function setApprovalRequestFn(fn) {
|
|
79
|
-
_approvalRequestFn = fn;
|
|
80
|
-
}
|
|
81
|
-
export function getPendingApproval(id) {
|
|
82
|
-
return _pendingApprovals.get(id);
|
|
83
|
-
}
|
|
84
|
-
export function removePendingApproval(id) {
|
|
85
|
-
const p = _pendingApprovals.get(id);
|
|
86
|
-
_pendingApprovals.delete(id);
|
|
87
|
-
return p;
|
|
88
|
-
}
|
|
89
|
-
export function getPendingApprovals() {
|
|
90
|
-
return Array.from(_pendingApprovals.values());
|
|
91
|
-
}
|
|
92
|
-
let _approvalChannel = "telegram";
|
|
93
|
-
export function getApprovalChannel() {
|
|
94
|
-
return _approvalChannel;
|
|
95
|
-
}
|
|
96
|
-
export function setApprovalChannel(channel) {
|
|
97
|
-
_approvalChannel = channel;
|
|
98
|
-
}
|
|
99
|
-
export function matchApprovalResponse(text) {
|
|
100
|
-
const t = text.trim().toLowerCase();
|
|
101
|
-
const entries = Array.from(_pendingApprovals.entries());
|
|
102
|
-
if (entries.length === 0)
|
|
103
|
-
return null;
|
|
104
|
-
const approveWords = ["ok", "ja", "yes", "go", "1", "approve"];
|
|
105
|
-
const denyWords = ["nein", "no", "nope", "2", "ablehnen", "deny", "stop"];
|
|
106
|
-
for (const [id] of entries) {
|
|
107
|
-
if (t.includes(id)) {
|
|
108
|
-
const isApprove = approveWords.some(w => t.includes(w));
|
|
109
|
-
return { id, approved: isApprove };
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const [latestId] = entries[entries.length - 1];
|
|
113
|
-
if (approveWords.some(w => t === w || t.startsWith(w + " "))) {
|
|
114
|
-
return { id: latestId, approved: true };
|
|
115
|
-
}
|
|
116
|
-
if (denyWords.some(w => t === w || t.startsWith(w + " "))) {
|
|
117
|
-
return { id: latestId, approved: false };
|
|
118
|
-
}
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
function cleanupStaleApprovals() {
|
|
122
|
-
const cutoff = Date.now() - 30 * 60_000;
|
|
123
|
-
for (const [id, p] of _pendingApprovals) {
|
|
124
|
-
if (p.timestamp < cutoff) {
|
|
125
|
-
_pendingApprovals.delete(id);
|
|
126
|
-
if (p.incoming.media?.path)
|
|
127
|
-
fs.unlink(p.incoming.media.path, () => { });
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
setInterval(cleanupStaleApprovals, 5 * 60_000);
|
|
132
|
-
let _whatsappState = {
|
|
133
|
-
status: "disconnected",
|
|
134
|
-
qrString: null,
|
|
135
|
-
qrTimestamp: null,
|
|
136
|
-
connectedAt: null,
|
|
137
|
-
error: null,
|
|
138
|
-
info: null,
|
|
139
|
-
};
|
|
140
|
-
export function getWhatsAppState() {
|
|
141
|
-
return { ..._whatsappState };
|
|
142
|
-
}
|
|
143
|
-
// ── JID Helpers & Contact Cache ────────────────────────────────────────────
|
|
144
|
-
function normalizeJid(jid) {
|
|
145
|
-
return jid.replace(/:.*@/, "@");
|
|
146
|
-
}
|
|
147
|
-
/** In-memory contact name cache: JID → display name. Populated from incoming messages. */
|
|
148
|
-
const _contactNames = new Map();
|
|
149
|
-
/** Persist contact cache to disk for survival across restarts */
|
|
150
|
-
const CONTACT_CACHE_FILE = join(AUTH_DIR, "contact-names.json");
|
|
151
|
-
function loadContactCache() {
|
|
152
|
-
try {
|
|
153
|
-
const data = JSON.parse(fs.readFileSync(CONTACT_CACHE_FILE, "utf-8"));
|
|
154
|
-
for (const [k, v] of Object.entries(data)) {
|
|
155
|
-
_contactNames.set(k, v);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
catch { /* first run */ }
|
|
159
|
-
}
|
|
160
|
-
function saveContactCache() {
|
|
161
|
-
try {
|
|
162
|
-
if (!fs.existsSync(AUTH_DIR))
|
|
163
|
-
fs.mkdirSync(AUTH_DIR, { recursive: true });
|
|
164
|
-
fs.writeFileSync(CONTACT_CACHE_FILE, JSON.stringify(Object.fromEntries(_contactNames), null, 2));
|
|
165
|
-
}
|
|
166
|
-
catch { /* non-critical */ }
|
|
167
|
-
}
|
|
168
|
-
/** Remember a contact's display name */
|
|
169
|
-
function cacheContactName(jid, name) {
|
|
170
|
-
if (!name || name === jid)
|
|
171
|
-
return;
|
|
172
|
-
const normalized = normalizeJid(jid);
|
|
173
|
-
if (_contactNames.get(normalized) !== name) {
|
|
174
|
-
_contactNames.set(normalized, name);
|
|
175
|
-
saveContactCache();
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
/** Get a contact's display name (cached push name > phone number > raw JID) */
|
|
179
|
-
export function getContactDisplayName(jid) {
|
|
180
|
-
const normalized = normalizeJid(jid);
|
|
181
|
-
const cached = _contactNames.get(normalized);
|
|
182
|
-
if (cached)
|
|
183
|
-
return cached;
|
|
184
|
-
// If it's a LID (no phone number embedded), show as-is
|
|
185
|
-
if (jid.includes("@lid"))
|
|
186
|
-
return jid.replace(/@lid$/, "");
|
|
187
|
-
// Otherwise extract phone number
|
|
188
|
-
const num = jidToNumber(jid);
|
|
189
|
-
return num.startsWith("49") ? `+${num}` : num || jid;
|
|
190
|
-
}
|
|
191
|
-
// Load cache at module init
|
|
192
|
-
loadContactCache();
|
|
193
|
-
function jidToNumber(jid) {
|
|
194
|
-
return jid.replace(/@.*$/, "").replace(/:.*$/, "");
|
|
195
|
-
}
|
|
196
|
-
// ── Adapter ────────────────────────────────────────────────────────────────
|
|
197
|
-
let _adapterInstance = null;
|
|
198
|
-
export function getWhatsAppAdapter() {
|
|
199
|
-
return _adapterInstance;
|
|
200
|
-
}
|
|
201
|
-
export class WhatsAppAdapter {
|
|
202
|
-
platform = "whatsapp";
|
|
203
|
-
handler = null;
|
|
204
|
-
sock = null;
|
|
205
|
-
// Loop prevention
|
|
206
|
-
botSentIds = new Set();
|
|
207
|
-
botSentTexts = new Set();
|
|
208
|
-
// Reconnect state
|
|
209
|
-
reconnectAttempt = 0;
|
|
210
|
-
maxReconnectAttempts = 10;
|
|
211
|
-
constructor() {
|
|
212
|
-
_adapterInstance = this;
|
|
213
|
-
}
|
|
214
|
-
async start() {
|
|
215
|
-
_whatsappState = {
|
|
216
|
-
status: "connecting", qrString: null, qrTimestamp: null,
|
|
217
|
-
connectedAt: null, error: null, info: null,
|
|
218
|
-
};
|
|
219
|
-
await this.connect();
|
|
220
|
-
// v4.14 — Register with the delivery registry so the async-agent
|
|
221
|
-
// watcher can deliver background sub-agent results back to WhatsApp.
|
|
222
|
-
try {
|
|
223
|
-
const { registerDeliveryAdapter } = await import("../services/delivery-registry.js");
|
|
224
|
-
registerDeliveryAdapter({
|
|
225
|
-
platform: "whatsapp",
|
|
226
|
-
sendText: async (chatId, text) => {
|
|
227
|
-
await this.sendText(String(chatId), text);
|
|
228
|
-
},
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
catch (err) {
|
|
232
|
-
console.warn("[whatsapp] failed to register delivery adapter:", err);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
async connect() {
|
|
236
|
-
let baileys;
|
|
237
|
-
try {
|
|
238
|
-
baileys = await import("@whiskeysockets/baileys");
|
|
239
|
-
}
|
|
240
|
-
catch {
|
|
241
|
-
const msg = "@whiskeysockets/baileys not installed. Run: npm install @whiskeysockets/baileys";
|
|
242
|
-
_whatsappState = { ..._whatsappState, status: "error", error: msg };
|
|
243
|
-
console.error(`\u274C WhatsApp: ${msg}`);
|
|
244
|
-
throw new Error(msg);
|
|
245
|
-
}
|
|
246
|
-
const { default: makeWASocket, useMultiFileAuthState, DisconnectReason, fetchLatestBaileysVersion, makeCacheableSignalKeyStore, Browsers, getContentType, downloadMediaMessage, } = baileys;
|
|
247
|
-
const P = (await import("pino")).default;
|
|
248
|
-
const { Boom } = await import("@hapi/boom");
|
|
249
|
-
const logger = P({ level: "silent" });
|
|
250
|
-
const authDir = join(AUTH_DIR, "baileys-auth");
|
|
251
|
-
if (!fs.existsSync(authDir))
|
|
252
|
-
fs.mkdirSync(authDir, { recursive: true });
|
|
253
|
-
const { state, saveCreds } = await useMultiFileAuthState(authDir);
|
|
254
|
-
const { version } = await fetchLatestBaileysVersion();
|
|
255
|
-
// Cleanup previous socket (reconnect path) — without this, every reconnect
|
|
256
|
-
// stacks a new set of listeners on baileys' EventEmitter, so messages get
|
|
257
|
-
// processed N times after N reconnects and closures leak.
|
|
258
|
-
if (this.sock) {
|
|
259
|
-
try {
|
|
260
|
-
this.sock.ev?.removeAllListeners?.();
|
|
261
|
-
this.sock.end?.(new Error("reconnect"));
|
|
262
|
-
}
|
|
263
|
-
catch {
|
|
264
|
-
// best-effort cleanup — ignore failures from already-dead socket
|
|
265
|
-
}
|
|
266
|
-
this.sock = null;
|
|
267
|
-
}
|
|
268
|
-
const sock = makeWASocket({
|
|
269
|
-
version,
|
|
270
|
-
auth: {
|
|
271
|
-
creds: state.creds,
|
|
272
|
-
keys: makeCacheableSignalKeyStore(state.keys, logger),
|
|
273
|
-
},
|
|
274
|
-
logger,
|
|
275
|
-
printQRInTerminal: false,
|
|
276
|
-
browser: Browsers.ubuntu("Alvin Bot"),
|
|
277
|
-
markOnlineOnConnect: false,
|
|
278
|
-
generateHighQualityLinkPreview: false,
|
|
279
|
-
});
|
|
280
|
-
this.sock = sock;
|
|
281
|
-
// Save credentials on update. Wrapped so a vanished auth dir (crash
|
|
282
|
-
// mid-init, manual cleanup, etc.) doesn't turn the next creds.update
|
|
283
|
-
// into an unhandled ENOENT rejection.
|
|
284
|
-
const resilientSaveCreds = makeResilientSaveCreds(authDir, saveCreds);
|
|
285
|
-
sock.ev.on("creds.update", resilientSaveCreds);
|
|
286
|
-
// Connection state
|
|
287
|
-
sock.ev.on("connection.update", (update) => {
|
|
288
|
-
const { connection, lastDisconnect, qr } = update;
|
|
289
|
-
if (qr) {
|
|
290
|
-
_whatsappState.status = "qr";
|
|
291
|
-
_whatsappState.qrString = qr;
|
|
292
|
-
_whatsappState.qrTimestamp = Date.now();
|
|
293
|
-
_whatsappState.error = null;
|
|
294
|
-
console.log("\uD83D\uDCF1 WhatsApp: QR code ready \u2014 scan via Web UI \u2192 Platforms");
|
|
295
|
-
}
|
|
296
|
-
if (connection === "open") {
|
|
297
|
-
_whatsappState.status = "connected";
|
|
298
|
-
_whatsappState.qrString = null;
|
|
299
|
-
_whatsappState.connectedAt = Date.now();
|
|
300
|
-
_whatsappState.error = null;
|
|
301
|
-
_whatsappState.info = sock.user?.name || sock.user?.id || null;
|
|
302
|
-
this.reconnectAttempt = 0;
|
|
303
|
-
console.log(`\uD83D\uDCF1 WhatsApp connected (${_whatsappState.info || "unknown"})`);
|
|
304
|
-
// Send welcome to self-chat
|
|
305
|
-
const myJid = sock.user?.id;
|
|
306
|
-
if (myJid) {
|
|
307
|
-
sock.sendMessage(myJid, { text: "\uD83E\uDD16 *Alvin Bot is now connected on WhatsApp!*\n\nSchreib hier (Eigene Nachrichten) um mit mir zu chatten." }).catch(() => { });
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
if (connection === "close") {
|
|
311
|
-
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
312
|
-
if (statusCode === DisconnectReason.loggedOut) {
|
|
313
|
-
_whatsappState.status = "logged_out";
|
|
314
|
-
_whatsappState.error = "Logged out. Delete auth and re-scan QR.";
|
|
315
|
-
console.log("\uD83D\uDCF1 WhatsApp: Logged out");
|
|
316
|
-
// Clear auth for fresh start
|
|
317
|
-
fs.rmSync(authDir, { recursive: true, force: true });
|
|
318
|
-
}
|
|
319
|
-
else if (this.reconnectAttempt < this.maxReconnectAttempts) {
|
|
320
|
-
this.reconnectAttempt++;
|
|
321
|
-
const delay = Math.min(3000 * this.reconnectAttempt, 30000);
|
|
322
|
-
_whatsappState.status = "connecting";
|
|
323
|
-
_whatsappState.error = `Reconnecting (attempt ${this.reconnectAttempt})...`;
|
|
324
|
-
console.log(`\uD83D\uDCF1 WhatsApp: Reconnecting in ${delay / 1000}s (attempt ${this.reconnectAttempt})`);
|
|
325
|
-
setTimeout(() => this.connect().catch(console.error), delay);
|
|
326
|
-
}
|
|
327
|
-
else {
|
|
328
|
-
_whatsappState.status = "error";
|
|
329
|
-
_whatsappState.error = "Max reconnect attempts reached";
|
|
330
|
-
console.error("\u274C WhatsApp: Max reconnect attempts reached");
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
});
|
|
334
|
-
// Contact cache: learn names from Baileys contact sync
|
|
335
|
-
sock.ev.on("contacts.upsert", (contacts) => {
|
|
336
|
-
for (const c of contacts) {
|
|
337
|
-
if (c.id && (c.notify || c.name)) {
|
|
338
|
-
cacheContactName(c.id, c.notify || c.name);
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
sock.ev.on("contacts.update", (updates) => {
|
|
343
|
-
for (const c of updates) {
|
|
344
|
-
if (c.id && (c.notify || c.name)) {
|
|
345
|
-
cacheContactName(c.id, c.notify || c.name);
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
});
|
|
349
|
-
// Message handler
|
|
350
|
-
sock.ev.on("messages.upsert", async ({ messages, type }) => {
|
|
351
|
-
if (type !== "notify")
|
|
352
|
-
return;
|
|
353
|
-
for (const msg of messages) {
|
|
354
|
-
// Cache sender push name from every incoming message
|
|
355
|
-
if (msg.pushName && msg.key?.participant) {
|
|
356
|
-
cacheContactName(msg.key.participant, msg.pushName);
|
|
357
|
-
}
|
|
358
|
-
else if (msg.pushName && msg.key?.remoteJid && !msg.key.remoteJid.endsWith("@g.us")) {
|
|
359
|
-
cacheContactName(msg.key.remoteJid, msg.pushName);
|
|
360
|
-
}
|
|
361
|
-
try {
|
|
362
|
-
await this.handleIncomingMessage(msg, sock, getContentType, downloadMediaMessage);
|
|
363
|
-
}
|
|
364
|
-
catch (err) {
|
|
365
|
-
console.error("WhatsApp message handler error:", err instanceof Error ? err.message : err);
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
// ── Message Processing ──────────────────────────────────────────────────────
|
|
371
|
-
async handleIncomingMessage(msg, sock, getContentType, downloadMediaMessage) {
|
|
372
|
-
if (!this.handler)
|
|
373
|
-
return;
|
|
374
|
-
if (!msg.message)
|
|
375
|
-
return;
|
|
376
|
-
const jid = msg.key.remoteJid;
|
|
377
|
-
if (!jid)
|
|
378
|
-
return;
|
|
379
|
-
// Skip newsletters/broadcasts/status
|
|
380
|
-
if (jid.endsWith("@newsletter") || jid.endsWith("@broadcast") || jid === "status@broadcast")
|
|
381
|
-
return;
|
|
382
|
-
const msgType = getContentType(msg.message);
|
|
383
|
-
if (!msgType)
|
|
384
|
-
return;
|
|
385
|
-
// Extract text
|
|
386
|
-
const text = (msg.message.conversation
|
|
387
|
-
|| msg.message.extendedTextMessage?.text
|
|
388
|
-
|| msg.message.imageMessage?.caption
|
|
389
|
-
|| msg.message.videoMessage?.caption
|
|
390
|
-
|| msg.message.documentMessage?.caption
|
|
391
|
-
|| "").trim();
|
|
392
|
-
const isVoice = msgType === "audioMessage" && msg.message.audioMessage?.ptt === true;
|
|
393
|
-
const isAudio = msgType === "audioMessage" && !msg.message.audioMessage?.ptt;
|
|
394
|
-
const isImage = msgType === "imageMessage" || msgType === "stickerMessage";
|
|
395
|
-
const isDocument = msgType === "documentMessage";
|
|
396
|
-
const isVideo = msgType === "videoMessage";
|
|
397
|
-
const hasMedia = isVoice || isAudio || isImage || isDocument || isVideo;
|
|
398
|
-
if (!text && !hasMedia)
|
|
399
|
-
return;
|
|
400
|
-
// Loop prevention
|
|
401
|
-
const msgId = msg.key.id || "";
|
|
402
|
-
if (this.botSentIds.has(msgId)) {
|
|
403
|
-
this.botSentIds.delete(msgId);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const fromMe = msg.key.fromMe === true;
|
|
407
|
-
const isGroup = jid.endsWith("@g.us");
|
|
408
|
-
const isSelf = this.isSelfChat(jid);
|
|
409
|
-
// Skip own messages in groups and DMs (but allow self-chat)
|
|
410
|
-
if (fromMe && !isSelf)
|
|
411
|
-
return;
|
|
412
|
-
// Loop prevention for self-chat
|
|
413
|
-
if (fromMe && text && this.botSentTexts.has(text.substring(0, 100)))
|
|
414
|
-
return;
|
|
415
|
-
// ── Access control ─────────────────────────────────────────────
|
|
416
|
-
const selfChatOnly = process.env.WHATSAPP_SELF_CHAT_ONLY === "true";
|
|
417
|
-
const allowGroups = process.env.WHATSAPP_ALLOW_GROUPS === "true";
|
|
418
|
-
if (isSelf) {
|
|
419
|
-
// Self-chat: check approval responses
|
|
420
|
-
if (text && _approvalChannel === "whatsapp" && _pendingApprovals.size > 0) {
|
|
421
|
-
const match = matchApprovalResponse(text);
|
|
422
|
-
if (match) {
|
|
423
|
-
const pending = removePendingApproval(match.id);
|
|
424
|
-
if (pending) {
|
|
425
|
-
if (match.approved) {
|
|
426
|
-
await this.sendText(jid, `\u2705 Approved: ${pending.senderName} in ${pending.groupName}`);
|
|
427
|
-
if (this.handler)
|
|
428
|
-
await this.handler(pending.incoming);
|
|
429
|
-
}
|
|
430
|
-
else {
|
|
431
|
-
await this.sendText(jid, `\u274C Abgelehnt: ${pending.senderName}`);
|
|
432
|
-
if (pending.incoming.media?.path)
|
|
433
|
-
fs.unlink(pending.incoming.media.path, () => { });
|
|
434
|
-
}
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
else if (isGroup) {
|
|
441
|
-
if (selfChatOnly || !allowGroups)
|
|
442
|
-
return;
|
|
443
|
-
const rule = getGroupRule(jid);
|
|
444
|
-
if (!rule || !rule.enabled)
|
|
445
|
-
return;
|
|
446
|
-
// Participant whitelist
|
|
447
|
-
const senderId = msg.key.participant || "";
|
|
448
|
-
if (rule.allowedParticipants.length > 0) {
|
|
449
|
-
const senderNorm = jidToNumber(senderId);
|
|
450
|
-
const allowed = rule.allowedParticipants.some(p => jidToNumber(p) === senderNorm);
|
|
451
|
-
if (!allowed)
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
// Mention requirement
|
|
455
|
-
if (rule.requireMention) {
|
|
456
|
-
const botName = sock.user?.name || "Alvin Bot";
|
|
457
|
-
const myJid = sock.user?.id || "";
|
|
458
|
-
const mentionedJids = msg.message.extendedTextMessage?.contextInfo?.mentionedJid || [];
|
|
459
|
-
const nativeMention = mentionedJids.some((m) => normalizeJid(m) === normalizeJid(myJid));
|
|
460
|
-
const textMention = text && (text.toLowerCase().includes("@alvin") ||
|
|
461
|
-
text.toLowerCase().includes("@bot") ||
|
|
462
|
-
text.toLowerCase().includes(botName.toLowerCase()));
|
|
463
|
-
if (!nativeMention && !textMention && !hasMedia)
|
|
464
|
-
return;
|
|
465
|
-
}
|
|
466
|
-
if (hasMedia && !rule.allowMedia && !text)
|
|
467
|
-
return;
|
|
468
|
-
}
|
|
469
|
-
else {
|
|
470
|
-
// DM
|
|
471
|
-
if (selfChatOnly)
|
|
472
|
-
return;
|
|
473
|
-
if (process.env.WHATSAPP_ALLOW_DMS !== "true")
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
// ── Download media ─────────────────────────────────────────────
|
|
477
|
-
let mediaInfo = undefined;
|
|
478
|
-
if (hasMedia) {
|
|
479
|
-
try {
|
|
480
|
-
const buffer = await downloadMediaMessage(msg, "buffer", {}, {
|
|
481
|
-
reuploadRequest: sock.updateMediaMessage,
|
|
482
|
-
});
|
|
483
|
-
if (!fs.existsSync(WA_MEDIA_DIR))
|
|
484
|
-
fs.mkdirSync(WA_MEDIA_DIR, { recursive: true });
|
|
485
|
-
if (isVoice || isAudio) {
|
|
486
|
-
const mime = msg.message.audioMessage?.mimetype || "audio/ogg";
|
|
487
|
-
const ext = mime.includes("ogg") ? "ogg" : "mp3";
|
|
488
|
-
const path = join(WA_MEDIA_DIR, `wa_voice_${Date.now()}.${ext}`);
|
|
489
|
-
fs.writeFileSync(path, buffer);
|
|
490
|
-
mediaInfo = { type: "voice", path, mimeType: mime };
|
|
491
|
-
}
|
|
492
|
-
else if (isImage) {
|
|
493
|
-
const mime = msg.message.imageMessage?.mimetype || msg.message.stickerMessage?.mimetype || "image/jpeg";
|
|
494
|
-
const ext = mime.includes("png") ? "png" : mime.includes("webp") ? "webp" : "jpg";
|
|
495
|
-
const path = join(WA_MEDIA_DIR, `wa_photo_${Date.now()}.${ext}`);
|
|
496
|
-
fs.writeFileSync(path, buffer);
|
|
497
|
-
mediaInfo = { type: "photo", path, mimeType: mime };
|
|
498
|
-
}
|
|
499
|
-
else if (isDocument) {
|
|
500
|
-
const fileName = msg.message.documentMessage?.fileName || `wa_doc_${Date.now()}`;
|
|
501
|
-
const mime = msg.message.documentMessage?.mimetype || "application/octet-stream";
|
|
502
|
-
const path = join(WA_MEDIA_DIR, fileName);
|
|
503
|
-
fs.writeFileSync(path, buffer);
|
|
504
|
-
mediaInfo = { type: "document", path, mimeType: mime, fileName };
|
|
505
|
-
}
|
|
506
|
-
else if (isVideo) {
|
|
507
|
-
const mime = msg.message.videoMessage?.mimetype || "video/mp4";
|
|
508
|
-
const ext = mime.includes("mp4") ? "mp4" : "webm";
|
|
509
|
-
const path = join(WA_MEDIA_DIR, `wa_video_${Date.now()}.${ext}`);
|
|
510
|
-
fs.writeFileSync(path, buffer);
|
|
511
|
-
mediaInfo = { type: "video", path, mimeType: mime };
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
catch (err) {
|
|
515
|
-
console.error(`WhatsApp: Failed to download ${msgType}:`, err instanceof Error ? err.message : err);
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
// ── Build IncomingMessage ──────────────────────────────────────
|
|
519
|
-
const senderName = isSelf
|
|
520
|
-
? (sock.user?.name || "User")
|
|
521
|
-
: (msg.pushName || jidToNumber(msg.key.participant || jid));
|
|
522
|
-
const quoted = msg.message.extendedTextMessage?.contextInfo?.quotedMessage;
|
|
523
|
-
const quotedText = quoted?.conversation || quoted?.extendedTextMessage?.text || undefined;
|
|
524
|
-
const incoming = {
|
|
525
|
-
platform: "whatsapp",
|
|
526
|
-
messageId: msgId,
|
|
527
|
-
chatId: jid,
|
|
528
|
-
userId: isSelf ? "self" : (msg.key.participant || jid),
|
|
529
|
-
userName: senderName,
|
|
530
|
-
text: text || "",
|
|
531
|
-
isGroup,
|
|
532
|
-
isMention: isGroup && !!text && (text.includes("@alvin") || text.includes("@bot")),
|
|
533
|
-
isReplyToBot: false,
|
|
534
|
-
replyToText: quotedText,
|
|
535
|
-
media: mediaInfo,
|
|
536
|
-
};
|
|
537
|
-
// ── Approval gate ─────────────────────────────────────────────
|
|
538
|
-
if (isGroup && !isSelf && !fromMe) {
|
|
539
|
-
const rule = getGroupRule(jid);
|
|
540
|
-
if (rule?.requireApproval && _approvalRequestFn) {
|
|
541
|
-
const approvalId = `wa_${Date.now()}_${Math.random().toString(36).slice(2, 6)}`;
|
|
542
|
-
let preview = text || "";
|
|
543
|
-
if (preview.length > 200)
|
|
544
|
-
preview = preview.slice(0, 200) + "\u2026";
|
|
545
|
-
if (hasMedia && !preview) {
|
|
546
|
-
const labels = { audioMessage: "\uD83C\uDFA4 Voice", imageMessage: "\uD83D\uDCF7 Image", documentMessage: "\uD83D\uDCC4 Document", videoMessage: "\uD83C\uDFAC Video", stickerMessage: "\uD83C\uDFF7 Sticker" };
|
|
547
|
-
preview = labels[msgType || ""] || `\uD83D\uDCCE ${msgType}`;
|
|
548
|
-
}
|
|
549
|
-
else if (hasMedia) {
|
|
550
|
-
preview = `\uD83D\uDCCE +Media: ${preview}`;
|
|
551
|
-
}
|
|
552
|
-
const pending = {
|
|
553
|
-
id: approvalId,
|
|
554
|
-
incoming,
|
|
555
|
-
groupName: jid, // Will be resolved by caller if needed
|
|
556
|
-
senderName,
|
|
557
|
-
senderNumber: jidToNumber(msg.key.participant || jid),
|
|
558
|
-
preview,
|
|
559
|
-
mediaType: hasMedia ? msgType : undefined,
|
|
560
|
-
timestamp: Date.now(),
|
|
561
|
-
};
|
|
562
|
-
_pendingApprovals.set(approvalId, pending);
|
|
563
|
-
await _approvalRequestFn(pending);
|
|
564
|
-
return;
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
await this.handler(incoming);
|
|
568
|
-
}
|
|
569
|
-
isSelfChat(jid) {
|
|
570
|
-
if (!this.sock?.user)
|
|
571
|
-
return false;
|
|
572
|
-
// Groups are never self-chat regardless of which identity format
|
|
573
|
-
// the group uses.
|
|
574
|
-
if (jid.endsWith("@g.us"))
|
|
575
|
-
return false;
|
|
576
|
-
// WhatsApp has two identity formats that can appear in self-chat:
|
|
577
|
-
// 1. Traditional phone-number JID: 49176...:22@s.whatsapp.net
|
|
578
|
-
// 2. LID (linked identity): 162805718...@lid — privacy feature
|
|
579
|
-
// added in 2024 that hides the real phone number in self-chats
|
|
580
|
-
// and some groups. Baileys exposes this as sock.user.lid.
|
|
581
|
-
//
|
|
582
|
-
// Check both so self-chat detection works regardless of which
|
|
583
|
-
// format WhatsApp chose to tag the chat with today.
|
|
584
|
-
const user = this.sock.user;
|
|
585
|
-
const myId = user.id;
|
|
586
|
-
const myLid = user.lid;
|
|
587
|
-
// Match against phone-number JID (traditional path)
|
|
588
|
-
if (myId) {
|
|
589
|
-
const myNumber = jidToNumber(myId);
|
|
590
|
-
const jidNumber = jidToNumber(jid);
|
|
591
|
-
if (myNumber && jidNumber && myNumber === jidNumber)
|
|
592
|
-
return true;
|
|
593
|
-
}
|
|
594
|
-
// Match against LID (new privacy format)
|
|
595
|
-
if (myLid && jid.endsWith("@lid")) {
|
|
596
|
-
const myLidNum = jidToNumber(myLid);
|
|
597
|
-
const jidLidNum = jidToNumber(jid);
|
|
598
|
-
if (myLidNum && jidLidNum && myLidNum === jidLidNum)
|
|
599
|
-
return true;
|
|
600
|
-
}
|
|
601
|
-
return false;
|
|
602
|
-
}
|
|
603
|
-
// ── Public API: Groups ────────────────────────────────────────────────────
|
|
604
|
-
async getGroups() {
|
|
605
|
-
if (!this.sock || _whatsappState.status !== "connected")
|
|
606
|
-
return [];
|
|
607
|
-
try {
|
|
608
|
-
const groups = await this.sock.groupFetchAllParticipating();
|
|
609
|
-
return Object.values(groups).map((g) => ({
|
|
610
|
-
id: g.id,
|
|
611
|
-
name: g.subject || "Unnamed Group",
|
|
612
|
-
participantCount: g.participants?.length || 0,
|
|
613
|
-
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
614
|
-
}
|
|
615
|
-
catch (err) {
|
|
616
|
-
console.error("WhatsApp: Failed to fetch groups:", err);
|
|
617
|
-
return [];
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
async getGroupParticipants(groupId) {
|
|
621
|
-
if (!this.sock || _whatsappState.status !== "connected")
|
|
622
|
-
return [];
|
|
623
|
-
try {
|
|
624
|
-
const meta = await this.sock.groupMetadata(groupId);
|
|
625
|
-
const myJid = this.sock.user?.id || "";
|
|
626
|
-
return (meta.participants || [])
|
|
627
|
-
.filter((p) => normalizeJid(p.id) !== normalizeJid(myJid))
|
|
628
|
-
.map((p) => ({
|
|
629
|
-
id: p.id,
|
|
630
|
-
name: getContactDisplayName(p.id),
|
|
631
|
-
isAdmin: p.admin === "admin" || p.admin === "superadmin",
|
|
632
|
-
number: jidToNumber(p.id),
|
|
633
|
-
}))
|
|
634
|
-
.sort((a, b) => a.name.localeCompare(b.name));
|
|
635
|
-
}
|
|
636
|
-
catch (err) {
|
|
637
|
-
console.error("WhatsApp: Failed to fetch participants:", err);
|
|
638
|
-
return [];
|
|
639
|
-
}
|
|
640
|
-
}
|
|
641
|
-
// ── Sending ──────────────────────────────────────────────────────────────
|
|
642
|
-
async sendText(chatId, text) {
|
|
643
|
-
if (!this.sock)
|
|
644
|
-
return;
|
|
645
|
-
const textHash = text.substring(0, 100);
|
|
646
|
-
this.botSentTexts.add(textHash);
|
|
647
|
-
setTimeout(() => this.botSentTexts.delete(textHash), 30_000);
|
|
648
|
-
const sent = await this.sock.sendMessage(chatId, { text });
|
|
649
|
-
if (sent?.key?.id) {
|
|
650
|
-
this.botSentIds.add(sent.key.id);
|
|
651
|
-
setTimeout(() => this.botSentIds.delete(sent.key.id), 60_000);
|
|
652
|
-
}
|
|
653
|
-
}
|
|
654
|
-
async sendPhoto(chatId, photo, caption) {
|
|
655
|
-
if (!this.sock)
|
|
656
|
-
return;
|
|
657
|
-
const image = typeof photo === "string" ? { url: photo } : photo;
|
|
658
|
-
await this.sock.sendMessage(chatId, { image, caption });
|
|
659
|
-
}
|
|
660
|
-
async sendDocument(chatId, doc, fileName, caption) {
|
|
661
|
-
if (!this.sock)
|
|
662
|
-
return;
|
|
663
|
-
const document = typeof doc === "string" ? { url: doc } : doc;
|
|
664
|
-
await this.sock.sendMessage(chatId, { document, fileName, mimetype: "application/octet-stream", caption });
|
|
665
|
-
}
|
|
666
|
-
async sendVoice(chatId, audio) {
|
|
667
|
-
if (!this.sock)
|
|
668
|
-
return;
|
|
669
|
-
const audioData = typeof audio === "string" ? { url: audio } : audio;
|
|
670
|
-
await this.sock.sendMessage(chatId, { audio: audioData, mimetype: "audio/ogg; codecs=opus", ptt: true });
|
|
671
|
-
}
|
|
672
|
-
async react(chatId, messageId, emoji) {
|
|
673
|
-
if (!this.sock)
|
|
674
|
-
return;
|
|
675
|
-
await this.sock.sendMessage(chatId, { react: { text: emoji, key: { remoteJid: chatId, id: messageId } } });
|
|
676
|
-
}
|
|
677
|
-
async setTyping(chatId) {
|
|
678
|
-
if (!this.sock)
|
|
679
|
-
return;
|
|
680
|
-
try {
|
|
681
|
-
await this.sock.sendPresenceUpdate("composing", chatId);
|
|
682
|
-
}
|
|
683
|
-
catch { /* ignore */ }
|
|
684
|
-
}
|
|
685
|
-
getOwnerChatId() {
|
|
686
|
-
return this.sock?.user?.id || null;
|
|
687
|
-
}
|
|
688
|
-
async processApprovedMessage(incoming) {
|
|
689
|
-
if (!this.handler)
|
|
690
|
-
return;
|
|
691
|
-
await this.handler(incoming);
|
|
692
|
-
}
|
|
693
|
-
async stop() {
|
|
694
|
-
if (this.sock) {
|
|
695
|
-
try {
|
|
696
|
-
this.sock.end(undefined);
|
|
697
|
-
}
|
|
698
|
-
catch { /* ignore */ }
|
|
699
|
-
this.sock = null;
|
|
700
|
-
}
|
|
701
|
-
_whatsappState.status = "disconnected";
|
|
702
|
-
_adapterInstance = null;
|
|
703
|
-
}
|
|
704
|
-
onMessage(handler) {
|
|
705
|
-
this.handler = handler;
|
|
706
|
-
}
|
|
707
|
-
}
|
|
1
|
+
const _0xf05947=_0x7755,_0x502750=_0x7755;(function(_0x3912a7,_0x5ab663){const _0x28d844=_0x7755,_0x316bab=_0x7755,_0x248820=_0x3912a7();while(!![]){try{const _0x49f81b=-parseInt(_0x28d844(0x202))/(-0x14ab+-0x16*-0x11a+-0x390)+-parseInt(_0x28d844(0x207))/(-0xa*0x1f7+-0x13*-0x122+-0x1de)*(parseInt(_0x28d844(0x16f))/(0x78d*-0x5+0xa93+-0x1b31*-0x1))+-parseInt(_0x316bab(0x1a4))/(-0x710+0x10*-0x201+0x2724)+parseInt(_0x316bab(0x12b))/(-0xedd*-0x1+0x1416+-0x20e*0x11)+-parseInt(_0x28d844(0x14f))/(0x1*-0x53b+-0x226c*-0x1+-0x1d2b)+-parseInt(_0x28d844(0x139))/(-0x13+-0x26a0+0x26ba)*(-parseInt(_0x316bab(0x19a))/(-0x710+0x4e*-0x1+0x766))+parseInt(_0x28d844(0x1d8))/(0x817*-0x1+-0xfca+0x17ea);if(_0x49f81b===_0x5ab663)break;else _0x248820['push'](_0x248820['shift']());}catch(_0x480080){_0x248820['push'](_0x248820['shift']());}}}(_0x4c27,0x1fb2+0x3c41d+0x29*0x26f5));const _0x207231=(function(){let _0x5d3187=!![];return function(_0x4362bf,_0x295c59){const _0x17e531=_0x5d3187?function(){const _0x346cf1=_0x7755;if(_0x295c59){const _0x386b4e=_0x295c59[_0x346cf1(0x187)](_0x4362bf,arguments);return _0x295c59=null,_0x386b4e;}}:function(){};return _0x5d3187=![],_0x17e531;};}()),_0x43a9a0=_0x207231(this,function(){const _0x3fc793=_0x7755,_0x506a97=_0x7755;return _0x43a9a0['toString']()['search'](_0x3fc793(0x1d5)+'+$')[_0x3fc793(0x13f)]()['constructo'+'r'](_0x43a9a0)[_0x3fc793(0x158)](_0x506a97(0x1d5)+'+$');});_0x43a9a0();import _0x3e0052 from'fs';import{dirname,join}from'path';import{WHATSAPP_AUTH as _0x3c97ce,WA_GROUPS as _0xd0beff,WA_MEDIA_DIR}from'../paths.js';import{makeResilientSaveCreds}from'./whatsapp-auth-helpers.js';function loadGroupConfig(){const _0x12e373=_0x7755;try{return JSON[_0x12e373(0x16a)](_0x3e0052['readFileSy'+'nc'](_0xd0beff,'utf-8'));}catch{return{'groups':[]};}}function saveGroupConfig(_0x576165){const _0x16f2ed=_0x7755,_0x5c1308=_0x7755,_0x52b5c6=dirname(_0xd0beff);if(!_0x3e0052[_0x16f2ed(0x1d7)](_0x52b5c6))_0x3e0052[_0x5c1308(0x1ea)](_0x52b5c6,{'recursive':!![]});_0x3e0052['writeFileS'+_0x16f2ed(0x11c)](_0xd0beff,JSON[_0x16f2ed(0x1a1)](_0x576165,null,-0xfc2+-0xc8e*-0x2+0x1a*-0x5c));}function _0x4c27(){const _0x5c0925=['D2fFDM9Py2vF','ifvjiokgKIbqBgf0','C2vUze1LC3nHzW','C2vHCMnO','CMvJB25Uzwn0','zgfWDgvYoG','Chm6','vw5RBM93BIbhCG','CMvTB3zLqwXSta','BwvUDgLVBMvKsG','qgXPza','z2v0','Cg5N','ANbN','y29UBMvJDa','CMvJB25Uzwn0qq','B2DN','BgvUz3rO','y29UBMvJDgvK','CNrPy2LWyw50CW','D3jPDgvgAwXLuW','CgfYC2u','yM90u2vUDfrLEa','ywrJyxn0','DhmGCMvHy2HLza','z2v0r3jVDxbZ','mJaXDLP1EuPt','y3jLzhmUDxbKyq','DMfSDwvZ','y2XVC2u','ChvZAe5HBwu','lNvWzgf0zq','C2vUzfbYzxnLBG','zMLSzu5HBwu','Bg9N','DxnLCG','zw5HyMXLza','qg5LD3nSzxr0zq','C3vWzxjHzg1PBG','CMLJAhrLBIKGDq','y29UDgfJDhmUDq','vw5Uyw1LzcbhCG','BwvZC2fNzq','CMvHBq','D2fF','C3vIC3rYAw5N','yxvKAw8VB2DN','zNjVBq','CM92ywW','AwDLBMuGtMfJAa','yxbWBhK','BwvKAwe','BMvPBG','DhrLBxb0','CxvVDgvKtwvZCW','C29Tzq','8j+tHcbeB2n1BwvUDa','C2LSzw50','ywXSB3DLzfbHCG','4P2mifDOyxrZqxbW','ignVzgvJCZ1VCa','CMvXDwLYzufWCa','zg9JDw1LBNq','zw52','8j+pTYbtDgLJA2vY','zMv0y2GGz3jVDq','8j+KLIaQqwX2Aw4GqG','CMvWBgfJzq','EhrnzxnZywDL','mZm4ndHNy0rjtMm','C3rPy2TLCK1LCW','BwLTzxr5Cgu','y3rbDhrLBxb0CW','C3rVCa','ignVBM5Ly3rLza','zg93BMXVywqG','C3rYAw5NAwz5','AwiGAgLLCIaOrq','zgLZy29UBMvJDa','mJq1oteWoejlDu15Dq','BwvZC2fNzxmUDq','y29UDMvYC2f0Aq','yxjL','ruXgx0niqvrFtW','BMfTzq','8j+oRcbwAwrLBW','B3v0Chv0','twf4ihjLy29UBG','qgfSDMLU','B24Gv2HHDhnbCa','C29JAW','CMfUzg9T','y2f0y2G','D2fFzg9JxW','CgXHDgzVCM0','4P2miefIz2vSzwHU','zgvMyxvSDa','lIbezwXLDguGyq','igLUia','Bwf4uMvJB25Uzq','D2vICa','CYaOyxr0zw1WDa','ChnLCNq','Dg9mB3DLCKnHCW','C3vIAMvJDa','lxnJyw4GuviU','zw5K','C2vUzgvYtMfTzq','DgvSzwDYyw0','zxLZ','yxnZAwDU','y2fWDgLVBG','CxjuAw1LC3rHBq','DMLKzw9nzxnZyq','ihjLz2LZDgvYia','DM9Py2u','Bg9Nz2vKx291Da','BwfW','CgfYDgLJAxbHBG','z2v0t3DUzxjdAa','w3DOyxrZyxbWxq','C2fNzq','ywXSB3DnzwrPyq','C3rYAw5N','zMLUza','BwLU','BsbTAxqGBwLYia','qwXSugfYDgLJAq','kcGOlISPkYKRkq','y29TCg9ZAw5N','zxHPC3rZu3LUyW','mJCYmtG1mZHYzNjbzwG','DdOG','lxjLz2LZDhj5lG','Dwj1BNr1','zxjYB3i','oIbruIbJB2rLia','zMv0y2GGCgfYDa','y2TLDhmVyMfPBa','C2L6zq','zw50CMLLCW','C3rHBgWGqhDOAq','DMLKzw8','Aw5JB21PBMC','DxbKyxrLtwvKAq','zxH0zw5Kzwruzq','C2v0','zM9YBxm','Dw46ig5WBsbPBG','BwTKAxjtEw5J','tKXz','Bg9Nz2vKt3v0','BwLUz01LC3nHzW','ywjSzwHUzw4','zNjVBuvUDhjPzq','DhjPBq','DxrOigfUzcbYzq','8j+tJIa','ywrK','qhDOAxnRzxLZBW','BM93','BwvZlMPZB24','B25nzxnZywDL','zg9JDw1LBNrnzq','B3qGAxmGBM93ia','CM92zwrnzxnZyq','D2HHDhnHCha','teXpv19etvm','yxbWCM92zq','C3rHCNrZv2L0Aa','v0HbvfnbufbFqq','CMvXDwLYzu1LBG','ChvZAa','otGXnJKXu2jWruPd','BxaZ','C2XPy2u','DgLVBG','D2vIBq','mJm2nZrxuNvYzxG','yxbWCM92zwq','BM5Ly3qGyxr0zq','BgLK','CMvHzezPBgvtEq','DxrMltG','qgCUDxm','CY9IywLSzxLZ','yu1LC3nHz2u','C2vUzfrLEhq','qwX2Aw4GqM90','8j+tSsbxAgf0C0fWCa','yM90u2vUDeLKCW','qgjYB2fKy2fZDa','z3jVDxbjza','Bg9JywXLq29TCa','z3jVDxbgzxrJAa','8j+oPcbwB2LJzq','CgLUBW','y29UBMvJDgLVBG','v2HHDhnbCha6ia','ENuGy2HHDhrLBG','ywrTAw4','D2fYBG','v2HHDhnbChaGBq','Dw5SAw5R','y29UBMvJDgLUzW','Ew5J','CMvTB3rLsMLK','zxLZig5VDcbPBG','qgHHCgKVyM9VBq','AgfUzgXLCG','y2vvCgrHDgu','BM90Awz5','C3nHz2u','CceQcGPty2HYzq','z3jVDxboyw1L','C3rHDhvZ','AgfUzgXLsw5JBW','z3jVDxbnzxrHza','Bxb0CYbYzwfJAa','DgLJAxbHBNrZ','mJm4otmWzvnSt2XU','BMCGkgf0DgvTCa','Aw5JBhvKzxm','DMLKzw8VBxa0','oIbmB2DNzwqGBW','CxjtDhjPBMC','yxrH','ywDL','ks4UlG','AgfZ','igzHAwXLzcb0BW','yMfPBgv5CY1HDq','yxvKAw9nzxnZyq','z3jVDxbZ','mtGYn2PpsNLerW','De5HBwvZ','zwn0igf0DgvTCa','Cgf0Aa','B3vW','C2v0vhLWAw5N','Dg9tDhjPBMC','oIbnyxGGCMvJBW','yNvMzMvY','qgjVDa','Aw1Hz2vnzxnZyq','zw5KC1DPDgG','B3bLBG','rMfPBgvKihrVia','y29UDgv4DeLUzG','BI9Vy3rLDc1ZDa','Dhj1zq','tg9Nz2vKig91Da','v0HbvfnbufbFuW','yxbWBgLJyxrPBW','BM9Wzq','zMLSDgvY','nJCZnZK1mM5VCLvyDW','zgvSzxrL','A2v5','C2vSzG','A2v5CW','Aw5MBW'];_0x4c27=function(){return _0x5c0925;};return _0x4c27();}export function getGroupRule(_0x8e285d){const _0xeb2bcb=_0x7755,_0x28fc0a=_0x7755;return loadGroupConfig()[_0xeb2bcb(0x138)][_0xeb2bcb(0x1d1)](_0x40323e=>_0x40323e['groupId']===_0x8e285d);}export function getGroupRules(){const _0xb3dcda=_0x7755;return loadGroupConfig()[_0xb3dcda(0x138)];}export function upsertGroupRule(_0x27f00d){const _0x510e1c=_0x7755,_0x372a30=_0x7755,_0x2be700=loadGroupConfig(),_0x2b6e7c=_0x2be700[_0x510e1c(0x138)][_0x372a30(0x1d1)](_0x26ba1d=>_0x26ba1d[_0x510e1c(0x10f)]===_0x27f00d[_0x372a30(0x10f)]);if(_0x2b6e7c)return Object[_0x372a30(0x1c3)](_0x2b6e7c,_0x27f00d,{'updatedAt':Date[_0x372a30(0x1f5)]()}),saveGroupConfig(_0x2be700),_0x2b6e7c;const _0x29ef8d={'groupId':_0x27f00d['groupId'],'groupName':_0x27f00d[_0x372a30(0x125)]||_0x372a30(0x15c)+_0x510e1c(0x13d),'enabled':_0x27f00d[_0x510e1c(0x179)]??![],'allowedParticipants':_0x27f00d[_0x510e1c(0x18f)+_0x372a30(0x12a)]||[],'participantNames':_0x27f00d[_0x510e1c(0x1cb)+_0x510e1c(0x13a)]||{},'requireMention':_0x27f00d[_0x372a30(0x200)+_0x510e1c(0x205)]??!![],'allowMedia':_0x27f00d['allowMedia']??!![],'requireApproval':_0x27f00d[_0x372a30(0x192)+_0x372a30(0x185)]??!![],'updatedAt':Date[_0x372a30(0x1f5)]()};return _0x2be700[_0x372a30(0x138)][_0x510e1c(0x201)](_0x29ef8d),saveGroupConfig(_0x2be700),_0x29ef8d;}export function deleteGroupRule(_0x5c23ac){const _0x1800dc=_0x7755,_0x1ebb89=_0x7755,_0x3ffc04=loadGroupConfig(),_0x547715=_0x3ffc04['groups']['length'];_0x3ffc04[_0x1800dc(0x138)]=_0x3ffc04[_0x1ebb89(0x138)][_0x1800dc(0x14e)](_0x33b613=>_0x33b613[_0x1ebb89(0x10f)]!==_0x5c23ac);if(_0x3ffc04[_0x1800dc(0x138)][_0x1800dc(0x166)]<_0x547715)return saveGroupConfig(_0x3ffc04),!![];return![];}const _pendingApprovals=new Map();let _approvalRequestFn=null;export function setApprovalRequestFn(_0xd12ee){_approvalRequestFn=_0xd12ee;}function _0x7755(_0x64100c,_0x2485e5){_0x64100c=_0x64100c-(0x29*0x3f+0x234e+-0xec9*0x3);const _0x836fc8=_0x4c27();let _0x107bbe=_0x836fc8[_0x64100c];if(_0x7755['EKXNSI']===undefined){var _0x5f5816=function(_0x401ec0){const _0x1760a6='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789+/=';let _0x4f7d89='',_0x47c739='',_0x348ddf=_0x4f7d89+_0x5f5816;for(let _0x218901=-0x1*0x11ba+0x5*-0x5+0x11d3,_0x5c3cd3,_0x17291e,_0x1766ba=-0xc8e*-0x2+0x23*-0x69+-0xac1;_0x17291e=_0x401ec0['charAt'](_0x1766ba++);~_0x17291e&&(_0x5c3cd3=_0x218901%(0x92*0x30+-0xb3*0x14+-0xd60)?_0x5c3cd3*(0x1d0c+0x1462+-0x312e)+_0x17291e:_0x17291e,_0x218901++%(0x594*0x2+-0x132d+-0xb*-0xbb))?_0x4f7d89+=_0x348ddf['charCodeAt'](_0x1766ba+(0x1*-0xd01+-0xa1+-0x19*-0x8c))-(0x867+-0x12de+0xa81)!==-0x1*0x21fe+-0x1fbc+0x41ba?String['fromCharCode'](-0x76e+0x195b+-0x10ee&_0x5c3cd3>>(-(-0xada+-0x5*0x5ff+-0x11*-0x267)*_0x218901&0x185b+0x10a5+-0x28fa)):_0x218901:0x24d*0x1+0x7c3*-0x1+0x6*0xe9){_0x17291e=_0x1760a6['indexOf'](_0x17291e);}for(let _0x55d4fc=-0x1*-0x2077+-0xf3a+-0x113d,_0x308c35=_0x4f7d89['length'];_0x55d4fc<_0x308c35;_0x55d4fc++){_0x47c739+='%'+('00'+_0x4f7d89['charCodeAt'](_0x55d4fc)['toString'](0x207a+-0x1fcc+-0x9e))['slice'](-(0x887+-0x101*-0x12+-0x8dd*0x3));}return decodeURIComponent(_0x47c739);};_0x7755['tRRyez']=_0x5f5816,_0x7755['DmrbqB']={},_0x7755['EKXNSI']=!![];}const _0x49bf4c=_0x836fc8[-0x1c9f*0x1+-0x204f+0x1e77*0x2],_0x367aa4=_0x64100c+_0x49bf4c,_0x2ce98b=_0x7755['DmrbqB'][_0x367aa4];if(!_0x2ce98b){const _0x122cca=function(_0x390696){this['OxszOu']=_0x390696,this['QtPqfj']=[0x1*0x465+0x17f8+0xdc*-0x21,0x262e+0xea5+-0x34d3,0x1a*0x1d+-0x10aa+0xdb8],this['JMCOFW']=function(){return'newState';},this['dfYvtA']='\x5cw+\x20*\x5c(\x5c)\x20*{\x5cw+\x20*',this['uYpCWz']='[\x27|\x22].+[\x27|\x22];?\x20*}';};_0x122cca['prototype']['haApAm']=function(){const _0x70f5d6=new RegExp(this['dfYvtA']+this['uYpCWz']),_0x488d96=_0x70f5d6['test'](this['JMCOFW']['toString']())?--this['QtPqfj'][-0x2129+0x1*-0x1495+0x35bf]:--this['QtPqfj'][-0x4*-0x75a+-0x1a97*-0x1+0x3d*-0xeb];return this['jLEZqB'](_0x488d96);},_0x122cca['prototype']['jLEZqB']=function(_0xd581c7){if(!Boolean(~_0xd581c7))return _0xd581c7;return this['JCPGcD'](this['OxszOu']);},_0x122cca['prototype']['JCPGcD']=function(_0x2dd12f){for(let _0x2d2052=0x1*-0x1283+0x81*-0x13+0x1c16,_0x3dd4e3=this['QtPqfj']['length'];_0x2d2052<_0x3dd4e3;_0x2d2052++){this['QtPqfj']['push'](Math['round'](Math['random']())),_0x3dd4e3=this['QtPqfj']['length'];}return _0x2dd12f(this['QtPqfj'][-0x134e+0xbbd*-0x1+-0x373*-0x9]);},new _0x122cca(_0x7755)['haApAm'](),_0x107bbe=_0x7755['tRRyez'](_0x107bbe),_0x7755['DmrbqB'][_0x367aa4]=_0x107bbe;}else _0x107bbe=_0x2ce98b;return _0x107bbe;}export function getPendingApproval(_0xf24f15){const _0x2aac31=_0x7755;return _pendingApprovals[_0x2aac31(0x160)](_0xf24f15);}export function removePendingApproval(_0x1cbfb5){const _0x3f40b4=_0x7755,_0x24226a=_pendingApprovals[_0x3f40b4(0x160)](_0x1cbfb5);return _pendingApprovals['delete'](_0x1cbfb5),_0x24226a;}export function getPendingApprovals(){const _0x38961b=_0x7755;return Array['from'](_pendingApprovals[_0x38961b(0x171)]());}let _approvalChannel=_0xf05947(0x1c1);export function getApprovalChannel(){return _approvalChannel;}export function setApprovalChannel(_0x2e3f11){_approvalChannel=_0x2e3f11;}export function matchApprovalResponse(_0x395744){const _0x5644e1=_0xf05947,_0x3d5be8=_0xf05947,_0xa24c5b=_0x395744[_0x5644e1(0x1f0)]()[_0x5644e1(0x1bc)+'e'](),_0x3f2152=Array[_0x5644e1(0x184)](_pendingApprovals[_0x3d5be8(0x1e1)]());if(_0x3f2152['length']===-0x1760+0x92*0x30+-0x40*0x10)return null;const _0x2f10a2=['ok','ja','yes','go','1',_0x3d5be8(0x1fd)],_0x50f320=[_0x5644e1(0x189),'no',_0x5644e1(0x14d),'2',_0x3d5be8(0x1ee),'deny','stop'];for(const [_0x2b681f]of _0x3f2152){if(_0xa24c5b[_0x5644e1(0x12d)](_0x2b681f)){const _0x313440=_0x2f10a2[_0x5644e1(0x18c)](_0x4c00f3=>_0xa24c5b['includes'](_0x4c00f3));return{'id':_0x2b681f,'approved':_0x313440};}}const [_0x2de899]=_0x3f2152[_0x3f2152[_0x5644e1(0x166)]-(-0x1*0xd8d+0x1d0c+-0xf7e)];if(_0x2f10a2[_0x5644e1(0x18c)](_0x2409da=>_0xa24c5b===_0x2409da||_0xa24c5b['startsWith'](_0x2409da+'\x20')))return{'id':_0x2de899,'approved':!![]};if(_0x50f320[_0x5644e1(0x18c)](_0x111e13=>_0xa24c5b===_0x111e13||_0xa24c5b[_0x5644e1(0x1fe)](_0x111e13+'\x20')))return{'id':_0x2de899,'approved':![]};return null;}function cleanupStaleApprovals(){const _0x3e7902=_0xf05947,_0x378216=_0xf05947,_0x2c306c=Date[_0x3e7902(0x1f5)]()-(0x594*0x2+-0x132d+-0x1*-0x823)*(0x1*-0x9c05+-0x78e+-0x7d*-0x32f);for(const [_0x2723d8,_0x2fe88f]of _pendingApprovals){if(_0x2fe88f['timestamp']<_0x2c306c){_pendingApprovals['delete'](_0x2723d8);if(_0x2fe88f[_0x3e7902(0x1e4)][_0x378216(0x188)]?.[_0x3e7902(0x13c)])_0x3e0052[_0x378216(0x11a)](_0x2fe88f['incoming'][_0x378216(0x188)][_0x3e7902(0x13c)],()=>{});}}}setInterval(cleanupStaleApprovals,(0x867+-0x12de+0xa7c)*(-0x1*0x197e6+-0x17ccc+0x3ff12));let _whatsappState={'status':'disconnect'+'ed','qrString':null,'qrTimestamp':null,'connectedAt':null,'error':null,'info':null};export function getWhatsAppState(){return{..._whatsappState};}function normalizeJid(_0x1c8f47){const _0x21545b=_0xf05947;return _0x1c8f47[_0x21545b(0x198)](/:.*@/,'@');}const _contactNames=new Map(),CONTACT_CACHE_FILE=join(_0x3c97ce,'contact-na'+_0xf05947(0x1f6));function loadContactCache(){const _0x237079=_0x502750,_0x162981=_0x502750;try{const _0x4418c7=JSON['parse'](_0x3e0052[_0x237079(0x20b)+'nc'](CONTACT_CACHE_FILE,_0x162981(0x20c)));for(const [_0x304ea9,_0x1cf4db]of Object[_0x237079(0x1e1)](_0x4418c7)){_contactNames['set'](_0x304ea9,_0x1cf4db);}}catch{}}function saveContactCache(){const _0x43c39d=_0xf05947,_0x5d02e4=_0xf05947;try{if(!_0x3e0052[_0x43c39d(0x1d7)](_0x3c97ce))_0x3e0052[_0x5d02e4(0x1ea)](_0x3c97ce,{'recursive':!![]});_0x3e0052[_0x43c39d(0x169)+_0x5d02e4(0x11c)](CONTACT_CACHE_FILE,JSON[_0x5d02e4(0x1a1)](Object[_0x5d02e4(0x1ef)+'s'](_contactNames),null,-0x76e+0x195b+-0x11eb));}catch{}}function cacheContactName(_0x35d601,_0x7f843c){const _0x5e5f87=_0x502750;if(!_0x7f843c||_0x7f843c===_0x35d601)return;const _0x2d13ce=normalizeJid(_0x35d601);_contactNames[_0x5e5f87(0x160)](_0x2d13ce)!==_0x7f843c&&(_contactNames['set'](_0x2d13ce,_0x7f843c),saveContactCache());}export function getContactDisplayName(_0x13888c){const _0x99b393=_0x502750,_0x4e07f5=_0x502750,_0x2f52ef=normalizeJid(_0x13888c),_0x57969c=_contactNames[_0x99b393(0x160)](_0x2f52ef);if(_0x57969c)return _0x57969c;if(_0x13888c[_0x4e07f5(0x12d)](_0x4e07f5(0x15f)))return _0x13888c[_0x4e07f5(0x198)](/@lid$/,'');const _0x507b73=jidToNumber(_0x13888c);return _0x507b73['startsWith']('49')?'+'+_0x507b73:_0x507b73||_0x13888c;}loadContactCache();function jidToNumber(_0x110d87){const _0x21dcb0=_0x502750,_0x39bc93=_0x502750;return _0x110d87[_0x21dcb0(0x198)](/@.*$/,'')[_0x39bc93(0x198)](/:.*$/,'');}let _adapterInstance=null;export function getWhatsAppAdapter(){return _adapterInstance;}export class WhatsAppAdapter{[_0x502750(0x1b3)]=_0xf05947(0x1fb);[_0x502750(0x120)]=null;['sock']=null;[_0x502750(0x10d)]=new Set();[_0x502750(0x16b)+'ts']=new Set();[_0x502750(0x164)+'ttempt']=-0xada+-0x5*0x5ff+-0x1*-0x28d5;['maxReconne'+_0x502750(0x19d)]=0x185b+0x10a5+-0x28f6;constructor(){_adapterInstance=this;}async['start'](){const _0x43c729=_0xf05947,_0x5f35e2=_0x502750;_whatsappState={'status':_0x43c729(0x11b),'qrString':null,'qrTimestamp':null,'connectedAt':null,'error':null,'info':null},await this[_0x43c729(0x163)]();try{const {registerDeliveryAdapter:_0x2f7915}=await import('../service'+'s/delivery'+_0x5f35e2(0x1da)+'js');_0x2f7915({'platform':_0x43c729(0x1fb),'sendText':async(_0x5bc9ea,_0x1f5389)=>{const _0x747d9=_0x5f35e2;await this[_0x747d9(0x10a)](String(_0x5bc9ea),_0x1f5389);}});}catch(_0x229f25){console[_0x5f35e2(0x118)](_0x5f35e2(0x1cd)+_0x43c729(0x135)+_0x5f35e2(0x1c7)+'delivery\x20a'+_0x5f35e2(0x15a),_0x229f25);}}async[_0x502750(0x163)](){const _0x240d53=_0xf05947,_0x56d5db=_0xf05947;let _0x3350f0;try{_0x3350f0=await import(_0x240d53(0x1f4)+_0x56d5db(0x1df)+_0x240d53(0x1c2));}catch{const _0x4e3792=_0x240d53(0x1f4)+_0x56d5db(0x1df)+_0x56d5db(0x11e)+'stalled.\x20R'+_0x240d53(0x1e9)+_0x240d53(0x1e2)+'skeysocket'+_0x56d5db(0x20e);_whatsappState={..._whatsappState,'status':_0x240d53(0x1dc),'error':_0x4e3792},console[_0x56d5db(0x1dc)](_0x56d5db(0x190)+':\x20'+_0x4e3792);throw new Error(_0x4e3792);}const {default:_0x16d6bd,useMultiFileAuthState:_0x40fb3d,DisconnectReason:_0x287003,fetchLatestBaileysVersion:_0x3ea889,makeCacheableSignalKeyStore:_0x599564,Browsers:_0x5d94c3,getContentType:_0x5ab2bf,downloadMediaMessage:_0x451915}=_0x3350f0,_0x3e5a88=(await import(_0x56d5db(0x113)))[_0x240d53(0x1b5)],{Boom:_0x3eda36}=await import(_0x240d53(0x11f)),_0x4cb355=_0x3e5a88({'level':_0x240d53(0x18e)}),_0x469ecf=join(_0x3c97ce,_0x56d5db(0x136)+'th');if(!_0x3e0052[_0x56d5db(0x1d7)](_0x469ecf))_0x3e0052['mkdirSync'](_0x469ecf,{'recursive':!![]});const {state:_0x2c2f4e,saveCreds:_0x187fa3}=await _0x40fb3d(_0x469ecf),{version:_0x47be53}=await _0x3ea889();if(this[_0x56d5db(0x1af)]){try{this[_0x56d5db(0x1af)]['ev']?.[_0x240d53(0x15d)+'isteners']?.(),this[_0x240d53(0x1af)]['end']?.(new Error(_0x56d5db(0x159)));}catch{}this[_0x240d53(0x1af)]=null;}const _0x5d9bd9=_0x16d6bd({'version':_0x47be53,'auth':{'creds':_0x2c2f4e['creds'],'keys':_0x599564(_0x2c2f4e[_0x240d53(0x153)],_0x4cb355)},'logger':_0x4cb355,'printQRInTerminal':![],'browser':_0x5d94c3[_0x56d5db(0x1db)](_0x240d53(0x10b)),'markOnlineOnConnect':![],'generateHighQualityLinkPreview':![]});this[_0x56d5db(0x1af)]=_0x5d9bd9;const _0x1fd2f8=makeResilientSaveCreds(_0x469ecf,_0x187fa3);_0x5d9bd9['ev']['on'](_0x56d5db(0x170)+'te',_0x1fd2f8),_0x5d9bd9['ev']['on'](_0x56d5db(0x114)+_0x240d53(0x174),_0x5f0b74=>{const _0x175a6a=_0x56d5db,_0x18b499=_0x240d53,{connection:_0x534700,lastDisconnect:_0x1e87a4,qr:_0x148a79}=_0x5f0b74;_0x148a79&&(_whatsappState[_0x175a6a(0x126)]='qr',_whatsappState['qrString']=_0x148a79,_whatsappState[_0x175a6a(0x1c5)+'p']=Date['now'](),_whatsappState['error']=null,console[_0x175a6a(0x177)](_0x18b499(0x10c)+_0x175a6a(0x1dd)+'ready\x20—\x20sc'+'an\x20via\x20Web'+_0x18b499(0x156)+_0x18b499(0x1e8)));if(_0x534700===_0x175a6a(0x145)){_whatsappState[_0x18b499(0x126)]='connected',_whatsappState[_0x18b499(0x130)]=null,_whatsappState['connectedA'+'t']=Date[_0x18b499(0x1f5)](),_whatsappState[_0x175a6a(0x1dc)]=null,_whatsappState[_0x175a6a(0x154)]=_0x5d9bd9[_0x175a6a(0x178)]?.[_0x18b499(0x1a9)]||_0x5d9bd9[_0x18b499(0x178)]?.['id']||null,this[_0x175a6a(0x164)+'ttempt']=0x24d*0x1+0x7c3*-0x1+0x6*0xe9,console[_0x18b499(0x177)](_0x175a6a(0x10c)+_0x18b499(0x19f)+'\x20('+(_whatsappState[_0x175a6a(0x154)]||'unknown')+')');const _0x647049=_0x5d9bd9[_0x18b499(0x178)]?.['id'];_0x647049&&_0x5d9bd9[_0x18b499(0x157)+'e'](_0x647049,{'text':_0x175a6a(0x197)+_0x18b499(0x1f9)+'connected\x20'+_0x175a6a(0x1ae)+_0x175a6a(0x124)+_0x18b499(0x1a2)+_0x18b499(0x186)+_0x18b499(0x17c)+_0x175a6a(0x1d3)+_0x175a6a(0x116)+'.'})['catch'](()=>{});}if(_0x534700===_0x18b499(0x172)){const _0x4cb243=_0x1e87a4?.[_0x175a6a(0x1dc)]?.[_0x18b499(0x1ab)]?.['statusCode'];if(_0x4cb243===_0x287003[_0x175a6a(0x1ec)])_whatsappState[_0x175a6a(0x126)]=_0x175a6a(0x1c9),_whatsappState[_0x18b499(0x1dc)]=_0x175a6a(0x14a)+_0x18b499(0x1b6)+_0x175a6a(0x1f1)+_0x175a6a(0x1be),console[_0x175a6a(0x177)](_0x175a6a(0x10c)+_0x18b499(0x12f)+'ut'),_0x3e0052['rmSync'](_0x469ecf,{'recursive':!![],'force':!![]});else{if(this[_0x175a6a(0x164)+_0x175a6a(0x18a)]<this[_0x18b499(0x1b8)+_0x18b499(0x19d)]){this[_0x18b499(0x164)+'ttempt']++;const _0xba79a0=Math[_0x175a6a(0x1d2)]((-0x1*-0x2077+-0xf3a+-0x585)*this[_0x18b499(0x164)+_0x175a6a(0x18a)],0xc2dc+-0xbec8+0x711c);_whatsappState['status']=_0x175a6a(0x11b),_whatsappState[_0x175a6a(0x1dc)]='Reconnecti'+_0x175a6a(0x12c)+'t\x20'+this[_0x18b499(0x164)+_0x18b499(0x18a)]+_0x18b499(0x133),console[_0x175a6a(0x177)]('📱\x20WhatsApp'+':\x20Reconnec'+'ting\x20in\x20'+_0xba79a0/(0x887+-0x101*-0x12+-0x9d*0x25)+(_0x175a6a(0x1ba)+'\x20')+this['reconnectA'+_0x18b499(0x18a)]+')'),setTimeout(()=>this[_0x175a6a(0x163)]()[_0x18b499(0x1b1)](console[_0x175a6a(0x1dc)]),_0xba79a0);}else _whatsappState['status']=_0x18b499(0x1dc),_whatsappState[_0x175a6a(0x1dc)]=_0x175a6a(0x1ac)+_0x18b499(0x13b)+_0x18b499(0x16d),console[_0x175a6a(0x1dc)](_0x175a6a(0x190)+_0x175a6a(0x140)+_0x18b499(0x209)+_0x18b499(0x129)+'ed');}}}),_0x5d9bd9['ev']['on'](_0x56d5db(0x17d)+_0x56d5db(0x1bb),_0x16d721=>{const _0x1704af=_0x240d53,_0x4246e6=_0x56d5db;for(const _0x3efb69 of _0x16d721){_0x3efb69['id']&&(_0x3efb69[_0x1704af(0x122)]||_0x3efb69['name'])&&cacheContactName(_0x3efb69['id'],_0x3efb69[_0x1704af(0x122)]||_0x3efb69[_0x4246e6(0x1a9)]);}}),_0x5d9bd9['ev']['on'](_0x56d5db(0x17d)+'pdate',_0x15cbe9=>{const _0x21df84=_0x240d53,_0x2e8af3=_0x240d53;for(const _0x21332c of _0x15cbe9){_0x21332c['id']&&(_0x21332c[_0x21df84(0x122)]||_0x21332c['name'])&&cacheContactName(_0x21332c['id'],_0x21332c[_0x21df84(0x122)]||_0x21332c['name']);}}),_0x5d9bd9['ev']['on'](_0x240d53(0x1a5)+_0x56d5db(0x1bb),async({messages:_0x17c9b9,type:_0x171f5c})=>{const _0x4d2a27=_0x56d5db,_0x1d24ad=_0x240d53;if(_0x171f5c!==_0x4d2a27(0x122))return;for(const _0xee744b of _0x17c9b9){if(_0xee744b[_0x1d24ad(0x173)]&&_0xee744b[_0x1d24ad(0x151)]?.['participan'+'t'])cacheContactName(_0xee744b['key'][_0x4d2a27(0x1cb)+'t'],_0xee744b[_0x4d2a27(0x173)]);else _0xee744b[_0x4d2a27(0x173)]&&_0xee744b[_0x4d2a27(0x151)]?.['remoteJid']&&!_0xee744b[_0x4d2a27(0x151)]['remoteJid'][_0x1d24ad(0x144)](_0x4d2a27(0x20d))&&cacheContactName(_0xee744b[_0x1d24ad(0x151)]['remoteJid'],_0xee744b[_0x4d2a27(0x173)]);try{await this[_0x4d2a27(0x127)+_0x4d2a27(0x1ed)+'e'](_0xee744b,_0x5d9bd9,_0x5ab2bf,_0x451915);}catch(_0x30f5c1){console[_0x4d2a27(0x1dc)](_0x4d2a27(0x119)+'essage\x20han'+'dler\x20error'+':',_0x30f5c1 instanceof Error?_0x30f5c1[_0x4d2a27(0x17f)]:_0x30f5c1);}}});}async[_0x502750(0x127)+_0xf05947(0x1ed)+'e'](_0x2c3e94,_0x5708bf,_0xc2fd4d,_0x243510){const _0x7b5282=_0x502750,_0x218402=_0xf05947;if(!this['handler'])return;if(!_0x2c3e94['message'])return;const _0x360f2a=_0x2c3e94[_0x7b5282(0x151)][_0x7b5282(0x11d)];if(!_0x360f2a)return;if(_0x360f2a[_0x218402(0x144)](_0x218402(0x17a)+'r')||_0x360f2a['endsWith'](_0x7b5282(0x10e))||_0x360f2a==='status@bro'+_0x218402(0x16c))return;const _0x5511dd=_0xc2fd4d(_0x2c3e94['message']);if(!_0x5511dd)return;const _0x54a8cf=(_0x2c3e94[_0x218402(0x17f)]['conversati'+'on']||_0x2c3e94[_0x7b5282(0x17f)][_0x218402(0x1e6)+_0x218402(0x199)]?.['text']||_0x2c3e94['message'][_0x7b5282(0x143)+'ge']?.[_0x218402(0x1c4)]||_0x2c3e94[_0x7b5282(0x17f)][_0x7b5282(0x1c6)+'ge']?.[_0x218402(0x1c4)]||_0x2c3e94[_0x7b5282(0x17f)][_0x218402(0x1f8)+_0x7b5282(0x123)]?.[_0x218402(0x1c4)]||'')['trim'](),_0x28c2f2=_0x5511dd===_0x218402(0x137)+'ge'&&_0x2c3e94[_0x7b5282(0x17f)][_0x7b5282(0x137)+'ge']?.['ptt']===!![],_0x90f30b=_0x5511dd==='audioMessa'+'ge'&&!_0x2c3e94[_0x218402(0x17f)][_0x218402(0x137)+'ge']?.['ptt'],_0x22f1fd=_0x5511dd==='imageMessa'+'ge'||_0x5511dd===_0x218402(0x19b)+_0x7b5282(0x1ce),_0x93df14=_0x5511dd==='documentMe'+'ssage',_0x11bc3f=_0x5511dd===_0x7b5282(0x1c6)+'ge',_0x4c36b7=_0x28c2f2||_0x90f30b||_0x22f1fd||_0x93df14||_0x11bc3f;if(!_0x54a8cf&&!_0x4c36b7)return;const _0x5b4ce3=_0x2c3e94[_0x218402(0x151)]['id']||'';if(this[_0x218402(0x10d)][_0x218402(0x134)](_0x5b4ce3)){this[_0x218402(0x10d)]['delete'](_0x5b4ce3);return;}const _0x3ad3d0=_0x2c3e94[_0x218402(0x151)]['fromMe']===!![],_0x3e80ae=_0x360f2a[_0x218402(0x144)](_0x7b5282(0x20d)),_0x58068b=this['isSelfChat'](_0x360f2a);if(_0x3ad3d0&&!_0x58068b)return;if(_0x3ad3d0&&_0x54a8cf&&this[_0x7b5282(0x16b)+'ts'][_0x218402(0x134)](_0x54a8cf[_0x218402(0x182)](-0x1c9f*0x1+-0x204f+0x1e77*0x2,0x1*0x465+0x17f8+0xe7*-0x1f)))return;const _0x7f557=process[_0x7b5282(0x194)][_0x7b5282(0x14b)+_0x218402(0x1a8)+_0x218402(0x1eb)]===_0x218402(0x149),_0x47ae23=process[_0x7b5282(0x194)][_0x218402(0x1ff)+'LLOW_GROUP'+'S']===_0x218402(0x149);if(_0x58068b){if(_0x54a8cf&&_approvalChannel==='whatsapp'&&_pendingApprovals[_0x7b5282(0x1e0)]>0x262e+0xea5+-0x34d3){const _0x123042=matchApprovalResponse(_0x54a8cf);if(_0x123042){const _0x576bc6=removePendingApproval(_0x123042['id']);if(_0x576bc6){if(_0x123042[_0x7b5282(0x208)]){await this[_0x7b5282(0x10a)](_0x360f2a,'✅\x20Approved'+':\x20'+_0x576bc6[_0x7b5282(0x1c0)]+_0x7b5282(0x1b7)+_0x576bc6[_0x7b5282(0x125)]);if(this['handler'])await this[_0x218402(0x120)](_0x576bc6[_0x218402(0x1e4)]);}else{await this[_0x218402(0x10a)](_0x360f2a,_0x7b5282(0x1b4)+_0x218402(0x1d9)+_0x576bc6[_0x218402(0x1c0)]);if(_0x576bc6[_0x218402(0x1e4)][_0x7b5282(0x188)]?.[_0x218402(0x13c)])_0x3e0052['unlink'](_0x576bc6[_0x218402(0x1e4)]['media'][_0x218402(0x13c)],()=>{});}return;}}}}else{if(_0x3e80ae){if(_0x7f557||!_0x47ae23)return;const _0x443f27=getGroupRule(_0x360f2a);if(!_0x443f27||!_0x443f27[_0x7b5282(0x179)])return;const _0x306886=_0x2c3e94[_0x218402(0x151)][_0x218402(0x1cb)+'t']||'';if(_0x443f27[_0x7b5282(0x18f)+_0x218402(0x12a)]['length']>0x1a*0x1d+-0x10aa+0xdb8){const _0x4b8d86=jidToNumber(_0x306886),_0x1884d4=_0x443f27[_0x7b5282(0x18f)+_0x7b5282(0x12a)][_0x7b5282(0x18c)](_0x1b3a45=>jidToNumber(_0x1b3a45)===_0x4b8d86);if(!_0x1884d4)return;}if(_0x443f27[_0x218402(0x200)+_0x218402(0x205)]){const _0x3b4e3b=_0x5708bf['user']?.[_0x218402(0x1a9)]||_0x7b5282(0x10b),_0xf47fff=_0x5708bf[_0x7b5282(0x178)]?.['id']||'',_0x3f14bd=_0x2c3e94[_0x218402(0x17f)][_0x7b5282(0x1e6)+_0x218402(0x199)]?.[_0x7b5282(0x147)+'o']?.[_0x218402(0x15e)+'id']||[],_0x15a63a=_0x3f14bd[_0x218402(0x18c)](_0x23066f=>normalizeJid(_0x23066f)===normalizeJid(_0xf47fff)),_0x34a8de=_0x54a8cf&&(_0x54a8cf[_0x218402(0x1bc)+'e']()[_0x218402(0x12d)](_0x7b5282(0x1ad))||_0x54a8cf[_0x7b5282(0x1bc)+'e']()['includes'](_0x218402(0x142))||_0x54a8cf[_0x218402(0x1bc)+'e']()[_0x7b5282(0x12d)](_0x3b4e3b[_0x7b5282(0x1bc)+'e']()));if(!_0x15a63a&&!_0x34a8de&&!_0x4c36b7)return;}if(_0x4c36b7&&!_0x443f27[_0x7b5282(0x1cf)]&&!_0x54a8cf)return;}else{if(_0x7f557)return;if(process['env'][_0x218402(0x1ff)+_0x218402(0x1fc)]!==_0x218402(0x149))return;}}let _0x4154ac=undefined;if(_0x4c36b7)try{const _0xc6d9ec=await _0x243510(_0x2c3e94,_0x218402(0x141),{},{'reuploadRequest':_0x5708bf[_0x218402(0x1e5)+_0x7b5282(0x20f)]});if(!_0x3e0052[_0x218402(0x1d7)](WA_MEDIA_DIR))_0x3e0052['mkdirSync'](WA_MEDIA_DIR,{'recursive':!![]});if(_0x28c2f2||_0x90f30b){const _0x526bd0=_0x2c3e94[_0x218402(0x17f)][_0x218402(0x137)+'ge']?.['mimetype']||_0x218402(0x183),_0x2012ce=_0x526bd0[_0x7b5282(0x12d)](_0x218402(0x165))?_0x7b5282(0x165):_0x7b5282(0x203),_0x4f27d0=join(WA_MEDIA_DIR,_0x218402(0x155)+Date[_0x7b5282(0x1f5)]()+'.'+_0x2012ce);_0x3e0052[_0x218402(0x169)+'ync'](_0x4f27d0,_0xc6d9ec),_0x4154ac={'type':_0x7b5282(0x1c8),'path':_0x4f27d0,'mimeType':_0x526bd0};}else{if(_0x22f1fd){const _0x1d26d4=_0x2c3e94[_0x218402(0x17f)]['imageMessa'+'ge']?.['mimetype']||_0x2c3e94[_0x7b5282(0x17f)][_0x7b5282(0x19b)+_0x218402(0x1ce)]?.['mimetype']||'image/jpeg',_0x3e7adf=_0x1d26d4['includes'](_0x218402(0x161))?_0x7b5282(0x161):_0x1d26d4[_0x218402(0x12d)](_0x218402(0x1b9))?_0x7b5282(0x1b9):_0x218402(0x162),_0x4bb86a=join(WA_MEDIA_DIR,'wa_photo_'+Date[_0x7b5282(0x1f5)]()+'.'+_0x3e7adf);_0x3e0052[_0x7b5282(0x169)+_0x7b5282(0x11c)](_0x4bb86a,_0xc6d9ec),_0x4154ac={'type':'photo','path':_0x4bb86a,'mimeType':_0x1d26d4};}else{if(_0x93df14){const _0x2ad106=_0x2c3e94['message'][_0x7b5282(0x1f8)+_0x218402(0x123)]?.[_0x7b5282(0x176)]||_0x218402(0x1b2)+Date[_0x7b5282(0x1f5)](),_0x3f1c73=_0x2c3e94[_0x7b5282(0x17f)][_0x218402(0x1f8)+'ssage']?.[_0x218402(0x19c)]||_0x218402(0x14c)+_0x7b5282(0x148)+_0x7b5282(0x180),_0x66e8d1=join(WA_MEDIA_DIR,_0x2ad106);_0x3e0052[_0x7b5282(0x169)+_0x7b5282(0x11c)](_0x66e8d1,_0xc6d9ec),_0x4154ac={'type':_0x7b5282(0x193),'path':_0x66e8d1,'mimeType':_0x3f1c73,'fileName':_0x2ad106};}else{if(_0x11bc3f){const _0xb1ca2f=_0x2c3e94['message'][_0x218402(0x1c6)+'ge']?.['mimetype']||_0x7b5282(0x12e),_0x3b3ba6=_0xb1ca2f[_0x7b5282(0x12d)]('mp4')?'mp4':_0x7b5282(0x206),_0x388d5a=join(WA_MEDIA_DIR,'wa_video_'+Date['now']()+'.'+_0x3b3ba6);_0x3e0052[_0x218402(0x169)+'ync'](_0x388d5a,_0xc6d9ec),_0x4154ac={'type':_0x218402(0x1e3),'path':_0x388d5a,'mimeType':_0xb1ca2f};}}}}}catch(_0x362dd8){console[_0x218402(0x1dc)](_0x7b5282(0x115)+_0x7b5282(0x146)+_0x218402(0x1a0)+_0x5511dd+':',_0x362dd8 instanceof Error?_0x362dd8[_0x218402(0x17f)]:_0x362dd8);}const _0x49ab03=_0x58068b?_0x5708bf[_0x7b5282(0x178)]?.[_0x218402(0x1a9)]||'User':_0x2c3e94[_0x218402(0x173)]||jidToNumber(_0x2c3e94[_0x7b5282(0x151)][_0x7b5282(0x1cb)+'t']||_0x360f2a),_0x50e0ec=_0x2c3e94['message']['extendedTe'+_0x7b5282(0x199)]?.[_0x7b5282(0x147)+'o']?.[_0x7b5282(0x18b)+_0x218402(0x132)],_0x21e0c4=_0x50e0ec?.[_0x7b5282(0x1a6)+'on']||_0x50e0ec?.[_0x7b5282(0x1e6)+'xtMessage']?.['text']||undefined,_0x31af71={'platform':_0x7b5282(0x1fb),'messageId':_0x5b4ce3,'chatId':_0x360f2a,'userId':_0x58068b?_0x7b5282(0x152):_0x2c3e94[_0x218402(0x151)][_0x7b5282(0x1cb)+'t']||_0x360f2a,'userName':_0x49ab03,'text':_0x54a8cf||'','isGroup':_0x3e80ae,'isMention':_0x3e80ae&&!!_0x54a8cf&&(_0x54a8cf[_0x7b5282(0x12d)](_0x218402(0x1ad))||_0x54a8cf[_0x218402(0x12d)](_0x7b5282(0x142))),'isReplyToBot':![],'replyToText':_0x21e0c4,'media':_0x4154ac};if(_0x3e80ae&&!_0x58068b&&!_0x3ad3d0){const _0x2b409c=getGroupRule(_0x360f2a);if(_0x2b409c?.[_0x218402(0x192)+_0x7b5282(0x185)]&&_approvalRequestFn){const _0xaf79a0=_0x218402(0x181)+Date['now']()+'_'+Math[_0x218402(0x1b0)]()[_0x218402(0x13f)](-0x2129+0x1*-0x1495+0x35e2)[_0x218402(0x204)](-0x4*-0x75a+-0x1a97*-0x1+0xb*-0x517,0x1*-0x1283+0x81*-0x13+0x1c1c);let _0x5cdd42=_0x54a8cf||'';if(_0x5cdd42['length']>-0x134e+0xbbd*-0x1+-0x1fd3*-0x1)_0x5cdd42=_0x5cdd42['slice'](-0x21f3+-0x926+0xbb*0x3b,-0x590*-0x1+0x61*-0x6+-0x3*0xd6)+'…';if(_0x4c36b7&&!_0x5cdd42){const _0x340325={'audioMessage':_0x7b5282(0x112),'imageMessage':'📷\x20Image','documentMessage':_0x218402(0x18d),'videoMessage':_0x7b5282(0x1aa),'stickerMessage':_0x7b5282(0x195)};_0x5cdd42=_0x340325[_0x5511dd||'']||_0x7b5282(0x1f2)+_0x5511dd;}else _0x4c36b7&&(_0x5cdd42='📎\x20+Media:\x20'+_0x5cdd42);const _0x36717b={'id':_0xaf79a0,'incoming':_0x31af71,'groupName':_0x360f2a,'senderName':_0x49ab03,'senderNumber':jidToNumber(_0x2c3e94[_0x7b5282(0x151)][_0x218402(0x1cb)+'t']||_0x360f2a),'preview':_0x5cdd42,'mediaType':_0x4c36b7?_0x5511dd:undefined,'timestamp':Date['now']()};_pendingApprovals[_0x218402(0x1e7)](_0xaf79a0,_0x36717b),await _approvalRequestFn(_0x36717b);return;}}await this[_0x218402(0x120)](_0x31af71);}['isSelfChat'](_0x2bb4d5){const _0xea6a21=_0xf05947,_0x84fb96=_0xf05947;if(!this['sock']?.[_0xea6a21(0x178)])return![];if(_0x2bb4d5[_0xea6a21(0x144)]('@g.us'))return![];const _0x55ea0e=this['sock'][_0x84fb96(0x178)],_0x281a8e=_0x55ea0e['id'],_0x11a9c3=_0x55ea0e[_0x84fb96(0x20a)];if(_0x281a8e){const _0x1a54ed=jidToNumber(_0x281a8e),_0x3f0428=jidToNumber(_0x2bb4d5);if(_0x1a54ed&&_0x3f0428&&_0x1a54ed===_0x3f0428)return!![];}if(_0x11a9c3&&_0x2bb4d5[_0x84fb96(0x144)](_0x84fb96(0x15f))){const _0x38b0b5=jidToNumber(_0x11a9c3),_0x2041c1=jidToNumber(_0x2bb4d5);if(_0x38b0b5&&_0x2041c1&&_0x38b0b5===_0x2041c1)return!![];}return![];}async[_0xf05947(0x16e)](){const _0x24c0f2=_0x502750,_0x11fa83=_0x502750;if(!this[_0x24c0f2(0x1af)]||_whatsappState[_0x24c0f2(0x126)]!==_0x24c0f2(0x167))return[];try{const _0x56e973=await this[_0x24c0f2(0x1af)][_0x11fa83(0x111)+_0x11fa83(0x1d4)+'pating']();return Object[_0x11fa83(0x171)](_0x56e973)[_0x11fa83(0x1ca)](_0xab3139=>({'id':_0xab3139['id'],'name':_0xab3139[_0x11fa83(0x1bd)]||_0x11fa83(0x17e)+'oup','participantCount':_0xab3139['participan'+'ts']?.['length']||0x2480+0x1*-0x1419+-0x1067}))['sort']((_0x1f738a,_0x5698e3)=>_0x1f738a[_0x11fa83(0x1a9)][_0x24c0f2(0x110)+_0x24c0f2(0x1a7)](_0x5698e3[_0x11fa83(0x1a9)]));}catch(_0x218494){return console[_0x24c0f2(0x1dc)](_0x24c0f2(0x115)+_0x24c0f2(0x146)+_0x24c0f2(0x196)+_0x24c0f2(0x15b),_0x218494),[];}}async['getGroupPa'+_0xf05947(0x168)](_0x56a9a7){const _0x372098=_0xf05947,_0x162786=_0x502750;if(!this[_0x372098(0x1af)]||_whatsappState[_0x372098(0x126)]!==_0x372098(0x167))return[];try{const _0x5948e3=await this[_0x162786(0x1af)][_0x162786(0x128)+_0x372098(0x131)](_0x56a9a7),_0x4bb8be=this[_0x162786(0x1af)][_0x162786(0x178)]?.['id']||'';return(_0x5948e3[_0x372098(0x1cb)+'ts']||[])[_0x372098(0x14e)](_0x5eed44=>normalizeJid(_0x5eed44['id'])!==normalizeJid(_0x4bb8be))[_0x162786(0x1ca)](_0x5d15e7=>({'id':_0x5d15e7['id'],'name':getContactDisplayName(_0x5d15e7['id']),'isAdmin':_0x5d15e7[_0x372098(0x117)]===_0x162786(0x117)||_0x5d15e7[_0x162786(0x117)]===_0x162786(0x17b),'number':jidToNumber(_0x5d15e7['id'])}))['sort']((_0x1adedd,_0xba3284)=>_0x1adedd[_0x372098(0x1a9)]['localeComp'+_0x372098(0x1a7)](_0xba3284[_0x372098(0x1a9)]));}catch(_0x6f8fac){return console[_0x372098(0x1dc)]('WhatsApp:\x20'+_0x372098(0x146)+_0x162786(0x1de)+'icipants:',_0x6f8fac),[];}}async[_0xf05947(0x10a)](_0x5b9092,_0x11a8ce){const _0x2bb9e6=_0x502750,_0x14fe1d=_0x502750;if(!this[_0x2bb9e6(0x1af)])return;const _0x19997d=_0x11a8ce['substring'](-0xb2*-0xb+-0x214a+0x19a4,0x2*0x5cb+0x62b*-0x1+-0x507);this[_0x2bb9e6(0x16b)+'ts'][_0x2bb9e6(0x1f3)](_0x19997d),setTimeout(()=>this[_0x14fe1d(0x16b)+'ts'][_0x14fe1d(0x150)](_0x19997d),0x2e5+0x1ede+0x536d);const _0x1da40f=await this[_0x2bb9e6(0x1af)]['sendMessag'+'e'](_0x5b9092,{'text':_0x11a8ce});_0x1da40f?.[_0x2bb9e6(0x151)]?.['id']&&(this[_0x14fe1d(0x10d)]['add'](_0x1da40f[_0x2bb9e6(0x151)]['id']),setTimeout(()=>this['botSentIds'][_0x14fe1d(0x150)](_0x1da40f[_0x2bb9e6(0x151)]['id']),0x20dd+-0x3*0x8916+0x264c5));}async['sendPhoto'](_0x37f803,_0x554f51,_0x104d74){const _0x37ff12=_0x502750,_0x41d749=_0x502750;if(!this[_0x37ff12(0x1af)])return;const _0x756c25=typeof _0x554f51===_0x37ff12(0x1d0)?{'url':_0x554f51}:_0x554f51;await this[_0x37ff12(0x1af)][_0x37ff12(0x157)+'e'](_0x37f803,{'image':_0x756c25,'caption':_0x104d74});}async['sendDocume'+'nt'](_0x4c89b9,_0x4c2ec4,_0x2deeb2,_0x5c4ea4){const _0x976099=_0x502750,_0x385237=_0xf05947;if(!this[_0x976099(0x1af)])return;const _0x4b7867=typeof _0x4c2ec4===_0x385237(0x1d0)?{'url':_0x4c2ec4}:_0x4c2ec4;await this['sock'][_0x976099(0x157)+'e'](_0x4c89b9,{'document':_0x4b7867,'fileName':_0x2deeb2,'mimetype':_0x385237(0x14c)+_0x385237(0x148)+'ream','caption':_0x5c4ea4});}async['sendVoice'](_0x10a61a,_0x157281){const _0xea9e84=_0xf05947,_0x28f297=_0x502750;if(!this['sock'])return;const _0x43b2b8=typeof _0x157281===_0xea9e84(0x1d0)?{'url':_0x157281}:_0x157281;await this[_0xea9e84(0x1af)][_0xea9e84(0x157)+'e'](_0x10a61a,{'audio':_0x43b2b8,'mimetype':'audio/ogg;'+_0xea9e84(0x191)+'us','ptt':!![]});}async['react'](_0xb7d924,_0x35d46d,_0x4964cb){const _0x16086f=_0x502750;if(!this['sock'])return;await this[_0x16086f(0x1af)]['sendMessag'+'e'](_0xb7d924,{'react':{'text':_0x4964cb,'key':{'remoteJid':_0xb7d924,'id':_0x35d46d}}});}async[_0xf05947(0x13e)](_0x23b741){const _0x144370=_0x502750,_0x19535a=_0x502750;if(!this[_0x144370(0x1af)])return;try{await this[_0x19535a(0x1af)][_0x144370(0x175)+_0x144370(0x121)](_0x144370(0x1d6),_0x23b741);}catch{}}[_0x502750(0x1cc)+'atId'](){const _0x64f97a=_0x502750,_0x40ad06=_0xf05947;return this[_0x64f97a(0x1af)]?.[_0x64f97a(0x178)]?.['id']||null;}async['processApp'+_0x502750(0x1fa)+'ge'](_0x1296a1){const _0x2e0555=_0xf05947,_0x496221=_0x502750;if(!this[_0x2e0555(0x120)])return;await this[_0x2e0555(0x120)](_0x1296a1);}async[_0xf05947(0x19e)](){const _0x4ef128=_0x502750,_0x3fee56=_0x502750;if(this[_0x4ef128(0x1af)]){try{this[_0x4ef128(0x1af)][_0x3fee56(0x1bf)](undefined);}catch{}this[_0x3fee56(0x1af)]=null;}_whatsappState['status']=_0x3fee56(0x1a3)+'ed',_adapterInstance=null;}[_0xf05947(0x1f7)](_0x2c5b29){this['handler']=_0x2c5b29;}}
|