Исправил записи
This commit is contained in:
Generated
+4139
File diff suppressed because it is too large
Load Diff
@@ -1,42 +0,0 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const data = await req.json();
|
||||
|
||||
const token = process.env.TELEGRAM_BOT_TOKEN;
|
||||
const chatId = process.env.TELEGRAM_CHAT_ID;
|
||||
|
||||
if (!token || !chatId) {
|
||||
return NextResponse.json({ error: 'Missing env vars' }, { status: 500 });
|
||||
}
|
||||
console.log('gr')
|
||||
|
||||
const text = `
|
||||
<b>📬 Новая заявка</b>
|
||||
|
||||
🎮 Действие: ${data.type || '—'}
|
||||
🖥 Кабина: ${data.room || '—'}
|
||||
📅 Дата: ${data.date || '—'}
|
||||
⏰ Время: ${data.time || '—'}
|
||||
🧑 Имя: ${data.name || '—'}
|
||||
🎮 Игра: ${data.game || '—'}
|
||||
📞 Контакт: ${data.contact || '—'}
|
||||
💬 Связь: ${data.contactMethod || '—'}
|
||||
`;
|
||||
|
||||
const res = await fetch(`https://api.telegram.org/bot${token}/sendMessage`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
chat_id: chatId,
|
||||
text,
|
||||
parse_mode: 'HTML',
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
return NextResponse.json({ error: 'Failed to send' }, { status: 500 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true });
|
||||
}
|
||||
@@ -82,7 +82,6 @@ export default function BronModal() {
|
||||
|
||||
const handleSend = async (): Promise<boolean> => {
|
||||
try {
|
||||
// Сначала сохраняем в БД
|
||||
if (formData.date && formData.time && formData.room) {
|
||||
const bookingRes = await fetch('/api/bookings', {
|
||||
method: 'POST',
|
||||
@@ -101,17 +100,7 @@ export default function BronModal() {
|
||||
}
|
||||
}
|
||||
|
||||
// Затем отправляем в Telegram
|
||||
const res = await fetch('/api/send-to-telegram', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
...formData,
|
||||
time: formData.time || '—',
|
||||
}),
|
||||
});
|
||||
|
||||
return res.ok;
|
||||
return true;
|
||||
} catch (e) {
|
||||
console.error('Ошибка сети', e);
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user