DB-backed workspace + LangGraph agent
This commit is contained in:
36
Frontend/server/api/telegram/send.post.ts
Normal file
36
Frontend/server/api/telegram/send.post.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import { readBody } from "h3";
|
||||
import { prisma } from "../../utils/prisma";
|
||||
import { getAuthContext } from "../../utils/auth";
|
||||
import { enqueueTelegramSend } from "../../queues/telegramSend";
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
const auth = await getAuthContext(event);
|
||||
const body = await readBody<{ threadId?: string; text?: string }>(event);
|
||||
|
||||
const threadId = (body?.threadId || "").trim();
|
||||
const text = (body?.text || "").trim();
|
||||
if (!threadId) throw createError({ statusCode: 400, statusMessage: "threadId is required" });
|
||||
if (!text) throw createError({ statusCode: 400, statusMessage: "text 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 msg = await prisma.omniMessage.create({
|
||||
data: {
|
||||
teamId: auth.teamId,
|
||||
contactId: thread.contactId,
|
||||
threadId: thread.id,
|
||||
direction: "OUT",
|
||||
channel: "TELEGRAM",
|
||||
status: "PENDING",
|
||||
text,
|
||||
occurredAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
await enqueueTelegramSend({ omniMessageId: msg.id });
|
||||
return { ok: true, messageId: msg.id };
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user