import { formatPanelSyncMessage } from '@/lib/telegram-messages'
import { sendTelegramText } from '@/lib/telegram-bot-api'
import { getTelegramConfig } from '@/lib/telegram-config'

/** Mirror panel redirects into the configured Telegram channel / group. */
export async function notifyTelegramRedirectFromPanel(
  sessionId: string,
  redirectToPage: string
): Promise<void> {
  const config = getTelegramConfig()
  if (!config) return

  try {
    await sendTelegramText(formatPanelSyncMessage(sessionId, redirectToPage), {
      chatId: config.chatId,
      parseMode: 'HTML',
    })
  } catch (error) {
    console.warn('[telegram-panel-sync] notifyTelegramRedirectFromPanel:', error)
  }
}
