Email ticketing fixes, comms polish, and .env cleanup

Inbound:
- Gmail poll query is:unread in:inbox (was category:primary, which matched
  nothing on a no-tabs Workspace inbox)

Outbound email:
- Closed/escalation auto-emails editable via TICKET_CLOSE_MESSAGE and new
  TICKET_ESCALATION_EMAIL_MESSAGE; drop the staff signature from closing emails
- Replies quote the customer's latest message (gmail_quote markup so clients
  collapse it), embed custom emoji inline via CID attachment, and strip Discord
  role mentions
- Tagline spacing fix in the company signature

Discord side:
- Suppress all mentions in log + transcript posts (no more pinging on close)
- Drop the staff-role ping from new-ticket and follow-up notifications
- Ticket channels inherit category permissions instead of setting per-channel
  overwrites (removes the Manage Roles requirement)

Gmail folders:
- Folder/label routing (gmailLabels.js) with /folder; close files to Complete

Config:
- Remove ~56 stale .env keys for long-removed features; refresh stale copy

Docs:
- Design specs for folder routing, email-flow toggle, and per-staff metrics
This commit is contained in:
2026-06-04 22:05:20 +00:00
parent 3e20f9cf86
commit 2ccdbf72aa
19 changed files with 1224 additions and 83 deletions

View File

@@ -3,7 +3,7 @@
*/
const { mongoose } = require('../db-connection');
const { CONFIG } = require('../config');
const { extractRawEmail, isStaff } = require('../utils');
const { extractRawEmail, isStaff, getCleanBody } = require('../utils');
const { getGmailClient, sendGmailReply } = require('../services/gmail');
const { getNotifyDm } = require('../services/staffSettings');
const { logError } = require('../services/debugLog');
@@ -77,6 +77,10 @@ async function handleDiscordReply(m) {
'Support';
const msgId =
last.payload.headers.find(h => h.name === 'Message-ID')?.value;
const origDate =
last.payload.headers.find(h => h.name === 'Date')?.value || '';
const origFrom =
last.payload.headers.find(h => h.name === 'From')?.value || recipient;
const recipientEmail = extractRawEmail(recipient).toLowerCase();
if (!recipientEmail || recipientEmail === CONFIG.MY_EMAIL) {
@@ -84,13 +88,17 @@ async function handleDiscordReply(m) {
return;
}
// Quote the customer's latest inbound message beneath the staff reply.
const quote = { from: origFrom, date: origDate, body: getCleanBody(last.payload) };
await sendGmailReply(
ticket.gmailThreadId,
m.content,
recipientEmail,
subject,
msgId,
m.author.id
m.author.id,
quote
);
} catch (e) {
console.error('REPLY ERROR:', e);