feat: integrate WAHA WhatsApp notifications for tasks, notes, and passwords with admin configuration settings
This commit is contained in:
@@ -7,6 +7,9 @@ try {
|
||||
$pdo->exec("CREATE TABLE IF NOT EXISTS system_config (k TEXT PRIMARY KEY, v TEXT)");
|
||||
$pdo->exec("INSERT OR IGNORE INTO system_config (k, v) VALUES ('completed_days', '7')");
|
||||
$pdo->exec("INSERT OR IGNORE INTO system_config (k, v) VALUES ('archived_days', '90')");
|
||||
$pdo->exec("INSERT OR IGNORE INTO system_config (k, v) VALUES ('waha_endpoint', '')");
|
||||
$pdo->exec("INSERT OR IGNORE INTO system_config (k, v) VALUES ('waha_chat_id', '')");
|
||||
$pdo->exec("INSERT OR IGNORE INTO system_config (k, v) VALUES ('waha_template', '')");
|
||||
} catch(Exception $e) {}
|
||||
|
||||
// ── Handle POST ───────────────────────────────────────────────────────────────
|
||||
@@ -83,8 +86,11 @@ if($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
|
||||
if(isset($_POST['update_sys_config'])) {
|
||||
$stmt = $pdo->prepare("UPDATE system_config SET v=? WHERE k=?");
|
||||
$stmt->execute([$_POST['completed_days'], 'completed_days']);
|
||||
$stmt->execute([$_POST['archived_days'], 'archived_days']);
|
||||
$stmt->execute([$_POST['completed_days'] ?? 7, 'completed_days']);
|
||||
$stmt->execute([$_POST['archived_days'] ?? 90, 'archived_days']);
|
||||
$stmt->execute([$_POST['waha_endpoint'] ?? '', 'waha_endpoint']);
|
||||
$stmt->execute([$_POST['waha_chat_id'] ?? '', 'waha_chat_id']);
|
||||
$stmt->execute([$_POST['waha_template'] ?? '', 'waha_template']);
|
||||
$success_msg = "System configuration saved!";
|
||||
}
|
||||
}
|
||||
@@ -94,6 +100,9 @@ $users = query("SELECT id, username, is_admin, notify_channels, telegram_id, ema
|
||||
$all_groups = query("SELECT * FROM groups ORDER BY name")->fetchAll();
|
||||
$conf_comp = query("SELECT v FROM system_config WHERE k='completed_days'")->fetchColumn() ?: 7;
|
||||
$conf_arch = query("SELECT v FROM system_config WHERE k='archived_days'")->fetchColumn() ?: 90;
|
||||
$waha_endpoint = query("SELECT v FROM system_config WHERE k='waha_endpoint'")->fetchColumn() ?: '';
|
||||
$waha_chat_id = query("SELECT v FROM system_config WHERE k='waha_chat_id'")->fetchColumn() ?: '';
|
||||
$waha_template = query("SELECT v FROM system_config WHERE k='waha_template'")->fetchColumn() ?: '';
|
||||
|
||||
// Activity stats for admin
|
||||
$total_users = count($users);
|
||||
@@ -436,6 +445,31 @@ $active_tab = $_GET['tab'] ?? 'overview';
|
||||
</div>
|
||||
<button type="submit" name="update_sys_config" class="btn" style="margin-top:1.25rem;"><i class="fa fa-save"></i> Save Configuration</button>
|
||||
</form>
|
||||
<h3 style="font-size:1rem; font-weight:700; margin-bottom:0.5rem; margin-top:2rem;"><i class="fab fa-whatsapp"></i> WAHA WhatsApp Notifications</h3>
|
||||
<p style="font-size:0.85rem; color:var(--text-light); margin-bottom:1.5rem;">Configure centralized WhatsApp notifications globally via WAHA (WhatsApp HTTP API).</p>
|
||||
<form method="POST">
|
||||
<input type="hidden" name="completed_days" value="<?= htmlspecialchars($conf_comp) ?>">
|
||||
<input type="hidden" name="archived_days" value="<?= htmlspecialchars($conf_arch) ?>">
|
||||
|
||||
<div style="display:grid; grid-template-columns:1fr; gap:1.5rem; max-width:600px;">
|
||||
<div class="form-group" style="margin:0;">
|
||||
<label>WAHA Endpoint URL</label>
|
||||
<input type="text" name="waha_endpoint" value="<?= htmlspecialchars($waha_endpoint) ?>" class="form-control" placeholder="http://localhost:3000/api/sendText">
|
||||
<div style="font-size:0.75rem; color:var(--text-light); margin-top:4px;">The full /api/sendText HTTP API endpoint where WAHA is hosted. Leave blank to disable WhatsApp Notification feature.</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin:0;">
|
||||
<label>Default Chat ID</label>
|
||||
<input type="text" name="waha_chat_id" value="<?= htmlspecialchars($waha_chat_id) ?>" class="form-control" placeholder="1234567890@c.us or group-id@g.us">
|
||||
<div style="font-size:0.75rem; color:var(--text-light); margin-top:4px;">The centralized group or destination ID.</div>
|
||||
</div>
|
||||
<div class="form-group" style="margin:0;">
|
||||
<label>Message Template</label>
|
||||
<textarea name="waha_template" class="form-control" rows="3" placeholder="*System Alert:* {action} on {module} '{item}' by {user}"><?= htmlspecialchars($waha_template) ?></textarea>
|
||||
<div style="font-size:0.75rem; color:var(--text-light); margin-top:4px;">Available Variables: <code>{action}</code>, <code>{module}</code>, <code>{item}</code>, <code>{user}</code></div>
|
||||
</div>
|
||||
</div>
|
||||
<button type="submit" name="update_sys_config" class="btn" style="margin-top:1.25rem;"><i class="fa fa-save"></i> Save WAHA Configuration</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- Danger Zone -->
|
||||
|
||||
Reference in New Issue
Block a user