Compare commits
2 Commits
f71da406d5
...
a0fcc90d31
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a0fcc90d31 | ||
|
|
00894751bd |
18
.npm/_logs/2026-05-14T13_30_23_576Z-debug-0.log
Normal file
18
.npm/_logs/2026-05-14T13_30_23_576Z-debug-0.log
Normal file
@@ -0,0 +1,18 @@
|
||||
0 verbose cli /opt/homebrew/Cellar/node@22/22.22.2/bin/node /opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/bin/npm-cli.js
|
||||
1 info using npm@10.9.7
|
||||
2 info using node@v22.22.2
|
||||
3 silly config load:file:/opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/npmrc
|
||||
4 silly config load:file:/Users/ayrisdev/Github/mailserver/.npmrc
|
||||
5 silly config load:file:/opt/homebrew/etc/npmrc
|
||||
6 verbose title npm exec prisma migrate dev --name add_notification_logs
|
||||
7 verbose argv "exec" "--" "prisma" "migrate" "dev" "--name" "add_notification_logs"
|
||||
8 verbose logfile logs-max:10 dir:/Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_30_23_576Z-
|
||||
9 verbose logfile /Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_30_23_576Z-debug-0.log
|
||||
10 silly logfile done cleaning log files
|
||||
11 http fetch GET https://registry.npmjs.org/npm attempt 1 failed with ENOTFOUND
|
||||
12 verbose cwd /Users/ayrisdev/Github/mailserver
|
||||
13 verbose os Darwin 24.6.0
|
||||
14 verbose node v22.22.2
|
||||
15 verbose npm v10.9.7
|
||||
16 verbose exit 1
|
||||
17 verbose code 1
|
||||
17
.npm/_logs/2026-05-14T13_30_35_429Z-debug-0.log
Normal file
17
.npm/_logs/2026-05-14T13_30_35_429Z-debug-0.log
Normal file
@@ -0,0 +1,17 @@
|
||||
0 verbose cli /opt/homebrew/Cellar/node@22/22.22.2/bin/node /opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/bin/npm-cli.js
|
||||
1 info using npm@10.9.7
|
||||
2 info using node@v22.22.2
|
||||
3 silly config load:file:/opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/npmrc
|
||||
4 silly config load:file:/Users/ayrisdev/Github/mailserver/.npmrc
|
||||
5 silly config load:file:/opt/homebrew/etc/npmrc
|
||||
6 verbose title npm exec prisma migrate dev --name add_notification_logs
|
||||
7 verbose argv "exec" "--" "prisma" "migrate" "dev" "--name" "add_notification_logs"
|
||||
8 verbose logfile logs-max:10 dir:/Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_30_35_429Z-
|
||||
9 verbose logfile /Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_30_35_429Z-debug-0.log
|
||||
10 silly logfile done cleaning log files
|
||||
11 verbose cwd /Users/ayrisdev/Github/mailserver
|
||||
12 verbose os Darwin 24.6.0
|
||||
13 verbose node v22.22.2
|
||||
14 verbose npm v10.9.7
|
||||
15 verbose exit 1
|
||||
16 verbose code 1
|
||||
17
.npm/_logs/2026-05-14T13_31_06_094Z-debug-0.log
Normal file
17
.npm/_logs/2026-05-14T13_31_06_094Z-debug-0.log
Normal file
@@ -0,0 +1,17 @@
|
||||
0 verbose cli /opt/homebrew/Cellar/node@22/22.22.2/bin/node /opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/bin/npm-cli.js
|
||||
1 info using npm@10.9.7
|
||||
2 info using node@v22.22.2
|
||||
3 silly config load:file:/opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/npmrc
|
||||
4 silly config load:file:/Users/ayrisdev/Github/mailserver/.npmrc
|
||||
5 silly config load:file:/opt/homebrew/etc/npmrc
|
||||
6 verbose title npm exec prisma db push
|
||||
7 verbose argv "exec" "--" "prisma" "db" "push"
|
||||
8 verbose logfile logs-max:10 dir:/Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_31_06_094Z-
|
||||
9 verbose logfile /Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_31_06_094Z-debug-0.log
|
||||
10 silly logfile done cleaning log files
|
||||
11 verbose cwd /Users/ayrisdev/Github/mailserver
|
||||
12 verbose os Darwin 24.6.0
|
||||
13 verbose node v22.22.2
|
||||
14 verbose npm v10.9.7
|
||||
15 verbose exit 1
|
||||
16 verbose code 1
|
||||
17
.npm/_logs/2026-05-14T13_56_06_958Z-debug-0.log
Normal file
17
.npm/_logs/2026-05-14T13_56_06_958Z-debug-0.log
Normal file
@@ -0,0 +1,17 @@
|
||||
0 verbose cli /opt/homebrew/Cellar/node@22/22.22.2/bin/node /opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/bin/npm-cli.js
|
||||
1 info using npm@10.9.7
|
||||
2 info using node@v22.22.2
|
||||
3 silly config load:file:/opt/homebrew/Cellar/node@22/22.22.2/lib/node_modules/npm/npmrc
|
||||
4 silly config load:file:/Users/ayrisdev/Github/mailserver/.npmrc
|
||||
5 silly config load:file:/opt/homebrew/etc/npmrc
|
||||
6 verbose title npm exec tsx scratch/check_logs.ts
|
||||
7 verbose argv "exec" "--" "tsx" "scratch/check_logs.ts"
|
||||
8 verbose logfile logs-max:10 dir:/Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_56_06_958Z-
|
||||
9 verbose logfile /Users/ayrisdev/Github/mailserver/.npm/_logs/2026-05-14T13_56_06_958Z-debug-0.log
|
||||
10 silly logfile done cleaning log files
|
||||
11 verbose cwd /Users/ayrisdev/Github/mailserver
|
||||
12 verbose os Darwin 24.6.0
|
||||
13 verbose node v22.22.2
|
||||
14 verbose npm v10.9.7
|
||||
15 verbose exit 1
|
||||
16 verbose code 1
|
||||
0
.npm/_update-notifier-last-checked
Normal file
0
.npm/_update-notifier-last-checked
Normal file
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { getLatestEmail } from '@/lib/mail';
|
||||
import { sendTelegramNotification } from '@/lib/notifications';
|
||||
|
||||
// Bu kısım normalde .env içinde olmalı
|
||||
const WEBHOOK_SECRET = 'besiktasK1903*';
|
||||
@@ -14,7 +15,7 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { to, event, timestamp } = body;
|
||||
const { to, event, subject: incomingSubject, body: incomingBody, from: incomingFrom } = body;
|
||||
|
||||
console.log(`📩 Webhook Sinyali Alındı! Alıcı: ${to}`);
|
||||
|
||||
@@ -30,49 +31,71 @@ export async function POST(request: Request) {
|
||||
return NextResponse.json({ success: true, message: 'No mapping found' });
|
||||
}
|
||||
|
||||
// 2. Mailcow'dan son maili çek
|
||||
// Not: Master password kullanılıyorsa format 'user@domain.tld*master@domain.tld' şeklindedir
|
||||
const loginUser = IMAP_PASSWORD ? `${to}*${process.env.MAILCOW_MASTER_USER || 'admin'}` : to;
|
||||
const mailData = await getLatestEmail(to, IMAP_PASSWORD);
|
||||
// 2. Mail İçeriğini Belirle (Ya gelen body'den ya da IMAP'ten)
|
||||
let mailData = null;
|
||||
|
||||
if (incomingSubject && incomingBody) {
|
||||
console.log("[Signal] İçerik worker'dan hazır geldi.");
|
||||
mailData = {
|
||||
subject: incomingSubject,
|
||||
text: incomingBody,
|
||||
from: incomingFrom || "Bilinmiyor"
|
||||
};
|
||||
} else {
|
||||
console.log("[Signal] İçerik eksik, IMAP'e gidiliyor...");
|
||||
mailData = await getLatestEmail(to, IMAP_PASSWORD);
|
||||
}
|
||||
|
||||
if (!mailData) {
|
||||
console.error(`[Signal] Mail içeriği çekilemedi: ${to}`);
|
||||
return NextResponse.json({ success: false, error: 'Could not fetch mail' }, { status: 500 });
|
||||
}
|
||||
|
||||
console.log(`[Signal] Mail Çekildi: "${mailData.subject}"`);
|
||||
console.log(`[Signal] Mail İşleniyor: "${mailData.subject}"`);
|
||||
|
||||
// 3. İçerik Analizi (BMW, Penti vb.)
|
||||
let processed = false;
|
||||
let extraInfo = "";
|
||||
const content = (mailData.subject + " " + mailData.text).toLowerCase();
|
||||
|
||||
if (content.includes("bmw") || content.includes("tamir")) {
|
||||
console.log("🚗 BMW/Tamir içerikli mail tespit edildi!");
|
||||
// Burada bildirim fırlatılacak
|
||||
console.log("🚗 [Signal] BMW/Tamir içerikli mail tespit edildi!");
|
||||
extraInfo = "🚗 BMW/Tamir İlgili İçerik";
|
||||
processed = true;
|
||||
}
|
||||
|
||||
if (content.includes("penti") || content.includes("sipariş")) {
|
||||
console.log("🛍️ Penti/Sipariş içerikli mail tespit edildi!");
|
||||
console.log("🛍️ [Signal] Penti/Sipariş içerikli mail tespit edildi!");
|
||||
extraInfo = "🛍️ Penti/Sipariş İlgili İçerik";
|
||||
processed = true;
|
||||
}
|
||||
|
||||
// 4. Bildirim Logu
|
||||
// 4. Bildirim Gönder (Telegram)
|
||||
const notificationResult = await sendTelegramNotification(
|
||||
mapping.userId,
|
||||
to,
|
||||
mailData.from,
|
||||
mailData.subject,
|
||||
extraInfo
|
||||
);
|
||||
|
||||
// 5. Bildirim Logu
|
||||
await prisma.notificationLog.create({
|
||||
data: {
|
||||
mailbox: to,
|
||||
sender: mailData.from,
|
||||
subject: mailData.subject,
|
||||
status: processed ? "SENT" : "SKIPPED",
|
||||
status: notificationResult.status,
|
||||
userId: mapping.userId,
|
||||
error: processed ? null : "Kritik anahtar kelime bulunamadı"
|
||||
error: notificationResult.error || (processed ? null : "Anahtar kelime eşleşmedi")
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
processed,
|
||||
subject: mailData.subject
|
||||
notification: notificationResult.status,
|
||||
subject: mailData.subject
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
|
||||
38
lib/notifications.ts
Normal file
38
lib/notifications.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { prisma } from "./prisma";
|
||||
|
||||
export async function sendTelegramNotification(userId: string, aliciMail: string, sender: string, subject: string, extraInfo: string = "") {
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { id: userId },
|
||||
});
|
||||
|
||||
if (!user || !user.telegramId || !process.env.TELEGRAM_BOT_TOKEN) {
|
||||
console.warn(`[Telegram] Skipped for user ${userId}. Token or ChatId missing.`);
|
||||
return { status: "FAILED", error: "Missing token or chatId" };
|
||||
}
|
||||
|
||||
const message = `🔔 *Yeni Mail Geldi!*\n\n📧 *Alıcı:* ${aliciMail}\n👤 *Gönderen:* ${sender}\n📝 *Konu:* ${subject}${extraInfo ? `\n\n💡 *Analiz:* ${extraInfo}` : ""}`;
|
||||
const telegramUrl = `https://api.telegram.org/bot${process.env.TELEGRAM_BOT_TOKEN}/sendMessage`;
|
||||
|
||||
try {
|
||||
const res = await fetch(telegramUrl, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
chat_id: user.telegramId,
|
||||
text: message,
|
||||
parse_mode: "Markdown",
|
||||
}),
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const errorText = await res.text();
|
||||
console.error(`[Telegram] API Error: ${res.status} ${errorText}`);
|
||||
return { status: "FAILED", error: `API Error: ${res.status}` };
|
||||
}
|
||||
|
||||
return { status: "SENT", error: null };
|
||||
} catch (err: any) {
|
||||
console.error(`[Telegram] Network Error: ${err.message}`);
|
||||
return { status: "FAILED", error: err.message };
|
||||
}
|
||||
}
|
||||
30
scratch/check_logs.ts
Normal file
30
scratch/check_logs.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { prisma } from "../lib/prisma";
|
||||
|
||||
async function checkDb() {
|
||||
try {
|
||||
console.log("--- Notification Logs ---");
|
||||
const nLogs = await prisma.notificationLog.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 5
|
||||
});
|
||||
console.log(JSON.stringify(nLogs, null, 2));
|
||||
|
||||
console.log("\n--- System Logs ---");
|
||||
const sLogs = await prisma.systemLog.findMany({
|
||||
orderBy: { createdAt: 'desc' },
|
||||
take: 5
|
||||
});
|
||||
console.log(JSON.stringify(sLogs, null, 2));
|
||||
|
||||
console.log("\n--- Mailbox Mappings ---");
|
||||
const mappings = await prisma.mailboxMapping.findMany();
|
||||
console.log(JSON.stringify(mappings, null, 2));
|
||||
|
||||
} catch (error) {
|
||||
console.error("DB Check failed:", error);
|
||||
} finally {
|
||||
await prisma.$disconnect();
|
||||
}
|
||||
}
|
||||
|
||||
checkDb();
|
||||
20
scratch/test_db.ts
Normal file
20
scratch/test_db.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { Client } from 'pg';
|
||||
import 'dotenv/config';
|
||||
|
||||
async function testConnection() {
|
||||
const connectionString = process.env.DATABASE_URL;
|
||||
const client = new Client({ connectionString });
|
||||
|
||||
try {
|
||||
console.log("Connecting to:", connectionString?.split('@')[1]);
|
||||
await client.connect();
|
||||
console.log("Connected successfully!");
|
||||
const res = await client.query('SELECT NOW()');
|
||||
console.log("Current time from DB:", res.rows[0]);
|
||||
await client.end();
|
||||
} catch (err) {
|
||||
console.error("Connection error:", err.message);
|
||||
}
|
||||
}
|
||||
|
||||
testConnection();
|
||||
Reference in New Issue
Block a user