This commit is contained in:
lizandrogd
2026-01-21 02:45:59 -05:00
parent edfa5f68d9
commit 845762f916
10 changed files with 207 additions and 8 deletions
+15
View File
@@ -0,0 +1,15 @@
<?php
require_once __DIR__ . '/../config/config.php';
$db = Database::getInstance();
$col = $db->fetch("SHOW COLUMNS FROM users LIKE 'bot_enabled'");
if ($col) {
echo "Column bot_enabled already exists\n";
exit(0);
}
try {
$db->query("ALTER TABLE users ADD COLUMN bot_enabled TINYINT(1) NULL DEFAULT 1 AFTER bot_paused_until");
echo "Added column bot_enabled\n";
} catch (Exception $e) {
echo "Failed to add bot_enabled: " . $e->getMessage() . "\n";
exit(1);
}
+9
View File
@@ -0,0 +1,9 @@
<?php
require_once __DIR__ . '/../config/config.php';
$db = Database::getInstance();
try {
$cols = $db->fetchAll('DESCRIBE message_templates');
foreach ($cols as $c) echo $c['Field'] . ' => ' . $c['Type'] . PHP_EOL;
} catch (Exception $e) {
echo 'Error: ' . $e->getMessage() . PHP_EOL;
}
+31
View File
@@ -0,0 +1,31 @@
<?php
require_once __DIR__ . '/../config/config.php';
require_once __DIR__ . '/../services/BotService.php';
$db = Database::getInstance();
$bot = new BotService();
$phone = '573012345678';
$db->execute('DELETE FROM users WHERE phone_number = :p', ['p' => $phone]);
$userId = $db->insert('users', ['phone_number' => $phone, 'status' => 'active', 'bot_enabled' => 0, 'welcome_sent_at' => date('Y-m-d H:i:s'), 'created_at' => date('Y-m-d H:i:s')]);
$user = $db->fetch('SELECT * FROM users WHERE id = :id', ['id' => $userId]);
// Clear conversations
$db->execute('DELETE FROM conversations WHERE user_id = :uid', ['uid' => $userId]);
// Send message while bot disabled
$bot->processMessage($user, 'hola', 'text');
$outs = $db->fetchAll("SELECT * FROM conversations WHERE user_id = :uid AND direction = 'outgoing'", ['uid' => $userId]);
echo "Outgoing after disabled: " . count($outs) . "\n";
// Enable bot
$db->update('users', ['bot_enabled' => 1], 'id = :id', ['id' => $userId]);
$user2 = $db->fetch('SELECT * FROM users WHERE id = :id', ['id' => $userId]);
$bot->processMessage($user2, 'hola', 'text');
$outs2 = $db->fetchAll("SELECT * FROM conversations WHERE user_id = :uid AND direction = 'outgoing'", ['uid' => $userId]);
echo "Outgoing after enabled: " . count($outs2) . "\n";
// Cleanup
$db->execute('DELETE FROM conversations WHERE user_id = :uid', ['uid' => $userId]);
$db->execute('DELETE FROM users WHERE id = :id', ['id' => $userId]);
echo "Done\n";
+13
View File
@@ -0,0 +1,13 @@
<?php
// Script de prueba para ejecutar api/get_templates.php en modo debug
$_GET['debug'] = 'true';
chdir(__DIR__ . '/../api');
ob_start();
try {
include 'get_templates.php';
} catch (Throwable $t) {
echo "Throwable: " . $t->getMessage() . "\n";
echo $t->getTraceAsString() . "\n";
}
$out = ob_get_clean();
echo $out;