Fix needs-reply: include unassigned tickets, fix reverse thread order bug
This commit is contained in:
parent
ea1d71560f
commit
3763fc0b15
1 changed files with 7 additions and 7 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue