Second Telegram Bot Cannot Detect Messages from First Bot

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?

Indeed, this is an inherent limitation in how Telegram operates. Bots are designed not to receive messages sent by other bots to avoid potential system abuse. I’ve faced a similar situation when developing an inter-bot communication system. My solution involved establishing a simple HTTP API that both bots could use. When the first bot sends a message, it triggers a POST request to the endpoint of the second bot. This effectively bypasses Telegram for bot-to-bot communication while maintaining the regular functionality in your chat. Alternatively, implementing a message queue, like Redis, could also aid in this scenario where the first bot publishes its messages and the second one subscribes.

Yeah, that’s how Telegram works. Bots can’t see messages from other bots in the same chat - doesn’t matter if they’re admins or what privacy settings you have. I hit this same wall last year building a monitoring system for multiple bots. My solution was a shared database where the first bot writes its messages and the second bot reads from there. You could also use webhooks with a common endpoint both bots can hit. There’s just no way to get bots talking to each other through regular Telegram messages.

yeah, that’s a common issue. bots can’t see messages from other bots due to tgram’s settings. maybe create a user account for the first bot to send messages, or look into using the client API. hope that helps!