up
This commit is contained in:
+40
-1
@@ -69,7 +69,30 @@ class BotService {
|
||||
} catch (Exception $e) {
|
||||
// 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;
|
||||
}
|
||||
} catch (Throwable $t) {
|
||||
@@ -508,6 +531,22 @@ class BotService {
|
||||
// No ponemos on_hold para evitar bloqueo automático; usamos advisor_requested
|
||||
$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.");
|
||||
|
||||
// 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");
|
||||
} catch (Exception $e) {
|
||||
error_log('requestAdvisor failed: ' . $e->getMessage());
|
||||
|
||||
Reference in New Issue
Block a user