up
This commit is contained in:
@@ -183,6 +183,9 @@ class WhatsAppWebhook {
|
||||
$filename = $message['document']['filename'] ?? null;
|
||||
}
|
||||
|
||||
// Log debug (temporal) para verificar cómo llegan media_url/filename
|
||||
error_log(sprintf('[webhook] messageId=%s type=%s mediaUrl=%s filename=%s mime=%s', $messageId, $messageType, $mediaUrl ?? 'NULL', $filename ?? 'NULL', $mimeType ?? 'NULL'));
|
||||
|
||||
// Guardar mensaje en base de datos
|
||||
$saveData = [
|
||||
'user_id' => $user['id'],
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
$sample = json_decode('{
|
||||
"object": "whatsapp_business_account",
|
||||
"entry": [
|
||||
{
|
||||
"id": "639871912520412",
|
||||
"changes": [
|
||||
{
|
||||
"value": {
|
||||
"messaging_product": "whatsapp",
|
||||
"metadata": {
|
||||
"display_phone_number": "573053370116",
|
||||
"phone_number_id": "959898150536936"
|
||||
},
|
||||
"contacts": [
|
||||
{
|
||||
"profile": { "name": "Usite" },
|
||||
"wa_id": "573168950803"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"from": "573168950803",
|
||||
"id": "wamid.HBgMNTczMTY4OTUwODAzFQIAEhgUM0JDQTEzMDI0MTU1MENBMEFGNzUA",
|
||||
"timestamp": "1769010091",
|
||||
"type": "document",
|
||||
"document": {
|
||||
"filename": "usuarios_blancos(5).csv",
|
||||
"mime_type": "text/csv",
|
||||
"sha256": "id9kq9uEkgJB9OmjciqDCqFLPJmPh5xtWvtdu8U8JRI=",
|
||||
"id": "1379066300634610",
|
||||
"url": "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=1379066300634610&source=webhook&ext=1769010393&hash=EXAMPLE"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"field": "messages"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}', true);
|
||||
|
||||
$message = $sample['entry'][0]['changes'][0]['value']['messages'][0];
|
||||
|
||||
$mediaUrl = null; $filename = null; $mimeType = null;
|
||||
|
||||
if (isset($message['document'])) {
|
||||
$filename = $message['document']['filename'] ?? null;
|
||||
$mimeType = $message['document']['mime_type'] ?? null;
|
||||
$mediaUrl = $message['document']['url'] ?? ($message['document']['id'] ?? null);
|
||||
}
|
||||
|
||||
echo "Computed mediaUrl: "; var_export($mediaUrl); echo "\n";
|
||||
echo "Computed filename: "; var_export($filename); echo "\n";
|
||||
echo "Computed mimeType: "; var_export($mimeType); echo "\n";
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
require_once __DIR__ . '/../api/webhook.php';
|
||||
|
||||
$sample = json_decode('{
|
||||
"object": "whatsapp_business_account",
|
||||
"entry": [
|
||||
{
|
||||
"id": "639871912520412",
|
||||
"changes": [
|
||||
{
|
||||
"value": {
|
||||
"messaging_product": "whatsapp",
|
||||
"metadata": {
|
||||
"display_phone_number": "573053370116",
|
||||
"phone_number_id": "959898150536936"
|
||||
},
|
||||
"contacts": [
|
||||
{
|
||||
"profile": { "name": "Usite" },
|
||||
"wa_id": "573168950803"
|
||||
}
|
||||
],
|
||||
"messages": [
|
||||
{
|
||||
"from": "573168950803",
|
||||
"id": "wamid.HBgMNTczMTY4OTUwODAzFQIAEhgUM0JDQTEzMDI0MTU1MENBMEFGNzUA",
|
||||
"timestamp": "1769010091",
|
||||
"type": "document",
|
||||
"document": {
|
||||
"filename": "usuarios_blancos(5).csv",
|
||||
"mime_type": "text/csv",
|
||||
"sha256": "id9kq9uEkgJB9OmjciqDCqFLPJmPh5xtWvtdu8U8JRI=",
|
||||
"id": "1379066300634610",
|
||||
"url": "https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=1379066300634610&source=webhook&ext=1769010393&hash=EXAMPLE"
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
"field": "messages"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}', true);
|
||||
|
||||
try {
|
||||
$webhook = new WhatsAppWebhook();
|
||||
$ok = $webhook->processPayload($sample);
|
||||
echo "processPayload returned: " . ($ok ? 'true' : 'false') . "\n";
|
||||
|
||||
$db = Database::getInstance();
|
||||
$row = $db->fetch('SELECT * FROM conversations WHERE message_id = :mid', ['mid' => 'wamid.HBgMNTczMTY4OTUwODAzFQIAEhgUM0JDQTEzMDI0MTU1MENBMEFGNzUA']);
|
||||
if ($row) {
|
||||
echo "Row found:\n" . json_encode($row, JSON_PRETTY_PRINT) . "\n";
|
||||
} else {
|
||||
echo "Row not found\n";
|
||||
}
|
||||
} catch (Throwable $t) {
|
||||
echo "Error: " . $t->getMessage() . "\n";
|
||||
echo $t->getTraceAsString();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../config/config.php';
|
||||
try {
|
||||
$db = Database::getInstance();
|
||||
$mid = 'wamid.TEST' . rand(1000,9999);
|
||||
$db->insert('conversations', [
|
||||
'user_id' => 2,
|
||||
'message_id' => $mid,
|
||||
'direction' => 'incoming',
|
||||
'message_type' => 'document',
|
||||
'content' => 'usuarios_blancos.csv',
|
||||
'media_url' => 'https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=1379066300634610&source=webhook&ext=1769010393&hash=EXAMPLE',
|
||||
'status' => 'received'
|
||||
]);
|
||||
$row = $db->fetch('SELECT * FROM conversations WHERE message_id = ?', [$mid]);
|
||||
echo json_encode($row, JSON_PRETTY_PRINT) . "\n";
|
||||
} catch (Throwable $t) {
|
||||
echo 'Error: ' . $t->getMessage() . "\n";
|
||||
}
|
||||
Reference in New Issue
Block a user