DB-backed workspace + LangGraph agent
This commit is contained in:
37
Frontend/server/api/telegram/threads.get.ts
Normal file
37
Frontend/server/api/telegram/threads.get.ts
Normal file
@@ -0,0 +1,37 @@
|
||||
import { prisma } from "../../utils/prisma";
|
||||
import { getAuthContext } from "../../utils/auth";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuthContext(event);
|
||||
|
||||
const threads = await prisma.omniThread.findMany({
|
||||
where: { teamId: auth.teamId, channel: "TELEGRAM" },
|
||||
orderBy: { updatedAt: "desc" },
|
||||
take: 50,
|
||||
include: {
|
||||
contact: true,
|
||||
messages: { orderBy: { occurredAt: "desc" }, take: 1 },
|
||||
},
|
||||
});
|
||||
|
||||
return {
|
||||
items: threads.map((t) => ({
|
||||
id: t.id,
|
||||
contact: { id: t.contact.id, name: t.contact.name },
|
||||
externalChatId: t.externalChatId,
|
||||
businessConnectionId: t.businessConnectionId,
|
||||
title: t.title,
|
||||
updatedAt: t.updatedAt,
|
||||
lastMessage: t.messages[0]
|
||||
? {
|
||||
id: t.messages[0].id,
|
||||
direction: t.messages[0].direction,
|
||||
status: t.messages[0].status,
|
||||
text: t.messages[0].text,
|
||||
occurredAt: t.messages[0].occurredAt,
|
||||
}
|
||||
: null,
|
||||
})),
|
||||
};
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user