import { NextResponse } from 'next/server' export async function POST(request: Request) { try { const { botToken, chatId } = await request.json() if (!botToken || !chatId) { return NextResponse.json( { success: false, error: 'Faltan credenciales (Token o Chat ID)' }, { status: 400 } ) } const message = "🤖 *Prueba de Conexión*\n\n¡Hola! Si lees esto, tu bot de Finanzas está correctamente configurado. 🚀" const url = `https://api.telegram.org/bot${botToken}/sendMessage` const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ chat_id: chatId, text: message, parse_mode: 'Markdown' }) }) const data = await response.json() if (!data.ok) { return NextResponse.json( { success: false, error: data.description || 'Error desconocido de Telegram' }, { status: 500 } ) } return NextResponse.json({ success: true, data }) } catch (error: any) { console.error('Telegram Test Error:', error) return NextResponse.json( { success: false, error: error.message || 'Error interno del servidor' }, { status: 500 } ) } }