How to make one Telegram bot communicate with another?

I’ve created a Telegram bot that works fine for sending messages to groups and users. But I’m having trouble getting it to send messages to another bot. Even when both bots are admins in a group, my second bot can’t receive messages from the first one. Only my real user account in the group sees the messages.

I’m using OkHttp to send messages like this:

Request request = new Request.Builder()
    .url("https://api.telegram.org/bot" + botToken + "/sendMessage?chat_id=" + chatId + "&parse_mode=HTML&text=" + message)
    .build();
client.newCall(request).enqueue(new MessageHandler(request.toString()));

And for receiving messages:

if (response.isSuccessful()) {
    List<String> segments = response.request().url().encodedPathSegments();
    // Process segments
}

This setup works fine for talking to real users. But bot-to-bot communication isn’t working. Any suggestions on what I might be missing or how to fix this?

I’ve encountered this issue before. Telegram intentionally restricts direct bot-to-bot communication to prevent potential abuse. Instead, you’ll need to set up a server-side application to act as an intermediary between your bots. This application can receive updates from both bots via webhooks or long polling, process the information, and then send appropriate responses through each bot’s API. It’s a bit more complex, but it allows for more secure and controlled interactions. Remember to handle authentication carefully in your server-side code to ensure only authorized bots can communicate through your system.

hey man, bots cant talk to each other directly in telegram. its a security thing. you gotta use webhooks or polling to get updates from telegram servers for both bots. then have ur backend code handle the logic and communication between them. hope that helps!

I have encountered this issue before and resolved it by introducing a central server as an intermediary between the bots. In my experience, Telegram intentionally restricts direct bot-to-bot interaction for security reasons, so the solution was to have both bots connect via a server that handles updates. The server can use either webhooks or long polling to receive messages from Telegram, process them, and then send the necessary responses through the correct bot API endpoint.

While this setup adds some complexity, it also gives you additional control over interactions and the opportunity to integrate features such as logging and rate limiting. Just ensure that your server is secure and robust enough to handle the load.