Files
whatsapp/scripts/test_bot_enabled.php
T
2026-01-21 02:45:59 -05:00

31 lines
1.4 KiB
PHP

<?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";