33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { readBody } from "h3";
|
|
import { getAuthContext } from "../../../utils/auth";
|
|
import { prisma } from "../../../utils/prisma";
|
|
import { enqueueTelegramSend } from "../../../queues/telegramSend";
|
|
|
|
export default defineEventHandler(async (event) => {
|
|
const auth = await getAuthContext(event);
|
|
const body = await readBody<{ omniMessageId?: string; attempts?: number }>(event);
|
|
|
|
const omniMessageId = String(body?.omniMessageId ?? "").trim();
|
|
if (!omniMessageId) {
|
|
throw createError({ statusCode: 400, statusMessage: "omniMessageId is required" });
|
|
}
|
|
|
|
const msg = await prisma.omniMessage.findFirst({
|
|
where: { id: omniMessageId, teamId: auth.teamId, channel: "TELEGRAM", direction: "OUT" },
|
|
select: { id: true },
|
|
});
|
|
if (!msg) {
|
|
throw createError({ statusCode: 404, statusMessage: "telegram outbound message not found" });
|
|
}
|
|
|
|
const attempts = Math.max(1, Math.min(Number(body?.attempts ?? 12), 50));
|
|
const job = await enqueueTelegramSend({ omniMessageId }, { attempts });
|
|
|
|
return {
|
|
ok: true,
|
|
queue: process.env.SENDER_FLOW_QUEUE_NAME || process.env.OUTBOUND_DELIVERY_QUEUE_NAME || "sender.flow",
|
|
jobId: job.id,
|
|
omniMessageId,
|
|
};
|
|
});
|