from __future__ import annotations

import requests


class TelegramNotifier:
    def __init__(self, bot_token: str, chat_id: str):
        if not bot_token or not chat_id:
            raise ValueError("TELEGRAM_BOT_TOKEN and TELEGRAM_CHAT_ID are required")
        self.bot_token = bot_token
        self.chat_id = chat_id
        self.base = f"https://api.telegram.org/bot{bot_token}"

    def send(self, text: str) -> dict:
        # Telegram hard limit ~4096 chars
        text = text[:4000]
        resp = requests.post(
            f"{self.base}/sendMessage",
            json={"chat_id": self.chat_id, "text": text, "disable_web_page_preview": False},
            timeout=30,
        )
        resp.raise_for_status()
        return resp.json()
