If you don't own the other bot and hence don't have access to its token, directly accessing it in the manner you originally envisaged (i.e., sending messages to it and receiving responses directly) isn't possible. Bot tokens are akin to passwords and are only provided to the developers who own or manage the bot. Telegram and other messaging platforms do not allow bots to send messages directly to each other as a security measure, and even if they could, you would need access control tokens to do so.
Alternative Solutions:
Since interacting directly with a bot you do not own via its token is out of the question, here are a couple of alternative methods you might consider:
1. User-initiated communication:
Instead of trying to programmatically send messages to the other bot, direct your users to interact with the bot themselves. For example, if the interaction must occur within a Telegram group chat, you can instruct users on how to initiate commands with the other bot within the group.
2. Utilize Public APIs:
Some bots, especially those designed to be interacted with by a wide range of users or applications, might expose a public API. These APIs typically provide a proper way to interact with the bot's features securely without needing the bot's token. Check if the bot offers a public API, and if so, utilize this API to implement your functionality.
3. Collaboration with the Bot Owner:
If your interest in the bot is part of a bigger project or business process, consider reaching out to the bot owner for a partnership or collaboration. This might lead to them providing you access to certain endpoints that can interact securely with the bot under controlled conditions.
4. Manual Interaction:
If automatic interaction isn't possible, perhaps a manual process where an intermediary (a person) interacts with both bots could be set up. This would be less efficient but might be feasible depending on the scale of your project.
5. Creating a User-level Interface:
Design an interface where the user interacts directly with your bot, which collects the necessary information and prompts the user on how to use the other bot themselves effectively. This method maintains user control and transparency.
Implementing a Relay Through User Interactions:
If you still need to facilitate some form of automated communication between your users and the external bot, consider creating a mechanism that formats user commands which can be easily copied and pasted into the external bot by the users themselves:
function doPost(e) {
var data = JSON.parse(e.postData.contents);
var chatId = data.message.chat.id;
var text = data.message.text;
var preparedCommand = prepareCommandForExternalBot(text);
sendMessageToUser(chatId, "Please copy and paste the following command to interact with the other bot: \n" + preparedCommand);
}
function prepareCommandForExternalBot(userInput) {
// Modify or format the text properly to work effectively when pasted by the user into the other bot.
return "Formatted Command Based on: " + userInput;
}
function sendMessageToUser(chatId, message) {
var token = "YOUR_BOT_TOKEN";
var url = 'https://api.telegram.org/bot' + token + '/sendMessage?chat_id=' + chatId + '&text=' + encodeURIComponent(message);
UrlFetchApp.fetch(url);
}
This script takes the user's input, 'formats' it in case you need to adapt the syntax to the external bot's commands (this would be manual by the users, so ensure you respect user intent and ethics) and instructs them how to interact directly.
Conclusion
Direct bot-to-bot communication when you don't control one of the bots is typically not feasible. Focus on guiding user interactions, collaborating with bot owners, or relying on public APIs where possible for automation or interaction.