From 3763fc0b15ab3044d21fc86fb45df6bb29814e7d Mon Sep 17 00:00:00 2001 From: Hoid Date: Tue, 17 Feb 2026 22:16:14 +0000 Subject: [PATCH] Fix needs-reply: include unassigned tickets, fix reverse thread order bug --- bin/docfast-support | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/bin/docfast-support b/bin/docfast-support index 708fba0..5c24030 100755 --- a/bin/docfast-support +++ b/bin/docfast-support @@ -161,16 +161,16 @@ async function cmdNeedsReply(args) { const needsReply = []; for (const c of conversations) { - // Only tickets assigned to the AI agent - const assignee = c.assignee?.email || c.user?.email || ''; - if (assignee.toLowerCase() !== AI_AGENT_EMAIL.toLowerCase()) continue; + // Only tickets assigned to the AI agent or unassigned + const assignee = c.assignee?.email || ''; + if (assignee && assignee.toLowerCase() !== AI_AGENT_EMAIL.toLowerCase()) continue; const tRes = await apiRequest('GET', `/conversations/${c.id}?embed=threads`); - if (tRes.status !== 200) continue; + if (tRes.status !== 200) { console.error(` Ticket ${c.id}: API returned ${tRes.status}`); continue; } const threads = (tRes.data._embedded?.threads || []) - .filter(t => t.type !== 'note' && t.type !== 'lineitem') // ignore internal notes and line items - if (threads.length === 0) continue; - const lastThread = threads[threads.length - 1]; // threads are in chronological order + .filter(t => t.type !== 'note' && t.type !== 'lineitem'); + if (threads.length === 0) { continue; } + const lastThread = threads[0]; // FreeScout returns threads in reverse chronological order (newest first) // type 'customer' = from customer, 'message' = from agent if (lastThread.type === 'customer') { needsReply.push(c);