21 lines
571 B
Python

from .models import TelegramBot
def get_bot_token(bot_name: str) -> str:
"""
Retrieve the Telegram bot token by bot name.
Args:
bot_name (str): The name of the bot to fetch.
Returns:
str: The Telegram bot token.
Raises:
ValueError: If no active bot with the given name is found.
"""
try:
bot = TelegramBot.objects.get(name=bot_name, is_active=True)
return bot.token
except TelegramBot.DoesNotExist:
raise ValueError(f"No active bot found with the name '{bot_name}'")