u
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
<?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";
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
require_once __DIR__ . '/../services/BotService.php';
|
||||
$db = Database::getInstance();
|
||||
$phone = '573010000001';
|
||||
// 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 'menu'
|
||||
echo "--- Sending 'menu' ---\n";
|
||||
$bot->processMessage($user, 'menu', 'text');
|
||||
$user = $db->fetch('SELECT * FROM users WHERE id = ?', [$user['id']]);
|
||||
print_r(['after menu user' => $user]);
|
||||
|
||||
// Simulate user selecting option 2
|
||||
echo "--- Sending '2' ---\n";
|
||||
$bot->processMessage($user, '2', '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);
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
require_once __DIR__ . '/../services/BotService.php';
|
||||
$db = Database::getInstance();
|
||||
$phone = '573010000003';
|
||||
// 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 incoming message 'Hola'
|
||||
$db->insert('conversations', ['user_id' => $user['id'], 'message_id' => 'INC1', 'direction' => 'incoming', 'message_type' => 'text', 'content' => 'Hola', 'status' => 'received', 'created_at' => date('Y-m-d H:i:s')]);
|
||||
|
||||
// Simulate advisor outgoing reply AFTER the incoming message
|
||||
$db->insert('conversations', ['user_id' => $user['id'], 'message_id' => 'OUT1', 'direction' => 'outgoing', 'message_type' => 'text', 'content' => 'Hola, soy el asesor', 'status' => 'sent', 'created_at' => date('Y-m-d H:i:s')]);
|
||||
|
||||
// Now user sends 'menu'
|
||||
echo "--- Sending 'menu' ---\n";
|
||||
$user = $db->fetch('SELECT * FROM users WHERE id = ?', [$user['id']]);
|
||||
$bot->processMessage($user, 'menu', 'text');
|
||||
$user = $db->fetch('SELECT * FROM users WHERE id = ?', [$user['id']]);
|
||||
print_r(['after menu user' => $user]);
|
||||
|
||||
// Simulate user selecting option 2
|
||||
echo "--- Sending '2' ---\n";
|
||||
$bot->processMessage($user, '2', 'text');
|
||||
$rows = $db->fetchAll('SELECT * FROM conversations WHERE user_id = ? ORDER BY created_at DESC LIMIT 5', [$user['id']]);
|
||||
print_r($rows);
|
||||
Reference in New Issue
Block a user