Managed BotsBOT-ONLY
Bot Walkthrough 11 of 18
Bots that manage other bots can control their access settings and tokens.
Handling Updates
The managedBot update is sent when a managed bot is updated. It contains the managed bot and its owner.
client.on("managedBot", (ctx) => {
const { user: owner, bot } = ctx.update.managedBot;
console.log(owner.id, bot.id);
});
Managing Access
Use setManagedBotAccessSettings to restrict access to specific users. The bot owner always retains access.
await client.setManagedBotAccessSettings(managedBotId, true, {
usersWithAccess: [userId],
});
Use getManagedBotAccessSettings to read the current settings.
const settings = await client.getManagedBotAccessSettings(managedBotId);
Set isAccessRestricted to false to remove the restriction.
await client.setManagedBotAccessSettings(managedBotId, false);
Managing Tokens
Use getManagedBotToken to get the current token.
const token = await client.getManagedBotToken(managedBotId);
Use revokeManagedBotToken to revoke it. The method returns the new token.
const newToken = await client.revokeManagedBotToken(managedBotId);