I’m working with two Java-based Telegram bots and facing an issue. The first bot successfully sends automated messages every 10 minutes. However, my second bot is supposed to capture these messages and save them to a text file, but it’s not working.
The problem is that my second bot only detects messages from regular users, not from other bots. I’ve already configured both bots through BotFather with privacy mode disabled and group access enabled. Both bots have admin privileges in the group.
Here’s my listener bot code:
public class MessageListener extends TelegramLongPollingBot {
private final String API_TOKEN = "****************************";
private final String USERNAME = "*****************";
@Override
public void onUpdateReceived(Update updateData) {
long chatIdentifier = 0;
int messageIdentifier = 0;
String messageContent = "";
try { // handle channel messages
chatIdentifier = updateData.getChannelPost().getChatId();
messageContent = updateData.getChannelPost().getText();
messageIdentifier = updateData.getChannelPost().getMessageId();
} catch (Exception ex1) {}
try { // handle regular messages
chatIdentifier = updateData.getMessage().getChatId();
messageContent = updateData.getMessage().getText();
messageIdentifier = updateData.getMessage().getMessageId();
} catch (Exception ex2) {}
System.out.println(chatIdentifier);
System.out.println(messageIdentifier);
System.out.println(messageContent);
}
@Override
public String getBotUsername() {
return USERNAME;
}
@Override
public String getBotToken() {
return API_TOKEN;
}
}
When I send messages as a regular user, everything works fine and I see the output in console. But when my first bot sends messages, nothing appears. What am I missing here?