";
echo "
🔨 CREANDO DATOS DE PRUEBA...
";
// Datos de usuarios de muestra - PERSONALIZA AQUÍ
$sampleUsers = [
['phone' => '+573168950803', 'name' => 'Usuario Principal']
];
$userIds = [];
foreach ($sampleUsers as $user) {
// Verificar si el usuario ya existe
$stmt = $pdo->prepare("SELECT id FROM users WHERE phone_number = ?");
$stmt->execute([$user['phone']]);
$existingUser = $stmt->fetch();
if ($existingUser) {
$userIds[] = $existingUser['id'];
echo "
⚠️ Usuario ya existe: {$user['name']} ({$user['phone']})
";
} else {
$stmt = $pdo->prepare("
INSERT INTO users (phone_number, name, status, created_at)
VALUES (?, ?, 'active', NOW())
");
$stmt->execute([$user['phone'], $user['name']]);
$userIds[] = $pdo->lastInsertId();
echo "
✅ Usuario creado: {$user['name']} ({$user['phone']})
";
}
}
// Crear conversaciones de muestra
$sampleconversations = [
['text' => 'Hola, necesito información sobre sus servicios', 'direction' => 'incoming'],
['text' => '¡Hola! Claro, te ayudo con gusto. ¿Qué tipo de servicio te interesa?', 'direction' => 'outgoing'],
['text' => 'Estoy buscando precios de desarrollo web', 'direction' => 'incoming'],
['text' => 'Perfecto, tenemos varios paquetes disponibles. Te envío la información.', 'direction' => 'outgoing'],
['text' => 'Gracias, muy amables', 'direction' => 'incoming'],
['text' => 'Buenos días, ¿están disponibles?', 'direction' => 'incoming'],
['text' => '¡Buenos días! Sí, estamos aquí para ayudarte. ¿En qué podemos asistirte?', 'direction' => 'outgoing'],
['text' => 'Quería hacer una consulta sobre horarios', 'direction' => 'incoming'],
['text' => 'Hola! Me pueden ayudar con un problema técnico?', 'direction' => 'incoming'],
['text' => 'Por supuesto! Cuéntanos qué problema tienes', 'direction' => 'outgoing']
];
$conversationsCreated = 0;
foreach ($userIds as $index => $userId) {
// Crear 2-3 mensajes por usuario
$messageCount = rand(2, 4);
for ($i = 0; $i < $messageCount; $i++) {
$messageIndex = ($index * $messageCount + $i) % count($sampleconversations);
$message = $sampleconversations[$messageIndex];
$messageData = [
'user_id' => $userId,
'content' => $message['text'],
'direction' => $message['direction'],
'message_type' => 'text',
'status' => $message['direction'] === 'outgoing' ? 'delivered' : 'sent',
'created_at' => date('Y-m-d H:i:s', strtotime("-" . rand(1, 72) . " hours"))
];
// Intentar insertar en conversations
try {
$stmt = $pdo->prepare("
INSERT INTO conversations (user_id, content, direction, message_type, status, created_at)
VALUES (?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$messageData['user_id'],
$messageData['content'],
$messageData['direction'],
$messageData['message_type'],
$messageData['status'],
$messageData['created_at']
]);
$conversationsCreated++;
} catch (Exception $e) {
// Si falla, intentar en conversations
try {
$stmt = $pdo->prepare("
INSERT INTO conversations (user_id, message_text, direction, message_type, status, created_at)
VALUES (?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$messageData['user_id'],
$messageData['content'],
$messageData['direction'],
$messageData['message_type'],
$messageData['status'],
$messageData['created_at']
]);
$conversationsCreated++;
} catch (Exception $e2) {
echo "
❌ Error creando mensaje: " . $e2->getMessage() . "
";
}
}
}
}
echo "
✅ Usuarios creados: " . count($userIds) . "
";
echo "
✅ Mensajes/conversaciones creados: $conversationsCreated
";
echo "
🎉 ¡Datos de prueba creados exitosamente!
";
echo "
SIGUIENTE PASO:
";
echo "
";
echo "
";
echo "
";
}
} catch (Exception $e) {
echo "❌ Error: " . htmlspecialchars($e->getMessage()) . "
";
}
if (!$_POST) {
echo "