diff --git a/src/lib/tickets/service.ts b/src/lib/tickets/service.ts index 2e60e5c..778a29c 100644 --- a/src/lib/tickets/service.ts +++ b/src/lib/tickets/service.ts @@ -310,10 +310,12 @@ export async function recordChatInboundMessage(params: { } /** - * Records an inbound email. Prefers exact thread matching via - * In-Reply-To/References (so a reply to a specific closed ticket lands on - * that ticket, not a random other open one); falls back to the same - * find-or-create-open-ticket heuristic used for Telegram. + * Records an inbound email. Threads it onto an existing ticket only via + * exact In-Reply-To/References matching. Unlike Telegram/the website widget + * (a continuous chat stream with no subject), email always carries a + * distinct subject per conversation — so a message with no header match is + * always a new, unrelated request and must become its own ticket, even if + * the customer already has another ticket open. */ export async function recordEmailInboundMessage(params: { fromEmail: string; @@ -330,7 +332,7 @@ export async function recordEmailInboundMessage(params: { const matchedTicketId = await findTicketIdByEmailReferences(params.referencedMessageIds); let ticket = matchedTicketId ? await db.query.tickets.findFirst({ where: eq(tickets.id, matchedTicketId) }) - : await findOpenTicketForCustomer(customer.id); + : null; let ticketIsNew = false; if (!ticket) {