(
self,
chat_agent: ChatAgent,
telegram_token: Optional[str] = None,
)
| 35 | |
| 36 | @dependencies_required('telebot') |
| 37 | def __init__( |
| 38 | self, |
| 39 | chat_agent: ChatAgent, |
| 40 | telegram_token: Optional[str] = None, |
| 41 | ) -> None: |
| 42 | self.chat_agent = chat_agent |
| 43 | |
| 44 | if not telegram_token: |
| 45 | self.token = os.getenv('TELEGRAM_TOKEN') |
| 46 | if not self.token: |
| 47 | raise ValueError( |
| 48 | "`TELEGRAM_TOKEN` not found in environment variables. " |
| 49 | "Get it from t.me/BotFather." |
| 50 | ) |
| 51 | else: |
| 52 | self.token = telegram_token |
| 53 | |
| 54 | import telebot # type: ignore[import-untyped] |
| 55 | |
| 56 | self.bot = telebot.TeleBot(token=self.token) |
| 57 | |
| 58 | # Register the message handler within the constructor |
| 59 | self.bot.message_handler(func=lambda message: True)(self.on_message) |
| 60 | |
| 61 | def run(self) -> None: |
| 62 | r"""Start the Telegram bot.""" |
nothing calls this directly
no outgoing calls
no test coverage detected