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:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user