Your lightweight open-source personal agent.
Python agent-frameworkai-agentai-agentschatbotchatopsdiscord-botllm-agentsllmslocal-llmmcpmodel-context-protocolmulti-agentopenai-compatibleopenclawpersonal-ai-assistantpythonself-hostedtelegram-bot-ai-assistantwebuiworkflow-automation
refactor: use explicit dependency injection for groq_api_key
Re-bin8989adc9aecd
diff --git a/nanobot/channels/manager.py b/nanobot/channels/manager.pyindex c32aa3da8..73c3334de 100644--- a/nanobot/channels/manager.py+++ b/nanobot/channels/manager.py@@ -36,10 +36,10 @@ class ChannelManager:if self.config.channels.telegram.enabled:try:from nanobot.channels.telegram import TelegramChannel- # Inject parent config for access to providers- self.config.channels.telegram.parent = self.configself.channels["telegram"] = TelegramChannel(- self.config.channels.telegram, self.bus+ self.config.channels.telegram,+ self.bus,+ groq_api_key=self.config.providers.groq.api_key,)logger.info("Telegram channel enabled")except ImportError as e:@@ -49,8 +49,6 @@ class ChannelManager:if self.config.channels.whatsapp.enabled:try:from nanobot.channels.whatsapp import WhatsAppChannel- # Inject parent config for access to providers- self.config.channels.whatsapp.parent = self.configself.channels["whatsapp"] = WhatsAppChannel(self.config.channels.whatsapp, self.bus)diff --git a/nanobot/channels/telegram.py b/nanobot/channels/telegram.pyindex 75b929982..23e1de00e 100644--- a/nanobot/channels/telegram.py+++ b/nanobot/channels/telegram.py@@ -85,9 +85,10 @@ class TelegramChannel(BaseChannel):name = "telegram"- def __init__(self, config: TelegramConfig, bus: MessageBus):+ def __init__(self, config: TelegramConfig, bus: MessageBus, groq_api_key: str = ""):super().__init__(config, bus)self.config: TelegramConfig = config+ self.groq_api_key = groq_api_keyself._app: Application | None = Noneself._chat_ids: dict[str, int] = {} # Map sender_id to chat_id for replies@@ -253,12 +254,7 @@ class TelegramChannel(BaseChannel):# Handle voice transcriptionif media_type == "voice" or media_type == "audio":from nanobot.providers.transcription import GroqTranscriptionProvider- # Try to get Groq API key from config- groq_key = None- if hasattr(self.config, 'parent') and hasattr(self.config.parent, 'providers'):- groq_key = self.config.parent.providers.groq.api_key-- transcriber = GroqTranscriptionProvider(api_key=groq_key)+ transcriber = GroqTranscriptionProvider(api_key=self.groq_api_key)transcription = await transcriber.transcribe(file_path)if transcription:logger.info(f"Transcribed {media_type}: {transcription[:50]}...")