up
This commit is contained in:
@@ -48,10 +48,15 @@ try {
|
||||
direction,
|
||||
message_type,
|
||||
content,
|
||||
media_url,
|
||||
status,
|
||||
created_at
|
||||
FROM conversations
|
||||
WHERE user_id = ?
|
||||
AND (
|
||||
message_type = 'text'
|
||||
OR (message_type IN ('image', 'audio', 'video', 'document') AND media_url IS NOT NULL AND media_url != '')
|
||||
)
|
||||
ORDER BY created_at ASC",
|
||||
[$user_id]
|
||||
);
|
||||
@@ -64,6 +69,7 @@ try {
|
||||
'direction' => $msg['direction'],
|
||||
'message_type' => $msg['message_type'],
|
||||
'content' => $msg['content'] ?? '',
|
||||
'media_url' => $msg['media_url'] ?? null,
|
||||
'status' => $msg['status'] ?? 'sent',
|
||||
'created_at' => $msg['created_at'],
|
||||
'time' => date('H:i', strtotime($msg['created_at'])),
|
||||
|
||||
@@ -86,7 +86,7 @@ try {
|
||||
// Construir URL pública
|
||||
$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http';
|
||||
$host = $_SERVER['HTTP_HOST'];
|
||||
$publicUrl = $protocol . '://' . $host . '/whatsapp/uploads/' . $uniqueName;
|
||||
$publicUrl = $protocol . '://' . $host . '/uploads/' . $uniqueName;
|
||||
|
||||
// Determinar tipo de medio
|
||||
$mediaType = 'document';
|
||||
|
||||
+19
-4
@@ -570,11 +570,24 @@ if (empty($user_id)) {
|
||||
const isOutgoing = msg.direction === 'outgoing';
|
||||
const messageClass = isOutgoing ? 'message-outgoing' : 'message-incoming';
|
||||
|
||||
// Verificar si es multimedia
|
||||
// Debug: ver todos los datos del mensaje
|
||||
console.log('Procesando mensaje:', {
|
||||
id: msg.id,
|
||||
type: msg.message_type,
|
||||
has_media_url: !!msg.media_url,
|
||||
media_url: msg.media_url,
|
||||
content: msg.content
|
||||
});
|
||||
|
||||
// Verificar si es multimedia (simplificado)
|
||||
let contentHtml = '';
|
||||
if (msg.media_url) {
|
||||
const isMultimedia = msg.media_url && msg.media_url.trim() !== '' &&
|
||||
msg.message_type && msg.message_type !== 'text';
|
||||
|
||||
if (isMultimedia) {
|
||||
console.log('→ Renderizando como multimedia:', msg.message_type);
|
||||
// Mensaje multimedia
|
||||
switch (msg.media_type) {
|
||||
switch (msg.message_type) {
|
||||
case 'image':
|
||||
contentHtml = `<img src="${msg.media_url}" alt="Imagen" class="message-media-image" onclick="openImageModal('${msg.media_url}')">`;
|
||||
break;
|
||||
@@ -586,6 +599,7 @@ if (empty($user_id)) {
|
||||
break;
|
||||
case 'audio':
|
||||
contentHtml = `<audio controls class="message-media-audio">
|
||||
<source src="${msg.media_url}" type="audio/webm">
|
||||
<source src="${msg.media_url}" type="audio/mpeg">
|
||||
<source src="${msg.media_url}" type="audio/ogg">
|
||||
Tu navegador no soporta audio HTML5.
|
||||
@@ -600,9 +614,10 @@ if (empty($user_id)) {
|
||||
</a>`;
|
||||
break;
|
||||
default:
|
||||
console.warn('Tipo multimedia desconocido:', msg.message_type);
|
||||
contentHtml = `<a href="${msg.media_url}" target="_blank" class="message-document">
|
||||
<i class="fas fa-file"></i>
|
||||
<span>Archivo adjunto</span>
|
||||
<span>${escapeHtml(msg.content || 'Archivo adjunto')}</span>
|
||||
</a>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
require_once 'config/config.php';
|
||||
|
||||
$db = Database::getInstance();
|
||||
|
||||
echo "<h2>Últimos 10 mensajes multimedia en la BD</h2>";
|
||||
echo "<style>
|
||||
table { border-collapse: collapse; width: 100%; }
|
||||
th, td { border: 1px solid #ddd; padding: 8px; text-align: left; }
|
||||
th { background-color: #4CAF50; color: white; }
|
||||
tr:nth-child(even) { background-color: #f2f2f2; }
|
||||
pre { background: #f4f4f4; padding: 10px; overflow-x: auto; }
|
||||
</style>";
|
||||
|
||||
$messages = $db->fetchAll("
|
||||
SELECT
|
||||
c.id,
|
||||
c.user_id,
|
||||
u.phone_number,
|
||||
c.direction,
|
||||
c.message_type,
|
||||
c.content,
|
||||
c.media_url,
|
||||
c.created_at
|
||||
FROM conversations c
|
||||
LEFT JOIN users u ON c.user_id = u.id
|
||||
WHERE c.message_type IN ('image', 'audio', 'video', 'document')
|
||||
ORDER BY c.created_at DESC
|
||||
LIMIT 10
|
||||
");
|
||||
|
||||
echo "<table>";
|
||||
echo "<tr>
|
||||
<th>ID</th>
|
||||
<th>Teléfono</th>
|
||||
<th>Dir</th>
|
||||
<th>Tipo</th>
|
||||
<th>Content</th>
|
||||
<th>Media URL</th>
|
||||
<th>Fecha</th>
|
||||
</tr>";
|
||||
|
||||
foreach ($messages as $msg) {
|
||||
echo "<tr>";
|
||||
echo "<td>{$msg['id']}</td>";
|
||||
echo "<td>{$msg['phone_number']}</td>";
|
||||
echo "<td>{$msg['direction']}</td>";
|
||||
echo "<td><strong>{$msg['message_type']}</strong></td>";
|
||||
echo "<td><pre>" . htmlspecialchars(substr($msg['content'], 0, 200)) . "</pre></td>";
|
||||
echo "<td><pre>" . htmlspecialchars(substr($msg['media_url'], 0, 100)) . "</pre></td>";
|
||||
echo "<td>" . date('H:i:s', strtotime($msg['created_at'])) . "</td>";
|
||||
echo "</tr>";
|
||||
}
|
||||
|
||||
echo "</table>";
|
||||
|
||||
echo "<h3>Análisis:</h3>";
|
||||
echo "<ul>";
|
||||
echo "<li>Si 'Content' tiene JSON → Problema: se guardó la respuesta de WhatsApp en lugar del caption</li>";
|
||||
echo "<li>Si 'Media URL' está vacía o tiene JSON → Problema: no se guardó correctamente la URL</li>";
|
||||
echo "<li>Si 'Media URL' tiene un ID (sin http) → Problema: es el media_id de WhatsApp, no la URL local</li>";
|
||||
echo "<li>Correcto: Media URL debería tener http://localhost/uploads/...</li>";
|
||||
echo "</ul>";
|
||||
?>
|
||||
@@ -4,12 +4,12 @@
|
||||
*/
|
||||
|
||||
// URL del API
|
||||
$apiUrl = 'http://localhost/whatsapp/api/send_media_message.php';
|
||||
$apiUrl = 'http://localhost/api/send_media_message.php';
|
||||
|
||||
// Datos de prueba
|
||||
$data = [
|
||||
'recipient' => '573168950803',
|
||||
'media_url' => 'http://localhost/whatsapp/uploads/test.jpg',
|
||||
'media_url' => 'http://localhost/uploads/test.jpg',
|
||||
'media_type' => 'image',
|
||||
'caption' => 'Test de imagen',
|
||||
'filename' => 'test.jpg'
|
||||
|
||||
Reference in New Issue
Block a user