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 = [];
|
const needsReply = [];
|
||||||
for (const c of conversations) {
|
for (const c of conversations) {
|
||||||
// Only tickets assigned to the AI agent
|
// Only tickets assigned to the AI agent or unassigned
|
||||||
const assignee = c.assignee?.email || c.user?.email || '';
|
const assignee = c.assignee?.email || '';
|
||||||
if (assignee.toLowerCase() !== AI_AGENT_EMAIL.toLowerCase()) continue;
|
if (assignee && assignee.toLowerCase() !== AI_AGENT_EMAIL.toLowerCase()) continue;
|
||||||
|
|
||||||
const tRes = await apiRequest('GET', `/conversations/${c.id}?embed=threads`);
|
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 || [])
|
const threads = (tRes.data._embedded?.threads || [])
|
||||||
.filter(t => t.type !== 'note' && t.type !== 'lineitem') // ignore internal notes and line items
|
.filter(t => t.type !== 'note' && t.type !== 'lineitem');
|
||||||
if (threads.length === 0) continue;
|
if (threads.length === 0) { continue; }
|
||||||
const lastThread = threads[threads.length - 1]; // threads are in chronological order
|
const lastThread = threads[0]; // FreeScout returns threads in reverse chronological order (newest first)
|
||||||
// type 'customer' = from customer, 'message' = from agent
|
// type 'customer' = from customer, 'message' = from agent
|
||||||
if (lastThread.type === 'customer') {
|
if (lastThread.type === 'customer') {
|
||||||
needsReply.push(c);
|
needsReply.push(c);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue