up
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$db->query("ALTER TABLE conversations MODIFY COLUMN status ENUM('sent','delivered','read','failed','received') DEFAULT 'sent'");
|
||||
echo "ALTER OK\n";
|
||||
} catch (Exception $e) {
|
||||
echo "ALTER ERROR: " . $e->getMessage() . "\n";
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->fetchAll('SELECT id, request_body, created_at FROM webhook_logs ORDER BY created_at DESC LIMIT 50');
|
||||
$missing = [];
|
||||
foreach ($rows as $r) {
|
||||
$data = json_decode($r['request_body'], true);
|
||||
if (!$data) continue;
|
||||
if (!empty($data['entry'])) {
|
||||
foreach ($data['entry'] as $entry) {
|
||||
if (!empty($entry['changes'])) {
|
||||
foreach ($entry['changes'] as $change) {
|
||||
$val = $change['value'] ?? [];
|
||||
if (!empty($val['messages'])) {
|
||||
foreach ($val['messages'] as $m) {
|
||||
$mid = $m['id'] ?? null;
|
||||
$from = $m['from'] ?? null;
|
||||
if ($mid) {
|
||||
$exists = $db->fetch("SELECT id FROM conversations WHERE message_id = ? LIMIT 1", [$mid]);
|
||||
if (!$exists) {
|
||||
$missing[] = ['message_id' => $mid, 'from' => $from, 'log_id' => $r['id'], 'log_time' => $r['created_at']];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($missing)) {
|
||||
echo "All recent messages found in conversations.\n";
|
||||
} else {
|
||||
echo "Missing messages (not found in conversations):\n";
|
||||
foreach ($missing as $m) {
|
||||
echo json_encode($m) . PHP_EOL;
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch('SELECT * FROM webhook_logs ORDER BY created_at DESC LIMIT 1');
|
||||
if ($row) {
|
||||
echo json_encode(['found' => true, 'row' => $row]);
|
||||
} else {
|
||||
echo json_encode(['found' => false]);
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['error' => $e->getMessage()]);
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$rows = $db->fetchAll('SELECT id, request_body, created_at FROM webhook_logs ORDER BY created_at DESC LIMIT 20');
|
||||
foreach ($rows as $r) {
|
||||
$rb = $r['request_body'];
|
||||
$has = strpos($rb, '"messages"') !== false ? 'HAS_MESSAGES' : (strpos($rb, '"statuses"') !== false ? 'ONLY_STATUSES' : 'OTHER');
|
||||
echo $r['created_at'] . ' | id:' . $r['id'] . ' | ' . $has . PHP_EOL;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
$mid = $argv[1] ?? '';
|
||||
if (!$mid) { echo "Usage: php dump_webhook_payload.php <message_id>\n"; exit(1); }
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch('SELECT id, request_body, created_at FROM webhook_logs WHERE request_body LIKE ? ORDER BY created_at DESC LIMIT 1', ['%'.$mid.'%']);
|
||||
if ($row) {
|
||||
$file = __DIR__ . '/webhook_payload_'.$mid.'.json';
|
||||
file_put_contents($file, $row['request_body']);
|
||||
echo "Saved payload to: $file\n";
|
||||
} else echo "No encontrado\n";
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: '.$e->getMessage().PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
$mid = $argv[1] ?? '';
|
||||
if (!$mid) { echo "Usage: php find_webhook_by_mid.php <message_id>\n"; exit(1); }
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch('SELECT id, request_body, created_at FROM webhook_logs WHERE request_body LIKE ? ORDER BY created_at DESC LIMIT 1', ['%'.$mid.'%']);
|
||||
if ($row) echo $row['created_at'] . ' | id:' . $row['id'] . PHP_EOL . $row['request_body'] . PHP_EOL;
|
||||
else echo "No encontrado\n";
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: '.$e->getMessage().PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
|
||||
$file = __DIR__ . '/webhook_payload_ABGGFlA5Fpa.json';
|
||||
if (!file_exists($file)) { echo "Payload not found\n"; exit(1); }
|
||||
$payload = json_decode(file_get_contents($file), true);
|
||||
if (!$payload) { echo "Invalid JSON\n"; exit(1); }
|
||||
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
foreach ($payload['entry'] as $entry) {
|
||||
foreach ($entry['changes'] as $change) {
|
||||
$val = $change['value'];
|
||||
if (!empty($val['messages'])) {
|
||||
foreach ($val['messages'] as $message) {
|
||||
$phone = $message['from'];
|
||||
$mid = $message['id'];
|
||||
$text = $message['text']['body'] ?? '';
|
||||
// Check user
|
||||
$user = $db->fetch('SELECT id FROM users WHERE phone_number = ?', [$phone]);
|
||||
if (!$user) {
|
||||
echo "User not found, creating: $phone\n";
|
||||
$db->insert('users', ['phone_number' => $phone, 'status' => 'active', 'created_at' => date('Y-m-d H:i:s')]);
|
||||
$userId = $db->lastInsertId();
|
||||
echo "Created user id: $userId\n";
|
||||
} else {
|
||||
$userId = $user['id'];
|
||||
echo "User exists id: $userId\n";
|
||||
}
|
||||
|
||||
// Attempt insert
|
||||
echo "Attempting insert message_id: $mid\n";
|
||||
$msg = [
|
||||
'user_id' => $userId,
|
||||
'message_id' => $mid,
|
||||
'direction' => 'incoming',
|
||||
'message_type' => 'text',
|
||||
'content' => $text,
|
||||
'media_url' => null,
|
||||
'status' => 'received',
|
||||
'created_at' => date('Y-m-d H:i:s')
|
||||
];
|
||||
try {
|
||||
// Manual insert using PDO to capture detailed errors
|
||||
$pdo = $db->getConnection();
|
||||
$keys = array_keys($msg);
|
||||
$fields = implode(', ', $keys);
|
||||
$placeholders = ':' . implode(', :', $keys);
|
||||
$sql = "INSERT INTO conversations ({$fields}) VALUES ({$placeholders})";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
echo "Prepared SQL\n";
|
||||
$res = $stmt->execute($msg);
|
||||
echo "Executed: " . ($res ? 'true' : 'false') . "\n";
|
||||
$err = $stmt->errorInfo();
|
||||
echo "Stmt errorInfo: " . json_encode($err) . "\n";
|
||||
$lastId = $pdo->lastInsertId();
|
||||
echo "Inserted conversation id (manual): $lastId\n";
|
||||
} catch (Exception $e) {
|
||||
echo "INSERT EXCEPTION: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
echo "EXCEPTION: " . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
echo "TEST START\n";
|
||||
ini_set('display_errors', 1);
|
||||
error_reporting(E_ALL);
|
||||
echo "Before config load\n";
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
echo "After config load\n";
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
echo "After DB load\n";
|
||||
require_once __DIR__ . '/../api/webhook.php';
|
||||
echo "After webhook include\n";
|
||||
|
||||
$json = file_get_contents(__DIR__ . '/webhook_payload_ABGGFlA5Fpa.json');
|
||||
$data = json_decode($json, true);
|
||||
try {
|
||||
echo "Calling processPayload...\n";
|
||||
$w = new WhatsAppWebhook();
|
||||
$ok = $w->processPayload($data);
|
||||
echo 'processPayload returned: ' . ($ok ? 'true' : 'false') . PHP_EOL;
|
||||
} catch (Exception $e) {
|
||||
echo 'EXCEPTION: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config_enhanced.php';
|
||||
require_once __DIR__ . '/../classes/Database.php';
|
||||
require_once __DIR__ . '/../api/webhook.php';
|
||||
|
||||
try {
|
||||
echo "Starting...\n";
|
||||
$db = Database::getInstance();
|
||||
echo "Got DB\n";
|
||||
$row = $db->fetch('SELECT id, request_body FROM webhook_logs ORDER BY created_at DESC LIMIT 1');
|
||||
echo "Latest log id: " . ($row['id'] ?? 'none') . PHP_EOL;
|
||||
$payload = json_decode($row['request_body'], true);
|
||||
echo "Decoded payload keys: " . implode(',', array_keys($payload)) . PHP_EOL;
|
||||
$w = new WhatsAppWebhook();
|
||||
echo "Webhook instance created\n";
|
||||
$res = $w->processPayload($payload);
|
||||
echo 'ProcessPayload => ' . ($res ? 'OK' : 'FAILED') . PHP_EOL;
|
||||
} catch (Exception $e) {
|
||||
echo 'ERROR: ' . $e->getMessage() . PHP_EOL;
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"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"}}]}}]}]}
|
||||
Reference in New Issue
Block a user