import os
from typing import Iterable
from telegram import Bot

def broadcast_telegram(text: str, chat_ids: Iterable[int], parse_mode: str | None = "HTML"):
    token = os.getenv("TELEGRAM_BOT_TOKEN")
    if not token:
        raise RuntimeError("TELEGRAM_BOT_TOKEN 미설정")
    bot = Bot(token=token)
    for cid in chat_ids:
        try:
            bot.send_message(chat_id=cid, text=text, parse_mode=parse_mode, disable_web_page_preview=True)
        except Exception as e:
            print(f"[notify] send fail to {cid}: {e}")
