// Best-effort Telegram notification — a failed send never blocks the form // submission it's attached to (the message is already saved in the DB by // the time this runs; Telegram is a convenience notification, not the // source of truth). export async function sendTelegramMessage(text: string): Promise { const token = process.env.TELEGRAM_BOT_TOKEN const chatId = process.env.TELEGRAM_CHAT_ID if (!token || !chatId) return try { 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, disable_web_page_preview: true }), }) if (!res.ok) { console.error('Telegram notification failed:', res.status, await res.text()) } } catch (e) { console.error('Telegram notification error:', e) } } function formatIstanbulDate(date: Date): string { return new Intl.DateTimeFormat('tr-TR', { timeZone: 'Europe/Istanbul', day: '2-digit', month: '2-digit', year: 'numeric', hour: '2-digit', minute: '2-digit', second: '2-digit', hour12: false, }).format(date) } export function formatContactMessageNotification(params: { name: string email: string subject: string message: string ip: string }): string { return [ '⚡ [Marmaris Local] Yeni İletişim Talebi', '', '📍 Kaynak: marmarislocal.com / İletişim Formu', `👤 Ad Soyad: ${params.name}`, `📧 E-posta: ${params.email}`, `📋 Konu: ${params.subject}`, `🌐 IP Adresi: ${params.ip}`, `⏰ Tarih: ${formatIstanbulDate(new Date())}`, '', '📝 Mesaj:', params.message, ].join('\n') } export function formatBusinessSubmissionNotification(params: { businessName: string categoryName: string neighborhoodName: string address: string phone?: string | null whatsapp?: string | null description: string contactName: string contactEmail: string ip: string }): string { return [ '🏢 [Marmaris Local] Yeni İşletme Başvurusu', '', '📍 Kaynak: marmarislocal.com / İşletme Ekle Formu', `🏷️ İşletme Adı: ${params.businessName}`, `📂 Kategori: ${params.categoryName}`, `📌 Mahalle: ${params.neighborhoodName}`, `🏠 Adres: ${params.address}`, ...(params.phone ? [`☎️ Telefon: ${params.phone}`] : []), ...(params.whatsapp ? [`💬 WhatsApp: ${params.whatsapp}`] : []), `👤 Başvuran: ${params.contactName}`, `📧 E-posta: ${params.contactEmail}`, `🌐 IP Adresi: ${params.ip}`, `⏰ Tarih: ${formatIstanbulDate(new Date())}`, '', '📝 Açıklama:', params.description, '', 'Onaylamak için admin panel → Başvurular.', ].join('\n') }