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

@@ -10,6 +10,7 @@ const { mongoose } = require('../../db-connection');
const { CONFIG } = require('../../config');
const { makeTicketName, resolveCreatorNickname } = require('../../services/tickets');
const { sendTicketNotificationEmail } = require('../../services/gmail');
const { moveThreadToFolder } = require('../../services/gmailLabels');
const { getTicketActionRow } = require('../../utils/ticketComponents');
const { enqueueRename, enqueueMove, enqueueSend } = require('../../services/channelQueue');
const { pinMessage } = require('../../services/pinMessage');
@@ -98,11 +99,20 @@ async function runEscalation(interaction, ticket, nextTier) {
try {
const escalatorName = interaction.member?.displayName || interaction.user.username;
const tierLabel = nextTier === 1 ? 'tier 2' : 'tier 3';
const emailBody = `${escalatorName} escalated this ticket to ${tierLabel}.`;
// Editable via TICKET_ESCALATION_EMAIL_MESSAGE in .env. Placeholders:
// {escalator_name}, {tier}; \n for line breaks.
const emailBody = (CONFIG.TICKET_ESCALATION_EMAIL_MESSAGE || '')
.replace(/\\n/g, '\n')
.replace(/\{escalator_name\}/g, escalatorName)
.replace(/\{tier\}/g, tierLabel);
await sendTicketNotificationEmail(ticket, emailBody, interaction.user.id);
} catch (emailErr) {
console.error('Escalation email failed (non-fatal):', emailErr.message);
}
// File the email thread into the Escalated folder — non-fatal, never blocks
// the escalation.
moveThreadToFolder(ticket.gmailThreadId, 'ESCALATED')
.catch(err => logError('gmailLabels: escalate move', err).catch(() => {}));
}
if (nextTier === 2 && ticket.welcomeMessageId) {
@@ -118,9 +128,10 @@ async function runEscalation(interaction, ticket, nextTier) {
if (logChan) {
const ticketType = isDiscordTicket ? 'Discord' : 'Email';
const tierLabel = nextTier === 1 ? 'tier 2' : 'tier 3';
await enqueueSend(logChan,
`${ticketType} ticket ${interaction.channel} escalated to ${tierLabel} by ${interaction.user.tag}.`
);
await enqueueSend(logChan, {
content: `${ticketType} ticket ${interaction.channel} escalated to ${tierLabel} by ${interaction.user.tag}.`,
allowedMentions: { parse: [] }
});
}
}
@@ -168,9 +179,10 @@ async function runDeescalation(interaction, ticket) {
const logChan = await fetchLoggingChannel(interaction.client);
if (logChan) {
const ticketType = isDiscordTicket ? 'Discord' : 'Email';
await enqueueSend(logChan,
`${ticketType} ticket ${interaction.channel} deescalated to ${tierLabel} by ${interaction.user.tag}.`
);
await enqueueSend(logChan, {
content: `${ticketType} ticket ${interaction.channel} deescalated to ${tierLabel} by ${interaction.user.tag}.`,
allowedMentions: { parse: [] }
});
}
}