Guides

Managed BotsBOT-ONLY

Bot Walkthrough 18 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

setManagedBotAccessSettings restricts access to specific users. The bot owner always retains access.

await client.setManagedBotAccessSettings(managedBotId, true, {
  usersWithAccess: [userId],
});

getManagedBotAccessSettings lets you read the current settings.

const settings = await client.getManagedBotAccessSettings(managedBotId);

A value of false for isAccessRestricted removes the restriction.

await client.setManagedBotAccessSettings(managedBotId, false);

Managing Tokens

To get the current token, call getManagedBotToken.

const token = await client.getManagedBotToken(managedBotId);

With revokeManagedBotToken, you can revoke it. The method returns the new token.

const newToken = await client.revokeManagedBotToken(managedBotId);