Mejoras en el envío de plantillas con imágenes
- Agregar detección de URLs de Discord gifts para evitar botones de traducción - Enviar imágenes en orden correcto (texto-imagen-texto-imagen) en Discord y Telegram - Usar APP_URL del .env para las URLs de imágenes - Agregar funciones sendContentWithOrderedImagesAndButtons en ambos bots
This commit is contained in:
@@ -335,26 +335,25 @@ function sendTemplateByCommand(PDO $pdo, Telegram\TelegramSender $sender, int $c
|
||||
$template = $stmt->fetch();
|
||||
|
||||
if ($template) {
|
||||
$converter = new Telegram\Converters\HtmlToTelegramHtmlConverter();
|
||||
$content = $converter->convert($template['message_content']);
|
||||
// Parsear el contenido manteniendo el orden texto-imagen
|
||||
$segments = $sender->parseContent($template['message_content']);
|
||||
|
||||
$plainText = $template['message_content'];
|
||||
$plainText = preg_replace('/<br\s*\/?>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<\/p>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<p[^>]*>/i', '', $plainText);
|
||||
$plainText = strip_tags($plainText);
|
||||
$plainText = html_entity_decode($plainText, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
// Limpiar espacios múltiples pero preservar saltos de línea
|
||||
$plainText = preg_replace('/[ \t]+/', ' ', $plainText);
|
||||
$plainText = preg_replace('/\n\s*\n/', "\n", $plainText);
|
||||
$plainText = trim($plainText);
|
||||
|
||||
$translationButtons = getTelegramTranslationButtons($pdo, $plainText);
|
||||
|
||||
if ($translationButtons) {
|
||||
$sender->sendMessage($chatId, $content, $translationButtons);
|
||||
} else {
|
||||
$sender->sendMessage($chatId, $content);
|
||||
if (!empty($segments)) {
|
||||
// Obtener texto completo para botones de traducción
|
||||
$plainText = $template['message_content'];
|
||||
$plainText = preg_replace('/<br\s*\/?>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<\/p>/i', "\n", $plainText);
|
||||
$plainText = preg_replace('/<p[^>]*>/i', '', $plainText);
|
||||
$plainText = strip_tags($plainText);
|
||||
$plainText = html_entity_decode($plainText, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$plainText = preg_replace('/[ \t]+/', ' ', $plainText);
|
||||
$plainText = preg_replace('/\n\s*\n/', "\n", $plainText);
|
||||
$plainText = trim($plainText);
|
||||
|
||||
$translationButtons = getTelegramTranslationButtons($pdo, $plainText);
|
||||
|
||||
// Enviar contenido ordenado con botones
|
||||
$sender->sendContentWithOrderedImagesAndButtons($chatId, $segments, $translationButtons);
|
||||
}
|
||||
} else {
|
||||
$sender->sendMessage($chatId, "❌ Plantilla no encontrada: #{$command}");
|
||||
|
||||
Reference in New Issue
Block a user