I followed the documentation and implementing SpringLongPollingBot,LongPollingSingleThreadUpdateConsumer method. I also wrote a ping method inside consume(List<Update> list){} and consume(Update update){}. However, after startup, while some initial messages are retrieved, no messages are being printed afterward, whether in private chats with the bot or in a group. What should I do to ensure that messages are received in real-time?
@Component
public class BotTowServiceImpl implements SpringLongPollingBot, LongPollingSingleThreadUpdateConsumer {
private BotConfig config;
private final TelegramClient telegramClient;
public BotTowServiceImpl(BotConfig config) {
this.config = config;
telegramClient = new OkHttpTelegramClient(getBotToken());
}
@Override
public String getBotToken() {
return config.getToken();
}
@Override
public LongPollingUpdateConsumer getUpdatesConsumer() {
return this;
}
@AfterBotRegistration
public void afterRegistration(BotSession botSession) {
System.out.println("Registered bot running state is: " + botSession.isRunning());
}
@Override
public void consume(List<Update> list) {
if(list.size()>0){
for (Update update:list) {
if(update.hasMessage()){
System.out.println(update.getMessage());
Chat chat = update.getMessage().getChat();
long chatId = update.getMessage().getChatId();
String messageText = update.getMessage().getText();
System.out.println(messageText);
User user = update.getMessage().getFrom();
String message_text = "Hey,"+user.getFirstName()+",Welcome to chat "+chat.getTitle();
SendMessage message = new SendMessage(String.valueOf(chatId),message_text);
try {
telegramClient.execute(message);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
}
@Override
public void consume(Update update) {
System.out.println("message:"+update.getMessage());
if (update.hasMessage() && update.getMessage().hasText()) {
// Set variables
String message_text = update.getMessage().getText();
long chat_id = update.getMessage().getChatId();
SendMessage message = SendMessage // Create a message object
.builder()
.chatId(chat_id)
.text(message_text)
.build();
try {
telegramClient.execute(message); // Sending our message object to user
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
I followed the documentation and implementing
SpringLongPollingBot
,LongPollingSingleThreadUpdateConsumer
method. I also wrote aping
method insideconsume(List<Update> list){}
andconsume(Update update){}
. However, after startup, while some initial messages are retrieved, no messages are being printed afterward, whether in private chats with the bot or in a group. What should I do to ensure that messages are received in real-time?@Component public class BotTowServiceImpl implements SpringLongPollingBot, LongPollingSingleThreadUpdateConsumer {
}
who can help check?