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

How to use TelegramLongPollingCommandBot with TelegramLongPollingBot using Spring #1035

Closed zsanzharko closed 2 years ago

zsanzharko commented 2 years ago

Hello! How to use these two classes together using Spring?

Sample code

@Slf4j
public abstract class CommandsHandler extends TelegramLongPollingCommandBot {

public static final String LOGTAG = "COMMANDS-HANDLER";

    // using methods 
     // getusername
     // gettoken
}

one of the main clases using TelegramLongPollingBot extention `

@Slf4j
@Component
@Getter
public class EventsBotApp extends TelegramLongPollingBot {
    // using methods 
    // getusername
    // gettoken
}

`

i have conflict in running the project org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException: Error getting updates: [409] Conflict: terminated by other getUpdates request; make sure that only one bot instance is running at org.telegram.telegrambots.meta.api.methods.updates.GetUpdates.deserializeResponse(GetUpdates.java:93) ~[telegrambots-meta-5.7.1.jar:na] at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.getUpdatesFromServer(DefaultBotSession.java:260) ~[telegrambots-5.7.1.jar:na] at org.telegram.telegrambots.updatesreceivers.DefaultBotSession$ReaderThread.run(DefaultBotSession.java:189) ~[telegrambots-5.7.1.jar:na]

rubenlagus commented 2 years ago

That error implies that you are running 2 instances of the bot, as per Telegram limitation, you can only run one of them. You should be able to create a simple Bean and then inject it whenever you need your bot.

zsanzharko commented 2 years ago

@rubenlagus Thanks!