up
This commit is contained in:
@@ -35,7 +35,13 @@ class BotService {
|
||||
if ($this->processSpecialCommands($phoneNumber, $messageText)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Si el asesor ya respondió después del último mensaje del usuario, frenar al bot
|
||||
$lastIncoming = $this->db->fetch("SELECT created_at FROM conversations WHERE user_id = :uid AND direction = 'incoming' ORDER BY created_at DESC LIMIT 1", ['uid' => $user['id']]);
|
||||
$lastOutgoing = $this->db->fetch("SELECT created_at FROM conversations WHERE user_id = :uid AND direction = 'outgoing' ORDER BY created_at DESC LIMIT 1", ['uid' => $user['id']]);
|
||||
if ($lastOutgoing && $lastIncoming && strtotime($lastOutgoing['created_at']) >= strtotime($lastIncoming['created_at'])) {
|
||||
// El asesor ya respondió, no enviar respuestas automáticas
|
||||
return;
|
||||
}
|
||||
// Verificar si el usuario está en un menú
|
||||
if ($user['current_menu_id']) {
|
||||
$this->processMenuSelection($user, $messageText);
|
||||
@@ -85,7 +91,7 @@ class BotService {
|
||||
$this->exitMenu($phoneNumber);
|
||||
return true;
|
||||
|
||||
case 'help':
|
||||
case 'asesor':
|
||||
case 'ayuda':
|
||||
$this->showHelp($phoneNumber);
|
||||
return true;
|
||||
|
||||
@@ -514,6 +514,17 @@ class WhatsAppService
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
|
||||
// Si es reply (context)
|
||||
if (isset($data['context']['message_id'])) {
|
||||
$messageData['reply_to_message_id'] = is_numeric($data['context']['message_id']) ? intval($data['context']['message_id']) : null;
|
||||
}
|
||||
|
||||
// Si es reaction
|
||||
if ($data['type'] === 'reaction' && isset($data['reaction'])) {
|
||||
$messageData['reaction_to_message_id'] = is_numeric($data['reaction']['message_id'] ?? null) ? intval($data['reaction']['message_id']) : null;
|
||||
$messageData['reaction_emoji'] = $data['reaction']['emoji'] ?? null;
|
||||
}
|
||||
|
||||
$this->db->insert('conversations', $messageData);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
Reference in New Issue
Block a user