Auto-Close System
Complete guide to configuring the auto-close system for automatic ticket management
Auto-Close Overview
The auto-close system automatically closes inactive tickets to keep your support system organized. This guide covers:
- Understanding how auto-close works
- Configuring auto-close settings
- Transcript generation process
- Monitoring and troubleshooting
How Auto-Close Works
1. Inactivity Detection
The system monitors ticket activity and tracks:
- Last message timestamp
- Ticket status (open/closed)
- Auto-close deadline
- Guild-specific settings
2. Auto-Close Process
When auto-closing a ticket:
- Generate HTML transcript of the conversation
- Save transcript to file system
- Update ticket status to 'closed'
- Set closed timestamp and closed by 'system'
- Decrement active ticket count for the guild
3. Transcript Generation
For each closed ticket:
- HTML transcript is generated with all messages
- Transcript includes user information and timestamps
- File is saved to the transcripts directory
- Transcript URL is stored in the ticket record
Configuring Auto-Close
1. Guild Settings
Basic Configuration
- Auto-Close Enabled: Enable/disable the system (default: true)
- Auto-Close Hours: Hours before auto-close (default: 72)
- Cooldown Enabled: Prevent spam (default: true)
- Cooldown Minutes: Minutes between ticket creation (default: 60)
2. Database Configuration
// Guild configuration schema
interface IGuildConfig {
autoCloseEnabled: boolean; // Default: true
autoCloseHours: number; // Default: 72
cooldownEnabled: boolean; // Default: true
cooldownMinutes: number; // Default: 60
devModeEnabled: boolean; // Default: false
devModeRoles: string[]; // Roles that bypass cooldown
logChannelId?: string; // Channel for logs
transcriptChannelId?: string; // Channel for transcripts
blockedUsers: string[]; // Users who cannot create tickets
maxActiveTickets: number; // Default: 5
}
3. Ticket Schema
// Ticket auto-close fields
interface ITicket {
status: 'open' | 'closed' | 'pending_close';
lastActivity: Date; // Updated on each message
autoCloseAt?: Date; // Calculated deadline
closedAt?: Date; // When ticket was closed
closedBy?: string; // Who closed it ('system' for auto-close)
transcriptUrl?: string; // URL to transcript file
transcriptPath?: string; // File system path
}
Auto-Close Service
1. Service Implementation
The AutoCloseService runs periodically to check for expired tickets:
class AutoCloseService {
async processAutoClose() {
// Find tickets that have exceeded their auto-close time
const expiredTickets = await Ticket.find({
status: 'open',
autoCloseAt: { $lte: new Date() }
});
for (const ticket of expiredTickets) {
await this.closeTicket(ticket);
}
}
private async closeTicket(ticket: ITicket) {
// Generate transcript
await this.transcriptService.generateTranscript(ticket);
// Update ticket status
ticket.status = 'closed';
ticket.closedBy = 'system';
ticket.closedAt = new Date();
await ticket.save();
// Update guild statistics
await Guild.findOneAndUpdate(
{ guildId: ticket.guildId },
{ $inc: { activeTickets: -1 } }
);
}
}
2. Cron Job
The auto-close service runs as a cron job:
- Runs every 5 minutes by default
- Checks for tickets that have exceeded auto-close time
- Processes tickets in batches
- Logs activity for monitoring
3. Transcript Service
The TranscriptService generates HTML transcripts:
- Creates formatted HTML with all messages
- Includes user information and timestamps
- Saves to configured transcripts directory
- Updates ticket with transcript URL
Monitoring Auto-Close
1. Logging
- Auto-close logs: Number of tickets auto-closed
- Error logs: Failed auto-close attempts
- Transcript logs: Transcript generation status
- Performance logs: Processing time and efficiency
2. Database Queries
// Check auto-close status
// Find tickets that will be auto-closed soon
const soonToExpire = await Ticket.find({
status: 'open',
autoCloseAt: {
$lte: new Date(Date.now() + 24 * 60 * 60 * 1000), // Next 24 hours
$gt: new Date()
}
});
// Find recently auto-closed tickets
const recentlyClosed = await Ticket.find({
status: 'closed',
closedBy: 'system',
closedAt: { $gte: new Date(Date.now() - 24 * 60 * 60 * 1000) } // Last 24 hours
});
3. Guild Statistics
- Active tickets: Real-time count of open tickets
- Total tickets: Historical count of all tickets
- Auto-close rate: Percentage of tickets auto-closed
- Average ticket lifetime: Time from creation to closure
Troubleshooting
Common Issues
Auto-Close Not Working
- Check if auto-close is enabled in guild config
- Verify auto-close hours setting
- Check if cron job is running
- Review service logs
Transcript Generation Fails
- Check transcripts directory permissions
- Verify file system space
- Check transcript service configuration
- Review error logs
Incorrect Closure Times
- Check guild auto-close hours setting
- Verify timezone configuration
- Check lastActivity field updates
- Review auto-close calculation logic
Database Update Errors
- Check database connection
- Verify ticket and guild schemas
- Check for database locks
- Review transaction logs
Debug Commands
// Check auto-close status
// Find tickets that should be auto-closed
db.tickets.find({
status: "open",
autoCloseAt: { $lte: new Date() }
});
// Check guild configuration
db.guilds.findOne({ guildId: "your-guild-id" });
// Check recent auto-closed tickets
db.tickets.find({
status: "closed",
closedBy: "system",
closedAt: { $gte: new Date(Date.now() - 24*60*60*1000) }
});
Best Practices
1. Timing Configuration
- Start with 72 hours (3 days) for general support
- Use shorter times (24-48 hours) for urgent categories
- Consider your support team's response time
- Account for weekends and holidays
2. Monitoring
- Regularly check auto-close logs
- Monitor transcript generation success rate
- Track auto-close vs manual close ratio
- Review customer feedback on auto-closed tickets
3. Exception Handling
- Set up alerts for auto-close failures
- Monitor transcript generation errors
- Check database performance during auto-close
- Have manual override procedures
4. Performance Optimization
- Process tickets in batches
- Use database indexes for auto-close queries
- Optimize transcript generation
- Monitor system resources during processing
Next Steps
After configuring auto-close:
- Configure Categories - Set up ticket categories
- Set Up Permissions - Configure role-based access
- Configure Dashboard - Set up the web interface
- Manage Staff - Train support staff