From 2642d254dc39255a1134d389036e5226c891732c Mon Sep 17 00:00:00 2001 From: AyrisAI Date: Thu, 14 May 2026 13:55:29 +0300 Subject: [PATCH] fix: use JSON for mail mappings to fix deployment shell error --- app/api/webhooks/mail/route.ts | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/api/webhooks/mail/route.ts b/app/api/webhooks/mail/route.ts index 54bb0c7..f69ac06 100644 --- a/app/api/webhooks/mail/route.ts +++ b/app/api/webhooks/mail/route.ts @@ -19,9 +19,17 @@ export async function POST(req: NextRequest) { console.log(`[Mail Webhook] Yeni mail geldi: ${sender} -> ${aliciMail}`); - // 1. Find which USER_X owns this mail address via MAIL_email=USER_X mapping - const envKey = `MAIL_${aliciMail}`; - const ownerUserKey = process.env[envKey]; // e.g., "USER_0" + // 1. Find which USER_X owns this mail address via JSON mapping + // Format: MAIL_USER_MAPPINGS='{"email1@domain.com":"USER_0", "email2@domain.com":"USER_1"}' + const mappingsRaw = process.env.MAIL_USER_MAPPINGS || "{}"; + let ownerUserKey: string | undefined = undefined; + + try { + const mappings = JSON.parse(mappingsRaw); + ownerUserKey = mappings[aliciMail]; + } catch (e) { + console.error("[Mail Webhook] MAIL_USER_MAPPINGS JSON ayrıştırma hatası:", e); + } if (ownerUserKey) { // 2. Get that USER's Telegram ID (e.g., USER_0_TELEGRAM_ID)