From 0c053ab036125a66a650fe4e55afa47f083a9c7b Mon Sep 17 00:00:00 2001 From: nickpons666 Date: Thu, 19 Feb 2026 16:01:46 -0600 Subject: [PATCH] =?UTF-8?q?Feature:=20Soporte=20para=20caption=20en=20im?= =?UTF-8?q?=C3=A1genes/videos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Telegram: Procesar caption de fotos y videos con botones de traducción - Discord: Ignorar mensajes vacíos (solo attachments sin texto) - Si no hay caption/texto, los bots no procesan nada - Si hay caption/texto, se traduce normalmente Cambios: - telegram/webhook/telegram_bot_webhook.php: Agregar procesamiento de $caption - discord_bot.php: Agregar validación de texto vacío - handleTelegramMessage: Ignorar textos vacíos - handleAutoTranslationWithButtons: Ignorar textos vacíos --- discord_bot.php | 5 ++++ telegram/webhook/telegram_bot_webhook.php | 29 +++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/discord_bot.php b/discord_bot.php index 7ce2d7c..15b9aba 100755 --- a/discord_bot.php +++ b/discord_bot.php @@ -331,6 +331,11 @@ function sendToN8NIA(Message $message, string $userMessage): void function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $text): void { try { + // Si no hay texto, ignorar (ej: solo imagen/video sin caption) + if (empty(trim($text))) { + return; + } + require_once __DIR__ . '/src/Translate.php'; $translator = new src\Translate(); diff --git a/telegram/webhook/telegram_bot_webhook.php b/telegram/webhook/telegram_bot_webhook.php index 77af1cc..92fa845 100755 --- a/telegram/webhook/telegram_bot_webhook.php +++ b/telegram/webhook/telegram_bot_webhook.php @@ -40,6 +40,7 @@ try { $chatId = $message['chat']['id']; $userId = $message['from']['id'] ?? null; $text = $message['text'] ?? ''; + $caption = $message['caption'] ?? ''; // Caption de foto/video $username = $message['from']['first_name'] ?? 'Usuario'; registerTelegramUser($pdo, $message['from']); @@ -48,14 +49,23 @@ try { sendWelcomeMessage($pdo, $sender, $chatId, $username); } - if (str_starts_with($text, '/')) { - handleTelegramCommand($sender, $pdo, $chatId, $userId, $text, $username); - } elseif (str_starts_with($text, '#')) { - $command = ltrim($text, '#'); - sendTemplateByCommand($pdo, $sender, $chatId, $command); - } else { - handleTelegramMessage($pdo, $sender, $chatId, $userId, $text); + // Procesar texto de mensajes regulares + if (!empty($text)) { + if (str_starts_with($text, '/')) { + handleTelegramCommand($sender, $pdo, $chatId, $userId, $text, $username); + } elseif (str_starts_with($text, '#')) { + $command = ltrim($text, '#'); + sendTemplateByCommand($pdo, $sender, $chatId, $command); + } else { + handleTelegramMessage($pdo, $sender, $chatId, $userId, $text); + } } + // Procesar caption de fotos o videos + elseif (!empty($caption)) { + // Solo traducir si hay caption + handleTelegramMessage($pdo, $sender, $chatId, $userId, $caption); + } + // Si no hay texto ni caption, ignorar (foto/video sin texto) } elseif (isset($update['callback_query'])) { $callbackQuery = $update['callback_query']; @@ -246,6 +256,11 @@ function handleTelegramCommand(Telegram\TelegramSender $sender, PDO $pdo, int $c function handleTelegramMessage(PDO $pdo, Telegram\TelegramSender $sender, int $chatId, int $userId, string $text): void { + // Si no hay texto, ignorar (ej: solo imagen/video sin caption) + if (empty(trim($text))) { + return; + } + $stmt = $pdo->prepare("SELECT chat_mode FROM recipients WHERE platform_id = ? AND platform = 'telegram'"); $stmt->execute([$userId]); $recipient = $stmt->fetch();