Configuration

Complete configuration guide for Ticket System

Configuration Overview

Ticket System requires configuration in several areas:

  • Discord Bot - Bot tokens, permissions, and OAuth settings
  • Payment Providers - Stripe, PayPal, and Patreon integration
  • Domain Settings - Custom domains and SSL configuration
  • Feature Limits - Subscription tier restrictions
  • Security - Encryption keys and authentication

Discord Configuration

Bot Setup

  1. Go to the Discord Developer Portal
  2. Create a new application or use an existing one
  3. Navigate to the "Bot" section
  4. Create a bot and copy the token
  5. Configure the following permissions:
    • Send Messages
    • Manage Threads
    • Use Slash Commands
    • Attach Files
    • Embed Links
    • Read Message History

OAuth Configuration

  1. In your Discord application, go to "OAuth2" → "General"
  2. Add your redirect URI: https://yourdomain.com/api/auth/callback/discord
  3. Copy the Client ID and Client Secret
  4. Configure the scopes: identify guilds
# Example Discord configuration
discord:
  defaultBot:
    token: "your-bot-token-here"
    clientId: "your-client-id"
    enabled: true
  oauth:
    clientId: "your-oauth-client-id"
    clientSecret: "your-oauth-client-secret"
    redirectUri: "https://yourdomain.com/api/auth/callback/discord"

Payment Configuration

Stripe Setup

  1. Create a Stripe account
  2. Get your API keys from the Dashboard
  3. Configure webhook endpoint: https://yourdomain.com/api/webhooks/stripe
  4. Set webhook events: customer.subscription.created, customer.subscription.updated, customer.subscription.deleted
# Stripe configuration
payments:
  stripe:
    publicKey: "pk_test_..."
    secretKey: "sk_test_..."
    webhookSecret: "whsec_..."
    enabled: true

PayPal Setup

  1. Create a PayPal Developer account
  2. Create an app and get Client ID and Secret
  3. Configure webhook URL: https://yourdomain.com/api/webhooks/paypal
  4. Set environment (sandbox/production)
# PayPal configuration
payments:
  paypal:
    clientId: "your-paypal-client-id"
    clientSecret: "your-paypal-client-secret"
    webhookId: "your-webhook-id"
    environment: "sandbox"  # or "production"
    enabled: true

Patreon Setup

  1. Create a Patreon Creator account
  2. Register your application
  3. Get Client ID and Secret
  4. Configure redirect URI: https://yourdomain.com/api/auth/callback/patreon
# Patreon configuration
payments:
  patreon:
    clientId: "your-patreon-client-id"
    clientSecret: "your-patreon-client-secret"
    accessToken: "your-access-token"
    refreshToken: "your-refresh-token"
    enabled: true

Domain Configuration

Primary Domain

Set your primary domain for the application:

domain:
  primary: "https://yourdomain.com"
  allowCustomDomains: true
  sslEnabled: true

Custom Domains

For enterprise customers, you can enable custom domains:

  1. Set allowCustomDomains: true
  2. Configure DNS records for customer domains
  3. Set up SSL certificates for each domain
  4. Configure NGINX virtual hosts

Feature Limits

Subscription Tiers

features:
  maxFreeGuilds: 1
  maxProGuilds: 5
  maxEnterpriseGuilds: -1  # Unlimited
  transcriptRetentionDays: 365

Usage Limits

  • Free Tier: 1 server, 50 tickets/month, 7-day retention
  • Pro Tier: 5 servers, 500 tickets/month, 30-day retention
  • Enterprise Tier: Unlimited servers, unlimited tickets, 365-day retention

Security Configuration

Encryption Keys

Generate secure encryption keys for your installation:

# Generate master key (32 bytes)
openssl rand -base64 32

# Generate JWT keys (Ed25519)
openssl genpkey -algorithm Ed25519 -out private.pem
openssl pkey -in private.pem -pubout -out public.pem

# Convert to base64 for configuration
base64 -w 0 private.pem
base64 -w 0 public.pem

Environment Variables

# Security configuration
NEXTAUTH_SECRET=your-nextauth-secret-here
NEXTAUTH_URL=https://yourdomain.com

# Encryption keys
MASTER_KEY=your-base64-encoded-master-key
JWT_PRIVATE_KEY=your-base64-encoded-private-key
JWT_PUBLIC_KEY=your-base64-encoded-public-key

Database Configuration

MongoDB Setup

# Local MongoDB
MONGODB_URI=mongodb://localhost:27017/ticket-system

# MongoDB Atlas
MONGODB_URI=mongodb+srv://username:[email protected]/ticket-system

# With authentication
MONGODB_URI=mongodb://username:password@localhost:27017/ticket-system?authSource=admin

Redis Setup

# Local Redis
REDIS_URL=redis://localhost:6379

# Redis Cloud
REDIS_URL=redis://username:password@host:port

# With SSL
REDIS_URL=rediss://username:password@host:port

Monitoring Configuration

Health Checks

# Health check endpoints
GET /api/health          # Web application health
GET /health              # Bot health
GET /api/admin/status    # System status

Logging

# Log levels
LOG_LEVEL=info          # error, warn, info, debug
LOG_FORMAT=json         # json, simple
LOG_FILE=logs/app.log   # File logging

Metrics

Configure metrics collection for monitoring:

  • Application Metrics: Response times, error rates
  • Business Metrics: Ticket volume, user activity
  • System Metrics: CPU, memory, disk usage

Testing Your Configuration

1. Verify Bot Connection

# Test bot connectivity
curl -X GET http://localhost:3001/health

# Check bot status in Discord
# The bot should appear online in your server

2. Test OAuth Flow

  1. Visit https://yourdomain.com/api/auth/signin
  2. Click "Sign in with Discord"
  3. Complete the OAuth flow
  4. Verify you're redirected back to the dashboard

3. Test Payment Integration

  1. Create a test subscription
  2. Verify webhook processing
  3. Check database records
  4. Test subscription management

4. Verify Database Connections

# Test MongoDB connection
mongosh --eval "db.runCommand({ping:1})"

# Test Redis connection
redis-cli ping

# Check application logs for connection errors

Troubleshooting

Common Configuration Issues

  • Invalid Bot Token: Check token format and permissions
  • OAuth Redirect Errors: Verify redirect URI matches exactly
  • Payment Webhook Failures: Check webhook URL and signature verification
  • Database Connection Errors: Verify connection strings and network access
  • SSL Certificate Issues: Check certificate validity and NGINX configuration

Configuration Validation

# Validate configuration
npm run validate:config

# Check environment variables
npm run check:env

# Test all integrations
npm run test:integrations

Next Steps

After completing configuration:

  1. First Setup - Create your first ticket category
  2. Bot Setup - Configure Discord bot permissions
  3. Dashboard Setup - Configure the web interface
  4. Analytics Setup - Configure monitoring and reporting