Files
whatsapp/scripts/test_interactive_flow.php
T
2026-01-21 15:19:58 -05:00

43 lines
1.3 KiB
PHP

<?php
require_once __DIR__ . '/../api/webhook.php';
require_once __DIR__ . '/../config/config.php';
$w = new WhatsAppWebhook();
// Build a fake 'value' structure with interactive list_reply
$value = [
'messages' => [
[
'from' => '573010000002',
'id' => 'TEST_INT_1',
'type' => 'interactive',
'interactive' => [
'type' => 'list_reply',
'list_reply' => ['id' => 'option_2', 'title' => 'Consultar resultados']
],
'timestamp' => time()
]
]
];
// Set current menu for user (simulate that menu was shown previously)
$db = Database::getInstance();
$db->update('users', ['current_menu_id' => 1, 'current_step' => 1], 'phone_number = :phone', ['phone' => '573010000002']);
// Use reflection to call private method processconversations
$ref = new ReflectionClass($w);
$m = $ref->getMethod('processconversations');
$m->setAccessible(true);
$m->invoke($w, $value);
// Check DB for last conversations for that phone
$db = Database::getInstance();
$user = $db->fetch('SELECT * FROM users WHERE phone_number = ?', ['573010000002']);
if ($user) {
$rows = $db->fetchAll('SELECT * FROM conversations WHERE user_id = ? ORDER BY created_at DESC LIMIT 5', [$user['id']]);
print_r($user);
print_r($rows);
} else {
echo "User not found\n";
}