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:
2026-02-19 19:12:28 -06:00
parent a55c45ef94
commit e8912bdb63
5 changed files with 130 additions and 89 deletions

View File

@@ -247,20 +247,43 @@ class TelegramSender
*/
public function sendContentWithOrderedImages(int $chatId, array $segments): void
{
$this->sendContentWithOrderedImagesAndButtons($chatId, $segments, null);
}
/**
* Enviar contenido con texto e imágenes en el orden correcto con botones
*/
public function sendContentWithOrderedImagesAndButtons(int $chatId, array $segments, ?array $buttons = null): void
{
$appUrl = $_ENV['APP_URL'] ?? getenv('APP_URL') ?? '';
$baseUrl = rtrim($appUrl, '/');
$totalSegments = count($segments);
$currentSegment = 0;
foreach ($segments as $segment) {
$currentSegment++;
$isLastSegment = ($currentSegment === $totalSegments);
if ($segment['type'] === 'text') {
// Enviar texto
if (!empty(trim($segment['content']))) {
$this->sendMessage($chatId, $segment['content']);
if ($isLastSegment && $buttons) {
$this->sendMessage($chatId, $segment['content'], $buttons);
} else {
$this->sendMessage($chatId, $segment['content']);
}
}
} elseif ($segment['type'] === 'image') {
$imagePath = $segment['src'];
if (file_exists($imagePath)) {
// Es un archivo local
$this->sendPhoto($chatId, $imagePath);
} elseif (strpos($imagePath, 'http') === 0) {
// Es una URL remota
// Convertir ruta local a URL usando APP_URL
if (strpos($imagePath, 'http') !== 0) {
$imagePath = $baseUrl . '/' . ltrim($imagePath, '/');
}
if ($isLastSegment && $buttons) {
$this->sendPhoto($chatId, $imagePath, null, $buttons);
} else {
$this->sendPhoto($chatId, $imagePath);
}
}