up
This commit is contained in:
+42
-1
@@ -138,7 +138,7 @@ class BotService {
|
||||
} else {
|
||||
// Opcional: informar que el asesor ya respondió y no podemos enviar automáticas
|
||||
try {
|
||||
$this->whatsappService->sendTextMessage($phoneNumber, "🔕 Un asesor ya ha intervenido en la conversación, por favor espera su respuesta o utiliza *menu* para ver opciones.");
|
||||
//$this->whatsappService->sendTextMessage($phoneNumber, "🔕 Un asesor ya ha intervenido en la conversación, por favor espera su respuesta o utiliza *menu* para ver opciones.");
|
||||
} catch (Exception $e) {
|
||||
// ignore
|
||||
}
|
||||
@@ -504,6 +504,47 @@ class BotService {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Marcar la conversación como "en servicio" por un operador (Atender)
|
||||
*/
|
||||
public function attendConversation($phoneNumber, $operatorId = null) {
|
||||
try {
|
||||
$now = date('Y-m-d H:i:s');
|
||||
$update = ['in_service' => 1, 'in_service_at' => $now, 'advisor_requested' => 0];
|
||||
if ($operatorId) $update['in_service_by'] = $operatorId;
|
||||
$this->db->update('users', $update, 'phone_number = :phone', ['phone' => $phoneNumber]);
|
||||
|
||||
// Notificar al usuario
|
||||
try {
|
||||
$this->whatsappService->sendTextMessage($phoneNumber, "🔔 Un asesor está atendiendo tu conversación. Por favor, espera su respuesta.");
|
||||
} catch (Exception $e) {
|
||||
// ignore send errors
|
||||
}
|
||||
|
||||
// Registrar actividad del operador si hay información disponible
|
||||
$user = $this->db->fetch('SELECT id FROM users WHERE phone_number = :phone', ['phone' => $phoneNumber]);
|
||||
$userId = $user['id'] ?? null;
|
||||
$activity = [
|
||||
'user_id' => $userId,
|
||||
'operator_id' => $operatorId,
|
||||
'action' => 'attend',
|
||||
'details' => 'Operator started attending the conversation',
|
||||
'created_at' => $now
|
||||
];
|
||||
try {
|
||||
$this->db->insert('operator_activity', $activity);
|
||||
} catch (Exception $e) {
|
||||
if (function_exists('writeLog')) writeLog('WARN', 'Failed to insert operator_activity: ' . $e->getMessage());
|
||||
error_log('Failed to insert operator_activity: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
if (function_exists('writeLog')) writeLog('INFO', "Operator {$operatorId} attending conversation for {$phoneNumber}");
|
||||
} catch (Exception $e) {
|
||||
error_log('attendConversation failed: ' . $e->getMessage());
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Actualizar estado del menú del usuario
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user