From ddc9a68a4000b4b322a9ee7aa44c2a81baf5d724 Mon Sep 17 00:00:00 2001
From: lizandrogd <77708265+lizandrogd@users.noreply.github.com>
Date: Wed, 21 Jan 2026 15:12:15 -0500
Subject: [PATCH] up
---
api/release_hold.php | 14 +++++++++++---
conversations.php | 25 +++++++++++++++++++++++--
index.php | 2 +-
services/BotService.php | 16 ++++++++++++++++
4 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/api/release_hold.php b/api/release_hold.php
index be7a4c1..6871354 100644
--- a/api/release_hold.php
+++ b/api/release_hold.php
@@ -20,9 +20,17 @@ try {
exit;
}
- $db->update('users', ['on_hold' => 0], 'id = :id', ['id' => $userId]);
-
- echo json_encode(['success' => true]);
+ // Use BotService to release hold (sends notification and clears flags)
+ try {
+ require_once __DIR__ . '/../services/BotService.php';
+ $bot = new BotService();
+ $bot->releaseHold($user['phone_number']);
+ echo json_encode(['success' => true]);
+ } catch (Exception $e) {
+ // Fallback to direct DB update if BotService fails
+ $db->update('users', ['on_hold' => 0, 'advisor_requested' => 0, 'bot_paused_until' => null], 'id = :id', ['id' => $userId]);
+ echo json_encode(['success' => true, 'warning' => 'BotService failed, flags cleared directly']);
+ }
} catch (Exception $e) {
http_response_code(500);
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
diff --git a/conversations.php b/conversations.php
index 6a23b94..4db4910 100644
--- a/conversations.php
+++ b/conversations.php
@@ -843,11 +843,23 @@
const releaseBtn = document.getElementById('release-hold-btn');
if (holdIndicator) {
- holdIndicator.style.display = conv.on_hold ? 'inline' : 'none';
+ // Show different labels depending on state
+ if (conv.on_hold) {
+ holdIndicator.textContent = 'EN ESPERA';
+ holdIndicator.style.color = '#b85';
+ holdIndicator.style.display = 'inline';
+ } else if (conv.advisor_requested) {
+ holdIndicator.textContent = 'SOLICITUD PENDIENTE';
+ holdIndicator.style.color = '#f39c12';
+ holdIndicator.style.display = 'inline';
+ } else {
+ holdIndicator.style.display = 'none';
+ }
}
if (releaseBtn) {
- releaseBtn.style.display = conv.on_hold ? 'inline-block' : 'none';
+ // show button when on_hold or advisor_requested
+ releaseBtn.style.display = (conv.on_hold || conv.advisor_requested) ? 'inline-block' : 'none';
releaseBtn.onclick = async () => {
try {
const resp = await fetch('api/release_hold.php', {
@@ -855,9 +867,14 @@
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ user_id: userId })
});
+ if (resp.status === 401) {
+ alert('Sesión expirada. Por favor inicie sesión de nuevo.');
+ return;
+ }
const json = await resp.json();
if (json && json.success) {
conv.on_hold = false;
+ conv.advisor_requested = 0;
holdIndicator.style.display = 'none';
releaseBtn.style.display = 'none';
await this.loadConversations();
@@ -866,6 +883,10 @@
}
} catch (e) {
console.error('Error releasing hold', e);
+ alert('Error liberando espera');
+ }
+ };
+ }
}
};
}
diff --git a/index.php b/index.php
index 3b82e2f..cb3c0d7 100644
--- a/index.php
+++ b/index.php
@@ -653,7 +653,7 @@ try {
-
+