Fix: use embed=threads API, fix thread ordering
This commit is contained in:
parent
edc030e932
commit
00348babe7
1 changed files with 5 additions and 6 deletions
|
|
@ -96,8 +96,8 @@ async function cmdView(args) {
|
|||
console.log(`Status: ${c.status} | Customer: ${c.customer?.email || 'unknown'} | Created: ${c.createdAt}`);
|
||||
console.log('---');
|
||||
|
||||
// Get threads (messages)
|
||||
const tRes = await apiRequest('GET', `/conversations/${id}/threads`);
|
||||
// Get threads (messages) — must use embed=threads on conversation endpoint
|
||||
const tRes = await apiRequest('GET', `/conversations/${id}?embed=threads`);
|
||||
if (tRes.status === 200) {
|
||||
const threads = tRes.data._embedded?.threads || [];
|
||||
for (const t of threads) {
|
||||
|
|
@ -165,13 +165,12 @@ async function cmdNeedsReply(args) {
|
|||
const assignee = c.assignee?.email || c.user?.email || '';
|
||||
if (assignee.toLowerCase() !== AI_AGENT_EMAIL.toLowerCase()) continue;
|
||||
|
||||
const tRes = await apiRequest('GET', `/conversations/${c.id}/threads`);
|
||||
const tRes = await apiRequest('GET', `/conversations/${c.id}?embed=threads`);
|
||||
if (tRes.status !== 200) continue;
|
||||
const threads = (tRes.data._embedded?.threads || [])
|
||||
.filter(t => t.type !== 'note') // ignore internal notes
|
||||
.sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt));
|
||||
.filter(t => t.type !== 'note' && t.type !== 'lineitem') // ignore internal notes and line items
|
||||
if (threads.length === 0) continue;
|
||||
const lastThread = threads[0];
|
||||
const lastThread = threads[threads.length - 1]; // threads are in chronological order
|
||||
// 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