Files
finanzas/app/api/auth/send/route.ts

26 lines
845 B
TypeScript

import { NextResponse } from 'next/server';
import TelegramBot from 'node-telegram-bot-api';
import { generateOTP, saveOTP } from '@/lib/otp';
export async function POST() {
const token = process.env.TELEGRAM_BOT_TOKEN;
const chatId = process.env.TELEGRAM_CHAT_ID;
if (!token || !chatId) {
console.error("Telegram credentials missing");
return NextResponse.json({ error: 'Telegram not configured' }, { status: 500 });
}
const otp = generateOTP();
saveOTP(otp);
const bot = new TelegramBot(token, { polling: false });
try {
await bot.sendMessage(chatId, `🔐 Your Login Code: ${otp}`);
return NextResponse.json({ success: true });
} catch (error: any) {
console.error('Telegram Error:', error);
return NextResponse.json({ error: 'Failed to send message: ' + error.message }, { status: 500 });
}
}