I’m working with two Telegram bots built using Java. The first bot automatically sends messages every 10 minutes which works perfectly. However, my second bot is supposed to capture these messages and save them to a text file, but it’s not working as expected.
The issue is that my second bot only detects messages from regular users, not from other bots. I can see user messages in the console output, but when the first bot posts something, nothing appears.
I already checked the BotFather settings and disabled privacy mode plus enabled group functionality. Both bots have admin privileges in the group chat.
Here’s my listener bot code:
public class MessageListener extends TelegramLongPollingBot {
private final String TOKEN = "****************************";
private final String USERNAME = "*****************";
@Override
public void onUpdateReceived(Update updateData) {
long chatIdentifier = 0;
int messageIdentifier = 0;
String messageContent = "";
try { // channel messages
chatIdentifier = updateData.getChannelPost().getChatId();
messageContent = updateData.getChannelPost().getText();
messageIdentifier = updateData.getChannelPost().getMessageId();
} catch (Exception e1) {}
try { // regular chat messages
chatIdentifier = updateData.getMessage().getChatId();
messageContent = updateData.getMessage().getText();
messageIdentifier = updateData.getMessage().getMessageId();
} catch (Exception e2) {}
System.out.println(chatIdentifier);
System.out.println(messageIdentifier);
System.out.println(messageContent);
}
@Override
public String getBotUsername() {
return USERNAME;
}
@Override
public String getBotToken() {
return TOKEN;
}
}
What could be causing this problem? Any ideas on how to fix it?