UP
This commit is contained in:
@@ -0,0 +1,21 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config/config.php';
|
||||||
|
require_once __DIR__ . '/../services/BotService.php';
|
||||||
|
$db = Database::getInstance();
|
||||||
|
$phone = '573010000010';
|
||||||
|
// ensure user
|
||||||
|
$user = $db->fetch('SELECT * FROM users WHERE phone_number = ?', [$phone]);
|
||||||
|
if (!$user) {
|
||||||
|
$id = $db->insert('users', ['phone_number' => $phone, 'status' => 'active', 'created_at' => date('Y-m-d H:i:s')]);
|
||||||
|
$user = $db->fetch('SELECT * FROM users WHERE id = ?', [$id]);
|
||||||
|
}
|
||||||
|
$bot = new BotService();
|
||||||
|
|
||||||
|
echo "User id: {$user['id']} phone: {$phone}\n";
|
||||||
|
|
||||||
|
// Simulate sending 'INFORMACION ENVIADA' (uppercase + phrase)
|
||||||
|
echo "--- Sending 'INFORMACION ENVIADA' ---\n";
|
||||||
|
$bot->processMessage($user, 'INFORMACION ENVIADA', 'text');
|
||||||
|
// show last conversation entries
|
||||||
|
$rows = $db->fetchAll('SELECT * FROM conversations WHERE user_id = ? ORDER BY created_at DESC LIMIT 5', [$user['id']]);
|
||||||
|
print_r($rows);
|
||||||
+18
-1
@@ -38,6 +38,23 @@ class BotService {
|
|||||||
$this->sendWelcomeMessage($phoneNumber);
|
$this->sendWelcomeMessage($phoneNumber);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Si el usuario escribe 'enviado' o 'enviados' en cualquier momento, enviar confirmación de recepción
|
||||||
|
try {
|
||||||
|
// Support masculino/femenino, singular/plural: enviado, enviada, enviados, enviadas
|
||||||
|
if (preg_match('/\b(enviad[oa]s?)\b/iu', $messageText)) {
|
||||||
|
$ack = "Estaremos procesando su solicitud y confirmaremos en unos minutos";
|
||||||
|
try {
|
||||||
|
$this->whatsappService->sendTextMessage($phoneNumber, $ack);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
// ignore send errors
|
||||||
|
}
|
||||||
|
error_log("[BotService] processMessage - sent 'enviados' ack to user {$user['id']}");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} catch (Throwable $t) {
|
||||||
|
// ignore regex errors
|
||||||
|
}
|
||||||
|
|
||||||
// Procesar comandos especiales
|
// Procesar comandos especiales
|
||||||
if ($this->processSpecialCommands($phoneNumber, $messageText)) {
|
if ($this->processSpecialCommands($phoneNumber, $messageText)) {
|
||||||
@@ -470,7 +487,7 @@ class BotService {
|
|||||||
$pausedUntil = date('Y-m-d H:i:s', strtotime("+{$minutes} minutes"));
|
$pausedUntil = date('Y-m-d H:i:s', strtotime("+{$minutes} minutes"));
|
||||||
// No ponemos on_hold para evitar bloqueo automático; usamos advisor_requested
|
// 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->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. Si no hay respuesta, podrás volver a usar *menu* después de {$minutes} minutos.");
|
$this->whatsappService->sendTextMessage($phoneNumber, "🔔 Te hemos transferido con un asesor, te responderemos en breve.");
|
||||||
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