división de mensajes
This commit is contained in:
@ -184,4 +184,4 @@ def search_from_keywords_file():
|
||||
logging.info(f"Error al leer el archivo 'keywords.txt': {e}")
|
||||
|
||||
# Ejecutar la búsqueda desde el archivo
|
||||
search_from_keywords_file()
|
||||
|
||||
|
@ -40,8 +40,7 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
String chatId = update.getMessage().getChatId().toString();
|
||||
|
||||
if (messageText.equalsIgnoreCase("/resumen")) {
|
||||
String resumen = construirResumenNoticias();
|
||||
sendMessage(chatId, resumen);
|
||||
construirResumenNoticias(chatId);
|
||||
} else {
|
||||
sendMessage(chatId, "Comando no reconocido. Usa /resumen para obtener el resumen diario.");
|
||||
}
|
||||
@ -59,7 +58,7 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
}
|
||||
}
|
||||
|
||||
private String construirResumenNoticias() {
|
||||
private void construirResumenNoticias(String chatid) {
|
||||
LocalDate today = LocalDate.now();
|
||||
String fechaInicio = today.format(DateTimeFormatter.ISO_DATE);
|
||||
String fechaFin = today.plusDays(1).format(DateTimeFormatter.ISO_DATE);
|
||||
@ -67,23 +66,37 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
// Obtener las palabras clave de la API
|
||||
List<String> keywords = ApiService.getAllKeywords();
|
||||
|
||||
StringBuilder mensaje = new StringBuilder("📢 *Resumen de noticias del día:*\n\n");
|
||||
for (String keyword : keywords) {
|
||||
// Mensaje base para el encabezado
|
||||
String encabezado = "📢 **Resumen de noticias del día:**\n\n";
|
||||
|
||||
// Mensaje base para el pie
|
||||
String pie = "\n📢 ¡Mañana volveremos con más información!";
|
||||
|
||||
// Enviar el encabezado primero
|
||||
sendMessage(chatid,encabezado);
|
||||
|
||||
// Enviar los mensajes para cada keyword
|
||||
for (int i = 0; i < keywords.size(); i++) {
|
||||
String keyword = keywords.get(i);
|
||||
StringBuilder mensaje = new StringBuilder();
|
||||
|
||||
// Obtener las noticias para cada keyword (ahora se obtiene una lista de títulos)
|
||||
List<String> titles = ApiService.getTitlesByKeyword(keyword, fechaInicio, fechaFin);
|
||||
|
||||
if (!titles.isEmpty()) {
|
||||
mensaje.append("🔹 *").append(keyword).append("*:\n");
|
||||
mensaje.append("🔹 **").append(keyword).append("**:\n");
|
||||
for (String title : titles) {
|
||||
mensaje.append(" - ").append(title).append("\n");
|
||||
}
|
||||
mensaje.append("\n");
|
||||
} else {
|
||||
mensaje.append("🔹 *").append(keyword).append("*: No hay noticias disponibles.\n\n");
|
||||
mensaje.append("🔹 **").append(keyword).append("**: No hay noticias disponibles.\n");
|
||||
}
|
||||
|
||||
// Enviar el mensaje para la palabra clave
|
||||
sendMessage(chatid, mensaje.toString());
|
||||
}
|
||||
|
||||
mensaje.append("📢 ¡Mañana volveremos con más información!");
|
||||
return mensaje.toString();
|
||||
// Enviar el pie al final
|
||||
sendMessage(chatid, pie);
|
||||
}
|
||||
}
|
||||
|
@ -18,16 +18,16 @@ services:
|
||||
networks:
|
||||
- goshawk-network
|
||||
|
||||
# telegrambot:
|
||||
# build: ./bot
|
||||
# container_name: telegrambot_app
|
||||
# restart: always
|
||||
# ports:
|
||||
# - "8180:8080"
|
||||
# depends_on:
|
||||
# - app
|
||||
# networks:
|
||||
# - goshawk-network
|
||||
telegrambot:
|
||||
build: ./bot
|
||||
container_name: telegrambot_app
|
||||
restart: always
|
||||
ports:
|
||||
- "8180:8080"
|
||||
depends_on:
|
||||
- app
|
||||
networks:
|
||||
- goshawk-network
|
||||
networks:
|
||||
goshawk-network:
|
||||
external: true
|
||||
|
Reference in New Issue
Block a user