rubenlagus / TelegramBots

Java library to create bots using Telegram Bots API
https://telegram.me/JavaBotsApi
MIT License
4.68k stars 1.18k forks source link

Telegram bot is not running in Spring 3.1.0 #1226

Closed zsanzharko closed 1 year ago

zsanzharko commented 1 year ago

Describe the bug Hi! I can't see when telegram bot is running in spring. He's just start and stoping.

Code

package kz.tiger.zone.tigerzoneshopbot.bot;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Update;

@Component
@Slf4j
public class ShopBot extends TelegramLongPollingBot {
    private final String botUsername;

    public ShopBot(@Value("${bot.username}") String botUsername,
                   @Value("${bot.token}") String botToken) {
        super(botToken);
        this.botUsername = botUsername;
    }

    @Override
    public void onUpdateReceived(Update update) {
        log.info("Work!");
    }

    @Override
    public String getBotUsername() {
        return botUsername;
    }
}

LOG


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::                (v3.1.0)

2023-05-28T17:50:08.302+06:00  INFO 28032 --- [           main] k.t.z.t.TigerZoneShopBotApplication      : Starting TigerZoneShopBotApplication using Java 17.0.7 with PID 28032 (D:\develop\projects\tiger-zone-shop-bot\build\classes\java\main started by Legion in D:\develop\projects\tiger-zone-shop-bot)
2023-05-28T17:50:08.305+06:00  INFO 28032 --- [           main] k.t.z.t.TigerZoneShopBotApplication      : No active profile set, falling back to 1 default profile: "default"
2023-05-28T17:50:08.671+06:00  INFO 28032 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2023-05-28T17:50:08.692+06:00  INFO 28032 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 13 ms. Found 0 JPA repository interfaces.
2023-05-28T17:50:08.988+06:00  INFO 28032 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-05-28T17:50:09.226+06:00  INFO 28032 --- [           main] com.zaxxer.hikari.pool.HikariPool        : HikariPool-1 - Added connection org.postgresql.jdbc.PgConnection@40712ee9
2023-05-28T17:50:09.229+06:00  INFO 28032 --- [           main] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-05-28T17:50:09.294+06:00  INFO 28032 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: default]
2023-05-28T17:50:09.365+06:00  INFO 28032 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.2.2.Final
2023-05-28T17:50:09.366+06:00  INFO 28032 --- [           main] org.hibernate.cfg.Environment            : HHH000406: Using bytecode reflection optimizer
2023-05-28T17:50:09.505+06:00  INFO 28032 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-05-28T17:50:09.643+06:00  INFO 28032 --- [           main] o.s.o.j.p.SpringPersistenceUnitInfo      : No LoadTimeWeaver setup: ignoring JPA class transformer
2023-05-28T17:50:09.694+06:00  INFO 28032 --- [           main] org.hibernate.orm.dialect                : HHH035001: Using dialect: org.hibernate.dialect.PostgreSQLDialect, version: org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$DialectResolutionInfoImpl@50b0afd7
2023-05-28T17:50:09.872+06:00  INFO 28032 --- [           main] o.h.b.i.BytecodeProviderInitiator        : HHH000021: Bytecode provider name : bytebuddy
2023-05-28T17:50:10.046+06:00  INFO 28032 --- [           main] o.h.e.t.j.p.i.JtaPlatformInitiator       : HHH000490: Using JtaPlatform implementation: [org.hibernate.engine.transaction.jta.platform.internal.NoJtaPlatform]
2023-05-28T17:50:10.050+06:00  INFO 28032 --- [           main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2023-05-28T17:50:10.425+06:00  INFO 28032 --- [           main] k.t.z.t.TigerZoneShopBotApplication      : Started TigerZoneShopBotApplication in 2.495 seconds (process running for 3.068)
2023-05-28T17:50:10.430+06:00  INFO 28032 --- [ionShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2023-05-28T17:50:10.432+06:00  INFO 28032 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-05-28T17:50:10.439+06:00  INFO 28032 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

Information

centralhardware commented 1 year ago

are you sure that classpath contain starter?

zsanzharko commented 1 year ago

@centralhardware Are you mean about gradle dependencies? This is my dep.

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
    implementation 'org.springframework.boot:spring-boot-starter-jdbc'
    compileOnly 'org.projectlombok:lombok'
    implementation 'org.postgresql:postgresql'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
    implementation 'org.telegram:telegrambots-spring-boot-starter:6.5.0'
}
Aryesia commented 1 year ago

I have same problem, but I fixed that after created annotation:

image

And use it with MainApplicationClass

zsanzharko commented 1 year ago

@rubenlagus What do you think?

Programistich commented 1 year ago

@Aryesia but its not help, i create extend TelegramLongPollingBot and add EnableTelegramBot to application and no print update

Aryesia commented 1 year ago

@Programistich Hmm.. It's working for me. Maybe you have another problem (Proofs in screenshots)

Снимок экрана 2023-06-05 в 00 28 02 Снимок экрана 2023-06-05 в 00 22 51
Programistich commented 1 year ago

Can u share this project?

Programistich commented 1 year ago
image image

And no one updates print

Programistich commented 1 year ago
image

if i register manual i have error

DefaultBotSession : Error executing org.telegram.telegrambots.meta.api.methods.updates.GetUpdates query: [409] Conflict: terminated by other getUpdates request; make sure that only one bot instance is running

TheNullablePrototype commented 1 year ago

Running with:

Spring Boot v3.1.0 Spring v6.0.9 Java 20.0.1 Gradle-8.1.1

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.1.0'
    id 'io.spring.dependency-management' version '1.1.0'
}

group = 'group'
version = '0.0.1-SNAPSHOT'
sourceCompatibility = '17'

configurations {
    compileOnly {
        extendsFrom annotationProcessor
    }
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter'
    compileOnly 'org.projectlombok:lombok'

    implementation 'org.telegram:telegrambots:6.7.0'
    implementation 'org.telegram:telegrambots-spring-boot-starter:6.7.0'
    implementation 'org.telegram:telegrambotsextensions:6.7.0'

    developmentOnly 'org.springframework.boot:spring-boot-devtools'
    annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
    annotationProcessor 'org.projectlombok:lombok'
    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

tasks.named('test') {
    useJUnitPlatform()
}
@Import({TelegramBotStarterConfiguration.class})
@SpringBootApplication
public class TelegramBotApplication {
    public static void main(String[] args) {
        SpringApplication.run(TelegramBotApplication.class, args);
    }
}

works fine

zsanzharko commented 1 year ago

Now latest version for telegram is 2.7.12

https://github.com/rubenlagus/TelegramBots/commit/a48c4b2b94c550597a77e70205a284ac9dd7ec07