Feature: Soporte para caption en imágenes/videos
- 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
This commit is contained in:
@@ -331,6 +331,11 @@ function sendToN8NIA(Message $message, string $userMessage): void
|
|||||||
function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $text): void
|
function handleAutoTranslationWithButtons(PDO $pdo, Message $message, string $text): void
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
// Si no hay texto, ignorar (ej: solo imagen/video sin caption)
|
||||||
|
if (empty(trim($text))) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
require_once __DIR__ . '/src/Translate.php';
|
require_once __DIR__ . '/src/Translate.php';
|
||||||
$translator = new src\Translate();
|
$translator = new src\Translate();
|
||||||
|
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ try {
|
|||||||
$chatId = $message['chat']['id'];
|
$chatId = $message['chat']['id'];
|
||||||
$userId = $message['from']['id'] ?? null;
|
$userId = $message['from']['id'] ?? null;
|
||||||
$text = $message['text'] ?? '';
|
$text = $message['text'] ?? '';
|
||||||
|
$caption = $message['caption'] ?? ''; // Caption de foto/video
|
||||||
$username = $message['from']['first_name'] ?? 'Usuario';
|
$username = $message['from']['first_name'] ?? 'Usuario';
|
||||||
|
|
||||||
registerTelegramUser($pdo, $message['from']);
|
registerTelegramUser($pdo, $message['from']);
|
||||||
@@ -48,14 +49,23 @@ try {
|
|||||||
sendWelcomeMessage($pdo, $sender, $chatId, $username);
|
sendWelcomeMessage($pdo, $sender, $chatId, $username);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (str_starts_with($text, '/')) {
|
// Procesar texto de mensajes regulares
|
||||||
handleTelegramCommand($sender, $pdo, $chatId, $userId, $text, $username);
|
if (!empty($text)) {
|
||||||
} elseif (str_starts_with($text, '#')) {
|
if (str_starts_with($text, '/')) {
|
||||||
$command = ltrim($text, '#');
|
handleTelegramCommand($sender, $pdo, $chatId, $userId, $text, $username);
|
||||||
sendTemplateByCommand($pdo, $sender, $chatId, $command);
|
} elseif (str_starts_with($text, '#')) {
|
||||||
} else {
|
$command = ltrim($text, '#');
|
||||||
handleTelegramMessage($pdo, $sender, $chatId, $userId, $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'])) {
|
} elseif (isset($update['callback_query'])) {
|
||||||
$callbackQuery = $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
|
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 = $pdo->prepare("SELECT chat_mode FROM recipients WHERE platform_id = ? AND platform = 'telegram'");
|
||||||
$stmt->execute([$userId]);
|
$stmt->execute([$userId]);
|
||||||
$recipient = $stmt->fetch();
|
$recipient = $stmt->fetch();
|
||||||
|
|||||||
Reference in New Issue
Block a user