envío automático de índices
This commit is contained in:
@ -18,6 +18,7 @@ repositories {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'org.telegram:telegrambots-spring-boot-starter:6.9.7.0'
|
||||
implementation 'org.telegram:telegrambots-abilities:6.9.7.0'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-logging'
|
||||
|
@ -0,0 +1,41 @@
|
||||
package es.imunnic.inversionitasBot;
|
||||
|
||||
public class IndiceRequest {
|
||||
private String indice;
|
||||
private double valorActual;
|
||||
private double cambio; // Nuevo campo agregado
|
||||
private String porcentaje;
|
||||
|
||||
// Getters y Setters
|
||||
public String getIndice() {
|
||||
return indice;
|
||||
}
|
||||
|
||||
public void setIndice(String indice) {
|
||||
this.indice = indice;
|
||||
}
|
||||
|
||||
public double getValorActual() {
|
||||
return valorActual;
|
||||
}
|
||||
|
||||
public void setValorActual(double valorActual) {
|
||||
this.valorActual = valorActual;
|
||||
}
|
||||
|
||||
public double getCambio() {
|
||||
return cambio;
|
||||
}
|
||||
|
||||
public void setCambio(double cambio) {
|
||||
this.cambio = cambio;
|
||||
}
|
||||
|
||||
public String getPorcentaje() {
|
||||
return porcentaje;
|
||||
}
|
||||
|
||||
public void setPorcentaje(String porcentaje) {
|
||||
this.porcentaje = porcentaje;
|
||||
}
|
||||
}
|
@ -25,6 +25,8 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
//@Value("${telegram.bot.token}")
|
||||
private String BOT_TOKEN = "7626026035:AAHEMp_iIN3y8AwywL0R6OTQvNi7EcJZ0iY";
|
||||
|
||||
protected String CHAT_ID = "-1002289752202";
|
||||
|
||||
@Override
|
||||
public String getBotUsername() {
|
||||
return BOT_USERNAME;
|
||||
@ -49,7 +51,7 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
}
|
||||
}
|
||||
|
||||
private void sendMessage(String chatId, String text) {
|
||||
protected void sendMessage(String chatId, String text) {
|
||||
// Primero dividimos el mensaje si es necesario
|
||||
List<String> partes = dividirMensaje(text);
|
||||
|
||||
@ -70,7 +72,7 @@ public class TelegramBot extends TelegramLongPollingBot {
|
||||
|
||||
@Scheduled(cron = "0 0 13,20 * * ?", zone = "Europe/Paris")
|
||||
private void mensajeProgramado(){
|
||||
this.construirResumenNoticias("-1002289752202");
|
||||
this.construirResumenNoticias(this.CHAT_ID);
|
||||
}
|
||||
|
||||
private void construirResumenNoticias(String chatid) {
|
||||
|
@ -0,0 +1,27 @@
|
||||
package es.imunnic.inversionitasBot;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/telegram")
|
||||
public class TelegramController {
|
||||
|
||||
private final TelegramBot telegramBot;
|
||||
|
||||
public TelegramController(TelegramBot telegramBot) {
|
||||
this.telegramBot = telegramBot;
|
||||
}
|
||||
|
||||
@PostMapping("/send")
|
||||
public void sendMessage(@RequestBody IndiceRequest request) {
|
||||
String mensaje = String.format(
|
||||
"*📊 Índice:* `%s`\n" +
|
||||
"*💰 Valor Actual:* `%,.2f`\n" +
|
||||
"*📉 Cambio:* `%,.2f`\n" +
|
||||
"*📈 Cambio(%):* `%s`",
|
||||
request.getIndice(), request.getValorActual(), request.getPorcentaje()
|
||||
);
|
||||
telegramBot.sendMessage(telegramBot.CHAT_ID, mensaje );
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user