feat: P6 Inbox UI — InboxTab + API routes

ChannelView: вкладка 'Inbox' рядом с 'Аналитика'
InboxTab.js:
  - Webhook setup кнопка (если не настроен)
  - Табы: Новые / Все / Отвечено / Игнорировано
  - Карточки сообщений с иконкой типа (question/praise/complaint/spam)
  - AI-предложенный ответ с кнопкой 'Использовать →'
  - Форма ответа прямо в карточке
  - Кнопки: Ответить / Игнорировать / Спам
API routes: /api/inbox/[channelId], /reply, /status, /setup-webhook
This commit is contained in:
Ник (Claude)
2026-06-11 20:13:08 +03:00
parent d0fd328011
commit d262c2af7d
6 changed files with 344 additions and 1 deletions
+27
View File
@@ -0,0 +1,27 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
async function engineReq(path, opts = {}) {
const { method = 'GET', body, userId } = opts;
const headers = { 'x-internal-secret': ENGINE_SECRET };
if (userId) headers['x-user-id'] = String(userId);
if (body) headers['Content-Type'] = 'application/json';
const res = await fetch(`${ENGINE_URL}${path}`, {
method, headers, body: body ? JSON.stringify(body) : undefined,
});
return res.json();
}
export async function GET(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const { searchParams } = new URL(req.url);
const data = await engineReq(
`/api/inbox/${params.channelId}?${searchParams.toString()}`,
{ userId: user.id }
);
return NextResponse.json(data);
}
@@ -0,0 +1,15 @@
import { NextResponse } from 'next/server';
import { requireUser } from '@/lib/session';
const ENGINE_URL = process.env.ENGINE_URL || 'http://localhost:3030';
const ENGINE_SECRET = process.env.ENGINE_SECRET || '';
export async function POST(req, { params }) {
const user = await requireUser();
if (!user) return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
const res = await fetch(`${ENGINE_URL}/api/inbox/${params.channelId}/setup-webhook`, {
method: 'POST',
headers: { 'x-internal-secret': ENGINE_SECRET, 'x-user-id': String(user.id) },
});
return NextResponse.json(await res.json());
}