diff --git a/api/version/media-url_debug.log b/api/version/media-url_debug.log index 6dda3ea..633f574 100644 --- a/api/version/media-url_debug.log +++ b/api/version/media-url_debug.log @@ -9,3 +9,6 @@ [2026-01-21 14:09:48] Request: GET /api/version/media-url.php?id=2690520987949889 GET:{"id":"2690520987949889"} POST:[] [2026-01-21 14:09:48] Graph API request to https://graph.facebook.com/v22.0/2690520987949889 [2026-01-21 14:09:49] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=2690520987949889&source=getMedia&ext=1769022879&hash=ARmZNGo6nPUMqsu1WVi5OGDOIQucpHkU45UcMnR0kudP2Q +[2026-01-21 14:14:06] Request: GET /api/version/media-url.php?id=3932473397057815 GET:{"id":"3932473397057815"} POST:[] +[2026-01-21 14:14:06] Graph API request to https://graph.facebook.com/v22.0/3932473397057815 +[2026-01-21 14:14:07] Proxying Facebook media URL with Authorization to https://lookaside.fbsbx.com/whatsapp_business/attachments/?mid=3932473397057815&source=getMedia&ext=1769023137&hash=ARlu_MCLx6NJCX8mxWXoqSxQ5jNO5lfqPV3wj5mAfq0qAQ diff --git a/chat_window.php b/chat_window.php index 2e43238..d83e128 100644 --- a/chat_window.php +++ b/chat_window.php @@ -613,7 +613,20 @@ if (empty($user_id)) { } else if (isValidMediaUrl(msg.local_file)) { thumbUrl = `/${msg.local_file}`; } else if (isValidMediaUrl(msg.media_url_external)) { - thumbUrl = msg.media_url_external; + // Si es una URL externa de Facebook/lookaside, usar el proxy para incluir Authorization + const external = msg.media_url_external; + if (/lookaside\.fbsbx\.com|graph\.facebook\.com|facebook\.com/i.test(external)) { + // Intentar extraer mid del query string para usar ?id= + const midMatch = external.match(/[?&]mid=([^&]+)/i); + if (midMatch && midMatch[1]) { + const mid = decodeURIComponent(midMatch[1]); + thumbUrl = `/api/version/media-url.php?id=${encodeURIComponent(mid)}`; + } else { + thumbUrl = `/api/version/media-url.php?url=${encodeURIComponent(external)}`; + } + } else { + thumbUrl = external; + } } else if (isValidMediaUrl(msg.media_url)) { thumbUrl = msg.media_url; }