Update BotService.php
This commit is contained in:
+1
-39
@@ -69,30 +69,7 @@ class BotService {
|
|||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// ignore send errors
|
// ignore send errors
|
||||||
}
|
}
|
||||||
|
error_log("[BotService] processMessage - sent 'enviados' ack to user {$user['id']}");
|
||||||
// Marcar para atención humana y crear un system message para que el asesor lo vea
|
|
||||||
try {
|
|
||||||
$this->db->update('users', ['advisor_requested' => 1], 'phone_number = :phone', ['phone' => $phoneNumber]);
|
|
||||||
|
|
||||||
$sys = [
|
|
||||||
'system' => 'attention',
|
|
||||||
'type' => 'user_sent_documents',
|
|
||||||
'text' => 'El usuario indicó que ha enviado documentos o información; requiere atención.'
|
|
||||||
];
|
|
||||||
|
|
||||||
$this->db->insert('conversations', [
|
|
||||||
'user_id' => $user['id'],
|
|
||||||
'direction' => 'incoming',
|
|
||||||
'message_type' => 'text',
|
|
||||||
'content' => json_encode($sys),
|
|
||||||
'status' => 'received',
|
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log('[BotService] failed to mark advisor_requested on envio: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
error_log("[BotService] processMessage - sent 'enviados' ack to user {$user['id']} and marked advisor_requested");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} catch (Throwable $t) {
|
} catch (Throwable $t) {
|
||||||
@@ -532,21 +509,6 @@ class BotService {
|
|||||||
$this->db->update('users', ['advisor_requested' => 1, 'bot_paused_until' => $pausedUntil], 'phone_number = :phone', ['phone' => $phoneNumber]);
|
$this->db->update('users', ['advisor_requested' => 1, 'bot_paused_until' => $pausedUntil], 'phone_number = :phone', ['phone' => $phoneNumber]);
|
||||||
$this->whatsappService->sendTextMessage($phoneNumber, "🔔 Te hemos transferido con un asesor, te responderemos en breve.");
|
$this->whatsappService->sendTextMessage($phoneNumber, "🔔 Te hemos transferido con un asesor, te responderemos en breve.");
|
||||||
|
|
||||||
// Crear un mensaje 'system' en la conversación para que el equipo lo detecte fácilmente
|
|
||||||
try {
|
|
||||||
$user = $this->db->fetch('SELECT id FROM users WHERE phone_number = :phone', ['phone' => $phoneNumber]);
|
|
||||||
$this->db->insert('conversations', [
|
|
||||||
'user_id' => $user['id'] ?? null,
|
|
||||||
'direction' => 'incoming',
|
|
||||||
'message_type' => 'text',
|
|
||||||
'content' => json_encode(['system' => 'advisor_request', 'text' => 'Usuario solicitó asesor']),
|
|
||||||
'status' => 'received',
|
|
||||||
'created_at' => date('Y-m-d H:i:s')
|
|
||||||
]);
|
|
||||||
} catch (Exception $e) {
|
|
||||||
error_log('[BotService] requestAdvisor - failed to insert system message: ' . $e->getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (function_exists('writeLog')) writeLog('INFO', "Advisor solicited for $phoneNumber until $pausedUntil");
|
if (function_exists('writeLog')) writeLog('INFO', "Advisor solicited for $phoneNumber until $pausedUntil");
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
error_log('requestAdvisor failed: ' . $e->getMessage());
|
error_log('requestAdvisor failed: ' . $e->getMessage());
|
||||||
|
|||||||
Reference in New Issue
Block a user