import { NextResponse } from 'next/server'; import { auth } from '@/lib/auth'; import { telegramService } from '@/lib/telegram-service'; import { getUserNotificationSettings } from '@/lib/notification-settings-db'; // POST /api/users/[id]/notification-settings/test export async function POST( request: Request, { params }: { params: Promise<{ id: string }> } ) { try { const session = await auth(); if (!session?.user) { return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }); } const { id: userId } = await params; const currentUserId = (session.user as any).id; if (userId !== currentUserId) { return NextResponse.json({ error: 'Forbidden' }, { status: 403 }); } const settings = getUserNotificationSettings(userId); if (!settings.telegram_chat_id) { return NextResponse.json( { error: 'No Telegram chat ID configured' }, { status: 400 } ); } const success = await telegramService.testConnection( settings.telegram_chat_id ); if (success) { return NextResponse.json({ success: true, message: 'Test message sent' }); } else { return NextResponse.json( { error: 'Failed to send test message' }, { status: 500 } ); } } catch (error) { console.error('[POST /api/users/[id]/notification-settings/test]', error); return NextResponse.json( { error: 'Failed to send test message' }, { status: 500 } ); } }