DB-backed workspace + LangGraph agent
This commit is contained in:
41
Frontend/server/api/telegram/messages.get.ts
Normal file
41
Frontend/server/api/telegram/messages.get.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { getQuery } from "h3";
|
||||
import { prisma } from "../../utils/prisma";
|
||||
import { getAuthContext } from "../../utils/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuthContext(event);
|
||||
const q = getQuery(event);
|
||||
const threadId = typeof q.threadId === "string" ? q.threadId : "";
|
||||
if (!threadId) throw createError({ statusCode: 400, statusMessage: "threadId is required" });
|
||||
|
||||
const thread = await prisma.omniThread.findFirst({
|
||||
where: { id: threadId, teamId: auth.teamId, channel: "TELEGRAM" },
|
||||
});
|
||||
if (!thread) throw createError({ statusCode: 404, statusMessage: "thread not found" });
|
||||
|
||||
const items = await prisma.omniMessage.findMany({
|
||||
where: { teamId: auth.teamId, threadId: thread.id, channel: "TELEGRAM" },
|
||||
orderBy: { occurredAt: "asc" },
|
||||
take: 200,
|
||||
});
|
||||
|
||||
return {
|
||||
thread: {
|
||||
id: thread.id,
|
||||
contactId: thread.contactId,
|
||||
externalChatId: thread.externalChatId,
|
||||
businessConnectionId: thread.businessConnectionId,
|
||||
title: thread.title,
|
||||
updatedAt: thread.updatedAt,
|
||||
},
|
||||
items: items.map((m) => ({
|
||||
id: m.id,
|
||||
direction: m.direction,
|
||||
status: m.status,
|
||||
text: m.text,
|
||||
providerMessageId: m.providerMessageId,
|
||||
occurredAt: m.occurredAt,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user