This commit is contained in:
lizandrogd
2026-01-21 01:02:17 -05:00
parent 4e3e02111b
commit 87b89b52a5
14 changed files with 387 additions and 36 deletions
@@ -0,0 +1,32 @@
<?php
/**
* Safe migration: show current column type, backup distinct statuses, then alter.
*/
require_once __DIR__ . '/../config/config_enhanced.php';
require_once __DIR__ . '/../classes/Database.php';
try {
$db = Database::getInstance();
echo "Current structure for conversations table:\n";
$rows = $db->fetchAll("SHOW COLUMNS FROM conversations LIKE 'status'");
print_r($rows);
$distinct = $db->fetchAll("SELECT DISTINCT status FROM conversations");
echo "Distinct status values in table:\n";
print_r(array_column($distinct, 'status'));
// Ask user confirmation (CLI only)
if (php_sapi_name() === 'cli') {
echo "About to alter column 'status' to ENUM('sent','delivered','read','failed','received') DEFAULT 'sent'. Continue? (y/N): ";
$resp = trim(fgets(STDIN));
if (strtolower($resp) !== 'y') {
echo "Aborted by user.\n";
exit;
}
}
$db->query("ALTER TABLE conversations MODIFY COLUMN status ENUM('sent','delivered','read','failed','received') DEFAULT 'sent'");
echo "ALTER OK\n";
} catch (Exception $e) {
echo "ERROR: " . $e->getMessage() . "\n";
}
+15
View File
@@ -0,0 +1,15 @@
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
// Test calling API endpoint internally by setting input stream
$payload = json_encode([
'to' => '573001234567',
'message_id' => '<TEST_MSGID>',
'emoji' => '👍',
'dry_run' => true
]);
file_put_contents('php://memory', $payload); // no effect; instead call service directly
require_once __DIR__ . '/../api/send_reaction.php';
+5
View File
@@ -0,0 +1,5 @@
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once __DIR__ . '/../api/send_reply.php';
+21
View File
@@ -0,0 +1,21 @@
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once __DIR__ . '/../services/WhatsAppService.php';
try {
$s = new WhatsAppService();
echo "WhatsAppService loaded\n";
echo "Dry-run reaction:\n";
$r = $s->sendReaction('573001234567', '<MSGID123>', '❤️', true);
print_r($r);
echo "Dry-run text reply:\n";
$rr = $s->sendTextReply('573001234567', '<MSGID123>', 'Gracias por tu mensaje', false, true);
print_r($rr);
} catch (Throwable $t) {
echo "ERROR: " . $t->getMessage() . "\n";
}
+102
View File
@@ -0,0 +1,102 @@
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
require_once __DIR__ . '/../api/webhook.php';
$payload = [
"object" => "whatsapp_business_account",
"entry" => [
[
"id" => "0",
"changes" => [
[
"field" => "messages",
"value" => [
"messaging_product" => "whatsapp",
"metadata" => [
"display_phone_number" => "16505551111",
"phone_number_id" => "123456123"
],
"contacts" => [
[
"profile" => ["name" => "test user name"],
"wa_id" => "16315551181"
]
],
"messages" => [
[
"from" => "16315551181",
"id" => "ABGGFlA5Fpa",
"timestamp" => "1504902988",
"type" => "text",
"text" => ["body" => "this is a text message"]
]
]
]
]
]
]
]
];
try {
$w = new WhatsAppWebhook();
echo "Webhook instance created\n";
$result = $w->processPayload($payload);
echo "processPayload result: " . ($result ? 'true' : 'false') . "\n";
// Simular reacción entrante
$reactionPayload = [
"object" => "whatsapp_business_account",
"entry" => [
[
"id" => "0",
"changes" => [
[
"field" => "messages",
"value" => [
"messaging_product" => "whatsapp",
"metadata" => [
"display_phone_number" => "16505551111",
"phone_number_id" => "123456123"
],
"contacts" => [
[
"profile" => ["name" => "reactor"],
"wa_id" => "16315551181"
]
],
"messages" => [
[
"from" => "16315551181",
"id" => "REACTION1",
"timestamp" => "1504902990",
"type" => "reaction",
"reaction" => ["message_id" => "ABGGFlA5Fpa", "emoji" => "❤️"]
]
]
]
]
]
]
]
];
$r2 = $w->processPayload($reactionPayload);
echo "processReaction result: " . ($r2 ? 'true' : 'false') . "\n";
} catch (Throwable $t) {
echo "Fatal: " . $t->getMessage() . "\n";
echo $t->getTraceAsString() . "\n";
}
// Show last lines of system log
$log = __DIR__ . '/../logs/system.log';
if (file_exists($log)) {
echo "-- Last log lines --\n";
$lines = array_slice(file($log), -40);
foreach ($lines as $line) echo $line;
} else {
echo "No log file found\n";
}