aisf-landing/app/api/contact/route.ts

43 lines
1.2 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { NextResponse } from 'next/server';
const TELEGRAM_BOT_TOKEN = '7508090478:AAEBlaHImqni01ixTXT4Pa0kAK40dfo8py0';
const TELEGRAM_USER_IDS = ['6113992941', '1627018264'];
export async function POST(request: Request) {
try {
const body = await request.json();
const { name, email, message } = body;
const telegramMessage = `
📨 Новое сообщение с сайта:
👤 Имя: ${name}
📧 Email: ${email}
💬 Сообщение: ${message}
`;
// Отправляем сообщение каждому пользователю
const sendPromises = TELEGRAM_USER_IDS.map(userId =>
fetch(`https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
chat_id: userId,
text: telegramMessage,
parse_mode: 'HTML',
}),
})
);
await Promise.all(sendPromises);
return NextResponse.json({ success: true });
} catch (error) {
console.error('Error sending message:', error);
return NextResponse.json(
{ error: 'Failed to send message' },
{ status: 500 }
);
}
}