Bot Discord - Commit completo con todos los cambios
This commit is contained in:
621
telegram/admin/chat_telegram.php
Executable file
621
telegram/admin/chat_telegram.php
Executable file
@@ -0,0 +1,621 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../includes/session_check.php';
|
||||
require_once __DIR__ . '/../../includes/db.php';
|
||||
|
||||
// Solo para administradores
|
||||
if ($_SESSION['role'] !== 'admin') {
|
||||
header('HTTP/1.0 403 Forbidden');
|
||||
die('Acceso denegado.');
|
||||
}
|
||||
|
||||
// Obtener todos los usuarios de Telegram que han interactuado o son miembros de grupos
|
||||
$stmt = $pdo->query(
|
||||
"SELECT DISTINCT r.platform_id, r.name
|
||||
FROM recipients r
|
||||
WHERE r.platform = 'telegram' AND r.type = 'user'
|
||||
ORDER BY r.name ASC"
|
||||
);
|
||||
$users = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
require_once __DIR__ . '/../../templates/header.php';
|
||||
?>
|
||||
|
||||
<style>
|
||||
.chat-container {
|
||||
display: flex;
|
||||
height: calc(100vh - 200px); /* Ajustar altura */
|
||||
}
|
||||
|
||||
/* Estilos para el selector de emojis */
|
||||
.emoji-picker {
|
||||
position: fixed;
|
||||
width: 250px;
|
||||
max-height: 300px;
|
||||
overflow-y: auto;
|
||||
background: white;
|
||||
border: 1px solid #dee2e6;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
||||
z-index: 9999;
|
||||
display: none;
|
||||
flex-wrap: wrap;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.emoji-option {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
font-size: 1.5em;
|
||||
cursor: pointer;
|
||||
border-radius: 4px;
|
||||
transition: all 0.2s;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.emoji-option:hover {
|
||||
background-color: #f8f9fa;
|
||||
transform: scale(1.2);
|
||||
}
|
||||
|
||||
.emoji-option:active {
|
||||
transform: scale(0.95);
|
||||
}
|
||||
|
||||
.input-group-prepend .btn {
|
||||
border-top-right-radius: 0;
|
||||
border-bottom-right-radius: 0;
|
||||
}
|
||||
|
||||
.input-group-append .btn {
|
||||
border-top-left-radius: 0;
|
||||
border-bottom-left-radius: 0;
|
||||
}
|
||||
|
||||
#message-text {
|
||||
border-radius: 0;
|
||||
}
|
||||
|
||||
.message-text {
|
||||
white-space: pre-wrap;
|
||||
word-wrap: break-word;
|
||||
}
|
||||
.user-list {
|
||||
border-right: 1px solid #dee2e6;
|
||||
overflow-y: auto;
|
||||
}
|
||||
.chat-history {
|
||||
flex-grow: 1;
|
||||
overflow-y: auto;
|
||||
padding: 1rem;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
.message-form {
|
||||
padding: 1rem;
|
||||
border-top: 1px solid #dee2e6;
|
||||
}
|
||||
.message {
|
||||
max-width: 70%;
|
||||
padding: 0.5rem 1rem;
|
||||
border-radius: 1rem;
|
||||
margin-bottom: 0.5rem;
|
||||
}
|
||||
.message.in {
|
||||
background-color: #6495ED; /* Azul claro (CornflowerBlue) */
|
||||
color: white;
|
||||
align-self: flex-start;
|
||||
}
|
||||
|
||||
.message.out {
|
||||
background-color: #6495ED; /* Azul claro (CornflowerBlue) */
|
||||
color: white;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
.user-list .list-group-item.active {
|
||||
background-color: #0d6efd;
|
||||
border-color: #0d6efd;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h1 class="mt-4">Chat de Soporte de Telegram</h1>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body p-0">
|
||||
<div class="chat-container">
|
||||
<!-- Columna de Usuarios -->
|
||||
<div class="col-md-4 col-lg-3 user-list">
|
||||
<div class="list-group list-group-flush">
|
||||
<?php foreach ($users as $user): ?>
|
||||
<a href="#" class="list-group-item list-group-item-action" data-chat-id="<?= $user['platform_id'] ?>">
|
||||
<?= htmlspecialchars($user['name']) ?>
|
||||
</a>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Columna de Chat -->
|
||||
<div class="col-md-8 col-lg-9 d-flex flex-column">
|
||||
<div id="chat-history" class="chat-history">
|
||||
<div class="text-center text-muted my-auto">
|
||||
<i class="bi bi-arrow-left-circle-fill fs-1"></i>
|
||||
<p>Selecciona un usuario para ver la conversación.</p>
|
||||
</div>
|
||||
</div>
|
||||
<div id="message-form-container" class="message-form" style="display: none;">
|
||||
<form id="message-form">
|
||||
<input type="hidden" id="chat-id-input" name="chat_id">
|
||||
<div class="input-group" style="position: relative;">
|
||||
<div class="input-group-prepend">
|
||||
<button type="button" id="emoji-trigger" class="btn btn-outline-secondary" onclick="toggleEmojiPicker()">
|
||||
<i class="bi bi-emoji-smile"></i>
|
||||
</button>
|
||||
</div>
|
||||
<input type="text" id="message-text" name="message" class="form-control" placeholder="Escribe tu respuesta..." required>
|
||||
<div class="input-group-append">
|
||||
<button type="submit" class="btn btn-primary">Enviar</button>
|
||||
</div>
|
||||
|
||||
<!-- Selector de emojis simplificado -->
|
||||
<div id="emoji-picker" style="
|
||||
display: none;
|
||||
position: absolute;
|
||||
bottom: 100%;
|
||||
left: 0;
|
||||
background: white;
|
||||
border: 1px solid #ddd;
|
||||
border-radius: 8px;
|
||||
padding: 10px;
|
||||
width: 250px;
|
||||
max-height: 200px;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
||||
z-index: 1000;">
|
||||
<div style="display: flex; flex-wrap: wrap; gap: 5px;">
|
||||
<span class="emoji-option" onclick="insertEmoji('😊')" style="cursor: pointer; font-size: 24px;">😊</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😂')" style="cursor: pointer; font-size: 24px;">😂</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😍')" style="cursor: pointer; font-size: 24px;">😍</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😎')" style="cursor: pointer; font-size: 24px;">😎</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😢')" style="cursor: pointer; font-size: 24px;">😢</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😡')" style="cursor: pointer; font-size: 24px;">😡</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😴')" style="cursor: pointer; font-size: 24px;">😴</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('😷')" style="cursor: pointer; font-size: 24px;">😷</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('🤔')" style="cursor: pointer; font-size: 24px;">🤔</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('🤗')" style="cursor: pointer; font-size: 24px;">🤗</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('👍')" style="cursor: pointer; font-size: 24px;">👍</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('👎')" style="cursor: pointer; font-size: 24px;">👎</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('👏')" style="cursor: pointer; font-size: 24px;">👏</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('🙌')" style="cursor: pointer; font-size: 24px;">🙌</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('🤝')" style="cursor: pointer; font-size: 24px;">🤝</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('📱')" style="cursor: pointer; font-size: 24px;">📱</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('💻')" style="cursor: pointer; font-size: 24px;">💻</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('📷')" style="cursor: pointer; font-size: 24px;">📷</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('🎮')" style="cursor: pointer; font-size: 24px;">🎮</span>
|
||||
<span class="emoji-option" onclick="insertEmoji('📚')" style="cursor: pointer; font-size: 24px;">📚</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Función para mostrar/ocultar el selector de emojis
|
||||
function toggleEmojiPicker() {
|
||||
const picker = document.getElementById('emoji-picker');
|
||||
if (picker.style.display === 'none' || !picker.style.display) {
|
||||
picker.style.display = 'block';
|
||||
} else {
|
||||
picker.style.display = 'none';
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Función para insertar un emoji en el campo de texto
|
||||
function insertEmoji(emoji) {
|
||||
const input = document.getElementById('message-text');
|
||||
const start = input.selectionStart;
|
||||
const end = input.selectionEnd;
|
||||
const text = input.value;
|
||||
input.value = text.substring(0, start) + emoji + text.substring(end);
|
||||
input.focus();
|
||||
input.setSelectionRange(start + emoji.length, start + emoji.length);
|
||||
document.getElementById('emoji-picker').style.display = 'none';
|
||||
}
|
||||
|
||||
// Cerrar el selector al hacer clic fuera de él
|
||||
document.addEventListener('click', function(e) {
|
||||
const picker = document.getElementById('emoji-picker');
|
||||
const trigger = document.getElementById('emoji-trigger');
|
||||
if (picker && trigger &&
|
||||
e.target !== picker && !picker.contains(e.target) &&
|
||||
e.target !== trigger && !trigger.contains(e.target)) {
|
||||
picker.style.display = 'none';
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php require_once __DIR__ . '/../../templates/footer.php'; ?>
|
||||
|
||||
<script>
|
||||
// Función para insertar emojis en el campo de texto
|
||||
function insertEmoji(emoji) {
|
||||
const input = document.getElementById('message-text');
|
||||
const start = input.selectionStart;
|
||||
const end = input.selectionEnd;
|
||||
const text = input.value;
|
||||
|
||||
// Insertar el emoji en la posición del cursor
|
||||
input.value = text.substring(0, start) + emoji + text.substring(end);
|
||||
|
||||
// Mover el cursor después del emoji insertado
|
||||
const newPos = start + emoji.length;
|
||||
input.selectionStart = input.selectionEnd = newPos;
|
||||
|
||||
// Enfocar el campo de texto
|
||||
input.focus();
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function() {
|
||||
const userLinks = document.querySelectorAll('.user-list .list-group-item');
|
||||
const chatHistory = document.getElementById('chat-history');
|
||||
const formContainer = document.getElementById('message-form-container');
|
||||
const messageForm = document.getElementById('message-form');
|
||||
const chatIdInput = document.getElementById('chat-id-input');
|
||||
const messageTextInput = document.getElementById('message-text');
|
||||
|
||||
let activeChatId = null;
|
||||
let lastMessageId = 0;
|
||||
let refreshInterval = null;
|
||||
|
||||
userLinks.forEach(link => {
|
||||
link.addEventListener('click', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
// Marcar usuario activo
|
||||
userLinks.forEach(l => l.classList.remove('active'));
|
||||
this.classList.add('active');
|
||||
|
||||
// Detener el intervalo anterior si existe
|
||||
if (refreshInterval) {
|
||||
clearInterval(refreshInterval);
|
||||
}
|
||||
|
||||
// Establecer el nuevo chat activo
|
||||
activeChatId = this.getAttribute('data-chat-id');
|
||||
chatIdInput.value = activeChatId;
|
||||
lastMessageId = 0; // Reiniciar el ID del último mensaje
|
||||
|
||||
// Cargar el historial y comenzar a actualizar
|
||||
loadChatHistory(activeChatId);
|
||||
|
||||
// Iniciar la actualización automática con un intervalo dinámico
|
||||
let refreshDelay = 500; // Comenzar con 0.5 segundos
|
||||
|
||||
function startRefreshTimer() {
|
||||
if (refreshInterval) clearInterval(refreshInterval);
|
||||
|
||||
refreshInterval = setInterval(() => {
|
||||
if (activeChatId && !document.hidden) {
|
||||
checkForNewMessages(activeChatId);
|
||||
}
|
||||
}, refreshDelay);
|
||||
}
|
||||
|
||||
// Iniciar el temporizador
|
||||
startRefreshTimer();
|
||||
});
|
||||
});
|
||||
|
||||
function loadChatHistory(chatId, onlyNew = false) {
|
||||
// Usar un timestamp para evitar caché del navegador
|
||||
const timestamp = new Date().getTime();
|
||||
const url = `get_chat_history.php?chat_id=${chatId}${onlyNew ? '&last_id=' + lastMessageId : ''}&_=${timestamp}`;
|
||||
|
||||
if (!onlyNew) {
|
||||
chatHistory.innerHTML = '<div class="text-center text-muted my-auto"><div class="spinner-border" role="status"><span class="visually-hidden">Cargando...</span></div></div>';
|
||||
formContainer.style.display = 'block';
|
||||
}
|
||||
|
||||
fetch(url)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Datos recibidos:', data); // Depuración
|
||||
|
||||
if (onlyNew && (!data.history || data.history.length === 0)) {
|
||||
return; // No hay mensajes nuevos
|
||||
}
|
||||
|
||||
if (!onlyNew) {
|
||||
chatHistory.innerHTML = '';
|
||||
}
|
||||
|
||||
let hasNewMessages = false;
|
||||
|
||||
if (data.success && data.history && data.history.length > 0) {
|
||||
// Ordenar los mensajes por ID para asegurar el orden correcto
|
||||
data.history.sort((a, b) => a.id - b.id);
|
||||
|
||||
// Ordenar los mensajes por ID para asegurar el orden correcto
|
||||
data.history.sort((a, b) => a.id - b);
|
||||
|
||||
data.history.forEach(msg => {
|
||||
// Solo agregar mensajes más recientes que el último mostrado
|
||||
if (msg.id > lastMessageId || !onlyNew) {
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.classList.add('message', msg.direction);
|
||||
// Usar innerHTML para permitir que el enlace de traducción se añada correctamente
|
||||
messageDiv.innerHTML = `<div class="message-text">${msg.message_text.replace(/\n/g, '<br>')}</div>`;
|
||||
|
||||
// Add translate link if needed
|
||||
// For testing, always show for incoming messages
|
||||
if (msg.direction === 'in') { // msg.language_code !== 'es'
|
||||
const translateLink = document.createElement('a');
|
||||
translateLink.href = '#';
|
||||
translateLink.textContent = ' (Traducir)';
|
||||
translateLink.classList.add('translate-link');
|
||||
translateLink.setAttribute('data-message-id', msg.id);
|
||||
messageDiv.appendChild(translateLink);
|
||||
}
|
||||
|
||||
// Agregar el mensaje al historial
|
||||
chatHistory.appendChild(messageDiv);
|
||||
|
||||
// Actualizar el ID del último mensaje
|
||||
if (msg.id > lastMessageId) {
|
||||
lastMessageId = msg.id;
|
||||
}
|
||||
|
||||
hasNewMessages = true;
|
||||
}
|
||||
});
|
||||
|
||||
// Desplazarse al final solo si hay mensajes nuevos
|
||||
if (hasNewMessages) {
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
}
|
||||
} else if (!onlyNew) {
|
||||
chatHistory.innerHTML = '<div class="text-center text-muted my-auto">No hay mensajes en esta conversación.</div>';
|
||||
}
|
||||
|
||||
// Si no es una actualización, desplazarse al final
|
||||
if (!onlyNew) {
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
}
|
||||
|
||||
// Actualizar lastMessageId si viene en la respuesta
|
||||
if (data.last_id && data.last_id > lastMessageId) {
|
||||
lastMessageId = data.last_id;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
if (!onlyNew) {
|
||||
console.error('Error al cargar el historial:', error);
|
||||
chatHistory.innerHTML = '<div class="text-center text-danger my-auto">Error al cargar el historial. Intenta recargar la página.</div>';
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Función para verificar mensajes nuevos
|
||||
function checkForNewMessages(chatId) {
|
||||
if (!document.hidden && chatId) {
|
||||
// Usar fetch con headers para evitar caché
|
||||
fetch(`get_chat_history.php?chat_id=${chatId}&last_id=${lastMessageId}&_=${new Date().getTime()}`, {
|
||||
headers: {
|
||||
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
||||
'Pragma': 'no-cache',
|
||||
'Expires': '0'
|
||||
}
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
console.log('Datos recibidos en checkForNewMessages:', data); // Depuración
|
||||
|
||||
if (data.success && data.history && data.history.length > 0) {
|
||||
let hasNewMessages = false;
|
||||
|
||||
// Ordenar los mensajes por ID para asegurar el orden correcto
|
||||
data.history.sort((a, b) => a.id - b);
|
||||
|
||||
data.history.forEach(msg => {
|
||||
if (msg.id > lastMessageId) {
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.classList.add('message', msg.direction);
|
||||
messageDiv.textContent = msg.message_text;
|
||||
|
||||
chatHistory.appendChild(messageDiv);
|
||||
|
||||
if (msg.id > lastMessageId) {
|
||||
lastMessageId = msg.id;
|
||||
}
|
||||
|
||||
hasNewMessages = true;
|
||||
}
|
||||
});
|
||||
|
||||
if (hasNewMessages) {
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
// Si hay mensajes nuevos, reiniciar el temporizador con el intervalo más corto
|
||||
refreshDelay = 2000;
|
||||
startRefreshTimer();
|
||||
}
|
||||
}
|
||||
|
||||
if (data.last_id && data.last_id > lastMessageId) {
|
||||
lastMessageId = data.last_id;
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error al verificar mensajes nuevos:', error);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Actualizar el chat cuando la pestaña vuelve a estar activa
|
||||
document.addEventListener('visibilitychange', function() {
|
||||
if (!document.hidden && activeChatId) {
|
||||
loadChatHistory(activeChatId);
|
||||
}
|
||||
|
||||
// Inicializar el selector de emojis
|
||||
console.log('Inicializando selector de emojis...');
|
||||
let emojiPickerVisible = false;
|
||||
const emojiTrigger = document.getElementById('emoji-trigger');
|
||||
const emojiPicker = document.getElementById('emoji-picker');
|
||||
const messageTextInput = document.getElementById('message-text');
|
||||
|
||||
console.log('Elementos del selector de emojis:', {
|
||||
emojiTrigger: emojiTrigger ? 'Encontrado' : 'No encontrado',
|
||||
emojiPicker: emojiPicker ? 'Encontrado' : 'No encontrado',
|
||||
messageTextInput: messageTextInput ? 'Encontrado' : 'No encontrado'
|
||||
});
|
||||
|
||||
// Asegurarse de que el selector esté oculto inicialmente
|
||||
if (emojiPicker) {
|
||||
emojiPicker.style.display = 'none';
|
||||
emojiPicker.style.backgroundColor = '#fff';
|
||||
emojiPicker.style.border = '2px solid red';
|
||||
emojiPicker.innerHTML = '<div style="padding: 10px;">Selector de emojis</div>' + emojiPicker.innerHTML;
|
||||
}
|
||||
|
||||
// Mostrar/ocultar selector de emojis
|
||||
if (emojiTrigger) {
|
||||
emojiTrigger.addEventListener('click', function(e) {
|
||||
console.log('Botón de emoji clickeado');
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
if (!emojiPicker) {
|
||||
console.error('El selector de emojis no se encontró en el DOM');
|
||||
return false;
|
||||
}
|
||||
|
||||
if (emojiPickerVisible) {
|
||||
console.log('Ocultando selector de emojis');
|
||||
emojiPicker.style.display = 'none';
|
||||
} else {
|
||||
console.log('Mostrando selector de emojis');
|
||||
emojiPicker.style.display = 'block';
|
||||
// Posicionar el selector debajo del botón
|
||||
const rect = emojiTrigger.getBoundingClientRect();
|
||||
emojiPicker.style.position = 'fixed';
|
||||
emojiPicker.style.top = (rect.bottom + window.scrollY) + 'px';
|
||||
emojiPicker.style.left = (rect.left + window.scrollX) + 'px';
|
||||
emojiPicker.style.zIndex = '9999';
|
||||
console.log('Posición del selector:', emojiPicker.style.top, emojiPicker.style.left);
|
||||
}
|
||||
|
||||
emojiPickerVisible = !emojiPickerVisible;
|
||||
return false;
|
||||
});
|
||||
} else {
|
||||
console.error('No se pudo encontrar el botón de emoji');
|
||||
}
|
||||
|
||||
// Cerrar el selector al hacer clic fuera
|
||||
document.addEventListener('click', function(e) {
|
||||
if (!emojiPicker || !emojiTrigger) return;
|
||||
|
||||
const isClickInside = emojiPicker.contains(e.target) || emojiTrigger.contains(e.target);
|
||||
|
||||
if (emojiPickerVisible && !isClickInside) {
|
||||
console.log('Clic fuera del selector, ocultando...');
|
||||
emojiPicker.style.display = 'none';
|
||||
emojiPickerVisible = false;
|
||||
}
|
||||
});
|
||||
|
||||
// Manejar clics en emojis
|
||||
if (emojiPicker) {
|
||||
emojiPicker.addEventListener('click', function(e) {
|
||||
console.log('Clic en el selector de emojis');
|
||||
const emojiOption = e.target.closest('.emoji-option');
|
||||
if (emojiOption) {
|
||||
const emojiChar = emojiOption.getAttribute('data-emoji');
|
||||
console.log('Emoji seleccionado:', emojiChar);
|
||||
if (emojiChar) {
|
||||
insertEmoji(emojiChar);
|
||||
emojiPicker.style.display = 'none';
|
||||
emojiPickerVisible = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Evento para enviar mensaje
|
||||
messageForm.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
const messageText = messageTextInput.value.trim();
|
||||
if (!messageText) return;
|
||||
|
||||
const formData = new FormData(this);
|
||||
|
||||
// Optimistic UI update
|
||||
const messageDiv = document.createElement('div');
|
||||
messageDiv.className = `message out`;
|
||||
messageDiv.innerHTML = `
|
||||
<div class="message-text">${messageText.replace(/\n/g, '<br>')}</div>
|
||||
<div class="message-time">${new Date().toLocaleTimeString()}</div>
|
||||
`;
|
||||
chatHistory.appendChild(messageDiv);
|
||||
chatHistory.scrollTop = chatHistory.scrollHeight;
|
||||
|
||||
messageTextInput.value = '';
|
||||
|
||||
fetch('admin_send_message.php', {
|
||||
method: 'POST',
|
||||
body: formData
|
||||
})
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (!data.success) {
|
||||
alert('Error al enviar el mensaje: ' + data.error);
|
||||
// Opcional: eliminar el mensaje de la UI si falla
|
||||
chatHistory.removeChild(messageDiv);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error de red al enviar el mensaje.');
|
||||
chatHistory.removeChild(messageDiv);
|
||||
});
|
||||
});
|
||||
|
||||
// Evento para traducir mensaje
|
||||
chatHistory.addEventListener('click', function(e) {
|
||||
if (e.target.classList.contains('translate-link')) {
|
||||
e.preventDefault();
|
||||
const messageId = e.target.getAttribute('data-message-id');
|
||||
const messageDiv = e.target.parentElement;
|
||||
|
||||
fetch(`translate_message.php?message_id=${messageId}`)
|
||||
.then(response => response.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
const translatedText = document.createElement('div');
|
||||
translatedText.classList.add('translated-text');
|
||||
translatedText.textContent = data.translated_text;
|
||||
messageDiv.appendChild(translatedText);
|
||||
e.target.remove(); // Remove the translate link
|
||||
} else {
|
||||
alert('Error al traducir el mensaje: ' + data.error);
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
console.error('Error:', error);
|
||||
alert('Error de red al traducir el mensaje.');
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>
|
||||
338
telegram/admin/telegram_bot_interactions.php
Executable file
338
telegram/admin/telegram_bot_interactions.php
Executable file
@@ -0,0 +1,338 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../includes/session_check.php';
|
||||
require_once __DIR__ . '/../../includes/db.php';
|
||||
|
||||
// Crear las tablas necesarias si no existen
|
||||
try {
|
||||
$pdo->exec("
|
||||
-- Tabla para registrar interacciones con el bot
|
||||
CREATE TABLE IF NOT EXISTS telegram_bot_interactions (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
user_id BIGINT NOT NULL,
|
||||
username VARCHAR(255),
|
||||
first_name VARCHAR(255),
|
||||
last_name VARCHAR(255),
|
||||
interaction_type VARCHAR(50) NOT NULL,
|
||||
interaction_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||
UNIQUE KEY unique_interaction (user_id, interaction_type)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- Tabla para la configuración del mensaje del bot
|
||||
CREATE TABLE IF NOT EXISTS telegram_bot_messages (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
message_text TEXT NOT NULL,
|
||||
button_text VARCHAR(50) DEFAULT '¡Únete a nuestro grupo!',
|
||||
group_invite_link VARCHAR(255) DEFAULT 'https://t.me/+Hzh0G-1-BY41ZDNj',
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
register_users BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||
|
||||
-- Insertar configuración por defecto si no existe
|
||||
INSERT IGNORE INTO telegram_bot_messages
|
||||
(message_text, button_text, group_invite_link, is_active, register_users)
|
||||
VALUES (
|
||||
'¡Hola {user_name}! 👋\n\nGracias por interactuar con nuestro bot. Únete a nuestro grupo principal para mantenerte actualizado con nuestras novedades.',
|
||||
'¡Únete a nuestro grupo!',
|
||||
'https://t.me/+Hzh0G-1-BY41ZDNj',
|
||||
TRUE,
|
||||
TRUE
|
||||
);
|
||||
");
|
||||
} catch (PDOException $e) {
|
||||
die("Error al crear las tablas: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// Manejar el envío del formulario
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$messageText = $_POST['message_text'] ?? '';
|
||||
$buttonText = $_POST['button_text'] ?? '¡Únete a nuestro grupo!';
|
||||
$groupInviteLink = $_POST['group_invite_link'] ?? 'https://t.me/+Hzh0G-1-BY41ZDNj';
|
||||
$isActive = isset($_POST['is_active']) ? 1 : 0;
|
||||
$registerUsers = isset($_POST['register_users']) ? 1 : 0;
|
||||
|
||||
try {
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Actualizar la configuración
|
||||
$stmt = $pdo->prepare("
|
||||
UPDATE telegram_bot_messages
|
||||
SET message_text = ?,
|
||||
button_text = ?,
|
||||
group_invite_link = ?,
|
||||
is_active = ?,
|
||||
register_users = ?
|
||||
WHERE id = 1
|
||||
");
|
||||
|
||||
$stmt->execute([
|
||||
$messageText,
|
||||
$buttonText,
|
||||
$groupInviteLink,
|
||||
$isActive,
|
||||
$registerUsers
|
||||
]);
|
||||
|
||||
$pdo->commit();
|
||||
$successMessage = "¡Configuración guardada con éxito!";
|
||||
} catch (PDOException $e) {
|
||||
$pdo->rollBack();
|
||||
$errorMessage = "Error al guardar la configuración: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Obtener la configuración actual
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT * FROM telegram_bot_messages WHERE id = 1");
|
||||
$config = $stmt->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
if (!$config) {
|
||||
throw new Exception("No se encontró la configuración del mensaje del bot");
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorMessage = "Error al cargar la configuración: " . $e->getMessage();
|
||||
$config = [
|
||||
'message_text' => '¡Hola {user_name}! 👋\n\nGracias por interactuar con nuestro bot. Únete a nuestro grupo principal para mantenerte actualizado con nuestras novedades.',
|
||||
'button_text' => '¡Únete a nuestro grupo!',
|
||||
'group_invite_link' => 'https://t.me/+Hzh0G-1-BY41ZDNj',
|
||||
'is_active' => true,
|
||||
'register_users' => true
|
||||
];
|
||||
}
|
||||
|
||||
// Obtener estadísticas de interacciones
|
||||
try {
|
||||
$statsStmt = $pdo->query("
|
||||
SELECT
|
||||
COUNT(*) as total_interactions,
|
||||
COUNT(DISTINCT user_id) as unique_users
|
||||
FROM telegram_bot_interactions
|
||||
");
|
||||
$stats = $statsStmt->fetch(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
$errorMessage = "Error al cargar las estadísticas: " . $e->getMessage();
|
||||
$stats = [];
|
||||
}
|
||||
|
||||
$pageTitle = 'Interacciones del Bot de Telegram';
|
||||
require_once __DIR__ . '/../../templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h1 class="mt-4" data-translate="true">Interacciones del Bot de Telegram</h1>
|
||||
<p class="text-muted" data-translate="true">Configura el mensaje que se enviará cuando los usuarios interactúen con tu bot.</p>
|
||||
|
||||
<?php if (isset($successMessage)): ?>
|
||||
<div class="alert alert-success" data-translate="true"><?= htmlspecialchars($successMessage) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if (isset($errorMessage)): ?>
|
||||
<div class="alert alert-danger" data-translate="true"><?= htmlspecialchars($errorMessage) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-8">
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0" data-translate="true">Configuración del Mensaje del Bot</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="message_text" class="form-label" data-translate="true">Mensaje de Respuesta</label>
|
||||
<textarea class="form-control" id="message_text" name="message_text" rows="5" required><?= htmlspecialchars($config['message_text'] ?? '') ?></textarea>
|
||||
<div class="form-text" data-translate="true">
|
||||
Puedes usar los siguientes placeholders que serán reemplazados automáticamente:
|
||||
<ul class="mb-0">
|
||||
<li><code>{user_name}</code> - El nombre del usuario que interactúa con el bot.</li>
|
||||
<li><code>{group_link}</code> - El enlace al grupo principal.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-md-6">
|
||||
<label for="button_text" class="form-label" data-translate="true">Texto del Botón</label>
|
||||
<input type="text" class="form-control" id="button_text" name="button_text"
|
||||
value="<?= htmlspecialchars($config['button_text'] ?? '') ?>" required>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<label for="group_invite_link" class="form-label" data-translate="true">Enlace de Invitación al Grupo</label>
|
||||
<input type="url" class="form-control" id="group_invite_link" name="group_invite_link"
|
||||
value="<?= htmlspecialchars($config['group_invite_link'] ?? '') ?>" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="is_active" name="is_active"
|
||||
<?= ($config['is_active'] ?? true) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="is_active" data-translate="true">Activar mensaje de respuesta automática</label>
|
||||
</div>
|
||||
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="register_users" name="register_users"
|
||||
<?= ($config['register_users'] ?? true) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="register_users" data-translate="true">Registrar usuarios que interactúan con el bot</label>
|
||||
</div>
|
||||
|
||||
<button type="submit" class="btn btn-primary">
|
||||
<i class="bi bi-save-fill me-1"></i> <span data-translate="true">Guardar Cambios</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0" data-translate="true">Configuración de Webhook</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="mb-4">
|
||||
<h6 data-translate="true">Webhook Unificado</h6>
|
||||
<p class="small text-muted" data-translate="true">Este único webhook maneja tanto las interacciones directas con el bot como los mensajes de bienvenida a nuevos miembros en un grupo.</p>
|
||||
<div class="input-group mb-2">
|
||||
<input type="text" class="form-control" value="<?= rtrim($_ENV['APP_URL'] ?? 'https://pruebaspons.duckdns.org', '/') ?>/telegram/webhook/telegram_bot_webhook.php?auth_token=<?= urlencode($_ENV['TELEGRAM_WEBHOOK_TOKEN'] ?? '') ?>" id="unifiedWebhookUrl" readonly>
|
||||
<button class="btn btn-outline-secondary" type="button" onclick="copyToClipboard(document.getElementById('unifiedWebhookUrl'))">
|
||||
<i class="bi bi-clipboard"></i> Copiar
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<h6 data-translate="true">Comando de Configuración con cURL</h6>
|
||||
<p class="small text-muted" data-translate="true">Usa este comando en tu terminal para configurar el webhook en Telegram. Solo necesitas hacerlo una vez.</p>
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="input-group">
|
||||
<input type="text" class="form-control form-control-sm" value="curl -F 'url=<?= rtrim($_ENV['APP_URL'] ?? 'https://pruebaspons.duckdns.org', '/') ?>/telegram/webhook/telegram_bot_webhook.php?auth_token=<?= urlencode($_ENV['TELEGRAM_WEBHOOK_TOKEN'] ?? '') ?>' https://api.telegram.org/bot<?= $_ENV['TELEGRAM_BOT_TOKEN'] ?? '' ?>/setWebhook" id="curlUnifiedCommand" readonly>
|
||||
<button class="btn btn-outline-secondary btn-sm" type="button" onclick="copyToClipboard(document.getElementById('curlUnifiedCommand'))">
|
||||
<i class="bi bi-clipboard"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="alert alert-success mt-3 p-2 small">
|
||||
<i class="bi bi-check-circle-fill me-1"></i>
|
||||
<span data-translate="true">Este es el <strong>único webhook</strong> que necesitas configurar.</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-4">
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0" data-translate="true">Vista Previa</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="telegram-message">
|
||||
<div class="telegram-message-avatar">
|
||||
<img src="https://cdn4.telegram.org/file/vaG9VXzJ9Us3druVCEMoQv-1wwhBWO1hieJQxGZA9fY/1lZkbjXz6CQ" alt="Bot" class="rounded-circle" width="40">
|
||||
</div>
|
||||
<div class="telegram-message-content">
|
||||
<div class="telegram-message-username">Bot de Interacción</div>
|
||||
<div class="telegram-message-text">
|
||||
<?= nl2br(htmlspecialchars(str_replace(
|
||||
['{user_name}', '{group_link}'],
|
||||
['UsuarioEjemplo', $config['group_invite_link'] ?? ''],
|
||||
$config['message_text'] ?? ''
|
||||
))) ?>
|
||||
</div>
|
||||
<?php if (!empty($config['group_invite_link'])): ?>
|
||||
<div class="mt-2">
|
||||
<a href="<?= htmlspecialchars($config['group_invite_link']) ?>"
|
||||
class="btn btn-telegram"
|
||||
target="_blank">
|
||||
<?= htmlspecialchars($config['button_text'] ?? '') ?>
|
||||
</a>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php if (!empty($stats)): ?>
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-header">
|
||||
<h5 class="mb-0" data-translate="true">Estadísticas</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="d-flex justify-content-between mb-2">
|
||||
<span data-translate="true">Usuarios únicos registrados:</span>
|
||||
<span class="fw-bold"><?= number_format($stats['unique_users'] ?? 0) ?></span>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<span data-translate="true">Total de interacciones:</span>
|
||||
<span class="fw-bold"><?= number_format($stats['total_interactions'] ?? 0) ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.telegram-message {
|
||||
display: flex;
|
||||
padding: 8px 16px;
|
||||
margin-bottom: 1rem;
|
||||
background-color: #182533;
|
||||
border-radius: 8px;
|
||||
color: #e1e9f2;
|
||||
max-width: 100%;
|
||||
}
|
||||
.telegram-message-avatar {
|
||||
margin-right: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.telegram-message-avatar img {
|
||||
border-radius: 50%;
|
||||
}
|
||||
.telegram-message-username {
|
||||
font-weight: 500;
|
||||
color: #6ab3f3;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
.telegram-message-text {
|
||||
margin-top: 2px;
|
||||
line-height: 1.4;
|
||||
white-space: pre-line;
|
||||
}
|
||||
.btn-telegram {
|
||||
background-color: #2AABEE;
|
||||
color: white;
|
||||
border: none;
|
||||
padding: 6px 12px;
|
||||
border-radius: 4px;
|
||||
font-size: 14px;
|
||||
text-decoration: none;
|
||||
display: inline-block;
|
||||
}
|
||||
.btn-telegram:hover {
|
||||
background-color: #229ED9;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script>
|
||||
function copyToClipboard(button) {
|
||||
const input = button.closest('.input-group').querySelector('input');
|
||||
input.select();
|
||||
document.execCommand('copy');
|
||||
|
||||
// Cambiar el ícono temporalmente
|
||||
const icon = button.querySelector('i');
|
||||
const originalClass = icon.className;
|
||||
icon.className = 'bi bi-check';
|
||||
|
||||
// Restaurar después de 2 segundos
|
||||
setTimeout(() => {
|
||||
icon.className = originalClass;
|
||||
}, 2000);
|
||||
}
|
||||
</script>
|
||||
|
||||
<?php require_once __DIR__ . '/../../templates/footer.php'; ?>
|
||||
142
telegram/admin/telegram_welcome.php
Executable file
142
telegram/admin/telegram_welcome.php
Executable file
@@ -0,0 +1,142 @@
|
||||
<?php
|
||||
require_once __DIR__ . '/../../includes/session_check.php';
|
||||
require_once __DIR__ . '/../../includes/db.php';
|
||||
|
||||
// --- Lógica para el Mensaje de Bienvenida ---
|
||||
try {
|
||||
$pdo->exec("
|
||||
CREATE TABLE IF NOT EXISTS telegram_welcome_messages (
|
||||
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||
chat_id BIGINT NOT NULL UNIQUE,
|
||||
welcome_message TEXT,
|
||||
is_active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||
);
|
||||
");
|
||||
} catch (PDOException $e) {
|
||||
die("Error al verificar la tabla de bienvenida: " . $e->getMessage());
|
||||
}
|
||||
|
||||
// --- Lógica para los Ajustes Generales ---
|
||||
|
||||
// Manejar el envío de formularios
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
// Guardar Mensaje de Bienvenida
|
||||
if (isset($_POST['save_welcome_message'])) {
|
||||
$welcomeMessage = $_POST['welcome_message'] ?? '';
|
||||
$isActive = isset($_POST['is_active']) ? 1 : 0;
|
||||
$chatId = '-1002578350881'; // Manteniendo el ID de chat original para esta función
|
||||
|
||||
try {
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO telegram_welcome_messages (chat_id, welcome_message, is_active)
|
||||
VALUES (?, ?, ?)
|
||||
ON DUPLICATE KEY UPDATE welcome_message = ?, is_active = ?;
|
||||
");
|
||||
$stmt->execute([$chatId, $welcomeMessage, $isActive, $welcomeMessage, $isActive]);
|
||||
$successMessage = "¡Configuración de bienvenida guardada con éxito!";
|
||||
} catch (PDOException $e) {
|
||||
$errorMessage = "Error al guardar la configuración de bienvenida: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
// Guardar Ajustes Generales (Grupo por defecto)
|
||||
if (isset($_POST['save_general_settings'])) {
|
||||
$defaultGroupId = $_POST['default_announcement_group'] ?? '';
|
||||
try {
|
||||
$stmt = $pdo->prepare("INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) ON DUPLICATE KEY UPDATE setting_value = ?");
|
||||
$stmt->execute(['telegram_default_announcement_group', $defaultGroupId, $defaultGroupId]);
|
||||
$successMessage = "¡Ajustes generales guardados con éxito!";
|
||||
} catch (PDOException $e) {
|
||||
$errorMessage = "Error al guardar los ajustes generales: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// --- Obtener datos para mostrar en la página ---
|
||||
|
||||
// Configuración del Mensaje de Bienvenida
|
||||
$stmt_welcome = $pdo->prepare("SELECT * FROM telegram_welcome_messages WHERE chat_id = ?");
|
||||
$stmt_welcome->execute(['-1002578350881']);
|
||||
$welcomeConfig = $stmt_welcome->fetch(PDO::FETCH_ASSOC);
|
||||
if (!$welcomeConfig) {
|
||||
$welcomeConfig = [
|
||||
'welcome_message' => '¡Bienvenido/a {user_name} a nuestro grupo! Esperamos que disfrutes tu estancia.',
|
||||
'is_active' => true
|
||||
];
|
||||
}
|
||||
|
||||
// Grupos de Telegram para el selector
|
||||
$stmt_groups = $pdo->query("SELECT name, platform_id FROM recipients WHERE platform = 'telegram' AND type = 'channel' ORDER BY name ASC");
|
||||
$telegramGroups = $stmt_groups->fetchAll(PDO::FETCH_ASSOC);
|
||||
|
||||
// Configuración del grupo por defecto
|
||||
$stmt_settings = $pdo->prepare("SELECT setting_value FROM settings WHERE setting_key = ?");
|
||||
$stmt_settings->execute(['telegram_default_announcement_group']);
|
||||
$defaultGroupSetting = $stmt_settings->fetchColumn();
|
||||
|
||||
$pageTitle = 'Configuración de Telegram';
|
||||
require_once __DIR__ . '/../../templates/header.php';
|
||||
?>
|
||||
|
||||
<div class="container-fluid">
|
||||
<h1 class="mt-4" data-translate="true">Configuración de Telegram</h1>
|
||||
|
||||
<?php if (isset($successMessage)): ?>
|
||||
<div class="alert alert-success" data-translate="true"><?= htmlspecialchars($successMessage) ?></div>
|
||||
<?php endif; ?>
|
||||
<?php if (isset($errorMessage)): ?>
|
||||
<div class="alert alert-danger" data-translate="true"><?= htmlspecialchars($errorMessage) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Card para Mensaje de Bienvenida -->
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header"><h5 class="mb-0" data-translate="true">Gestionar Mensaje de Bienvenida</h5></div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="welcome_message" class="form-label" data-translate="true">Mensaje de Bienvenida</label>
|
||||
<textarea class="form-control" id="welcome_message" name="welcome_message" rows="5"><?= htmlspecialchars($welcomeConfig['welcome_message']) ?></textarea>
|
||||
<div class="form-text" data-translate="true">
|
||||
Puedes usar <code>{user_name}</code> y <code>{chat_title}</code>.
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-check form-switch mb-3">
|
||||
<input class="form-check-input" type="checkbox" id="is_active" name="is_active" <?= $welcomeConfig['is_active'] ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="is_active" data-translate="true">Activar mensaje de bienvenida</label>
|
||||
</div>
|
||||
<button type="submit" name="save_welcome_message" class="btn btn-primary">
|
||||
<i class="bi bi-save-fill me-1"></i> <span data-translate="true">Guardar Mensaje de Bienvenida</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Card para Ajustes Generales -->
|
||||
<div class="card shadow-sm mb-4">
|
||||
<div class="card-header"><h5 class="mb-0" data-translate="true">Ajustes de Comandos</h5></div>
|
||||
<div class="card-body">
|
||||
<form method="POST">
|
||||
<div class="mb-3">
|
||||
<label for="default_announcement_group" class="form-label" data-translate="true">Grupo de Anuncios por Defecto</label>
|
||||
<select class="form-select" id="default_announcement_group" name="default_announcement_group">
|
||||
<option value="" data-translate="true">-- No seleccionado --</option>
|
||||
<?php foreach ($telegramGroups as $group): ?>
|
||||
<option value="<?= htmlspecialchars($group['platform_id']) ?>" <?= ($defaultGroupSetting == $group['platform_id']) ? 'selected' : '' ?>>
|
||||
<?= htmlspecialchars($group['name']) ?> (ID: <?= htmlspecialchars($group['platform_id']) ?>)
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<div class="form-text" data-translate="true">Selecciona el grupo al que se enviarán los mensajes al usar el comando "Enviar a grupo #comando" desde el chat del bot.</div>
|
||||
</div>
|
||||
<button type="submit" name="save_general_settings" class="btn btn-primary">
|
||||
<i class="bi bi-save-fill me-1"></i> <span data-translate="true">Guardar Ajustes de Comandos</span>
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
require_once __DIR__ . '/../../templates/footer.php';
|
||||
?>
|
||||
Reference in New Issue
Block a user