Gmail folder auto-advance + /forward command
- Reply-cycle auto-advance: staff reply files the thread to "Awaiting Reply", a customer response files it to "Needs Response" (new GMAIL_LABEL_AWAITING_REPLY / GMAIL_LABEL_NEEDS_RESPONSE labels + autoAdvanceFolder, which only moves threads still in the auto-cycle and leaves hand-filed folders alone) - /forward: forward a ticket's email to another address (handlers/commands/forward.js + forward composition in services/gmail.js) - Tests for the auto-advance cycle; label fixtures updated for the new labels
This commit is contained in:
@@ -21,7 +21,7 @@ const {
|
||||
sanitizeEmbedText
|
||||
} = require('./utils');
|
||||
const { getGmailClient } = require('./services/gmail');
|
||||
const { moveThreadToFolder } = require('./services/gmailLabels');
|
||||
const { moveThreadToFolder, autoAdvanceFolder } = require('./services/gmailLabels');
|
||||
const { getNextTicketNumber, checkTicketLimits, getOrCreateTicketCategory, toDiscordSafeName, getSenderLocal } = require('./services/tickets');
|
||||
const { logError } = require('./services/debugLog');
|
||||
const { enqueueSend } = require('./services/channelQueue');
|
||||
@@ -305,10 +305,22 @@ async function poll(client) {
|
||||
content: `**New Follow-up from ${parsed.senderEmail}:**\n${truncatedFollowup}`,
|
||||
allowedMentions: { parse: [] }
|
||||
});
|
||||
// Follow-up on an existing thread: archive the new message only. Leave
|
||||
// whatever managed folder staff filed this thread under untouched.
|
||||
console.log('Archiving/reading Gmail message', msgRef.id);
|
||||
await markGmailMessageRead(gmail, msgRef);
|
||||
// Customer responded → advance the thread to Needs Response. A
|
||||
// successful move strips INBOX+UNREAD (archives + marks read like
|
||||
// markGmailMessageRead did). If the thread is manually filed (For Jake,
|
||||
// Spam, …) autoAdvanceFolder leaves it put and returns false — or the
|
||||
// move may fail — so in either case fall back to marking just the new
|
||||
// message read, preserving the manual filing and avoiding reprocessing.
|
||||
let advanced = false;
|
||||
try {
|
||||
advanced = await autoAdvanceFolder(parsed.threadId, 'NEEDS_RESPONSE', gmail);
|
||||
} catch (err) {
|
||||
logError('autoAdvanceFolder(NEEDS_RESPONSE)', err, null, client).catch(() => {});
|
||||
}
|
||||
if (!advanced) {
|
||||
console.log('Archiving/reading Gmail message', msgRef.id);
|
||||
await markGmailMessageRead(gmail, msgRef);
|
||||
}
|
||||
} else {
|
||||
// Create a new ticket channel.
|
||||
const limitCheck = await checkTicketLimits(parsed.senderEmail);
|
||||
|
||||
Reference in New Issue
Block a user