Second Telegram Bot Not Detecting Messages from First Bot

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?

Yeah, this is a core limitation of Telegram’s bot system that bit me when I built something similar. Bots can’t see messages from other bots - period. It’s designed this way to prevent infinite loops and spam between automated systems.

I fixed this by ditching the polling approach and using webhooks instead. Set up your first bot to make HTTP POST requests to an endpoint your second app watches. When the first bot sends a message, it logs the data to your text file through the webhook at the same time. You’ll need to run a simple HTTP server with your listener app, but it completely sidesteps the bot-to-bot restriction.

Another option that’s worked well for me is Redis pub/sub messaging between the apps. Gives you real-time data transfer without depending on Telegram’s message detection at all.

Same issue here! Telegram blocks bots from reading other bots’ messages. Easy fix - have your first bot write messages to a text file, then the second bot reads from that file. Works perfectly!

Indeed, this situation arises from a well-known restriction in the Telegram Bot API. Bots are inherently unable to receive messages from other bots, regardless of any configurations such as privacy settings or admin roles. This limitation is intentional to curb issues like spam loops. I’ve encountered similar challenges while developing a bot that tracks other bots. Your implementation appears sound, but you are encountering a fundamental API restriction rather than a coding error. A feasible workaround is to have the first bot log messages to a shared database or file that the second bot can then access. Alternatively, employing a regular user account via the Telegram Client API could facilitate the relay of messages, albeit requiring a different authentication method and libraries.