Automatically corrects conversations where support agents incorrectly appear as customers. This typically happens when agents send emails to customers, and the system misidentifies the agent as the customer.
- ✅ Automatically detects and corrects misidentified agent/customer roles
- ✅ Web-based Admin Interface - Configure via FreeScout admin panel (no file editing needed)
- ✅ Manual Execution - "Fix Now" button with real-time preview and results
- ✅ Scheduled task automation (daily, weekly, or monthly)
- ✅ Optional real-time correction on conversation creation
- ✅ Dry-run mode for testing before applying changes
- ✅ Comprehensive logging and debugging
- ✅ Configurable agent email addresses and mailboxes via web UI
- ✅ Skips agent-to-agent internal communications
Copy the entire CustomerCorrection folder to your FreeScout Docker container:
# Via docker cp
docker cp Modules/CustomerCorrection/ <container_name>:/www/html/Modules/
# Or via Portainer file manager
# Upload the CustomerCorrection folder to /www/html/Modules/Option A: Web Interface (Recommended)
- Log in to FreeScout as an administrator
- Navigate to:
/customer-correction/settingsin your browser- Example:
https://your-freescout.com/customer-correction/settings
- Example:
- Configure settings via the web interface:
- Add agent email addresses (one per line)
- Select mailboxes to monitor
- Set schedule frequency and automation options
- Click "Save Settings"
Option B: Configuration File (Alternative)
Access your Docker container via Portainer console and edit the configuration:
cd /www/html/Modules/CustomerCorrection/Config
nano config.phpUpdate the following settings:
'agent_emails' => [
'support@yourcompany.com', // Replace with your agent emails
'help@yourcompany.com',
'sales@yourcompany.com',
],
'mailbox_ids' => [2, 3], // Replace with your mailbox IDs (or [] for all)
'schedule_frequency' => 'weekly', // Options: daily, weekly, monthly
'process_days' => 30, // Process conversations from last 30 daysNote: Settings configured via the web interface take priority over the config file.
In the Docker container at /www/html/:
cd /www/html
# Enable the module
php artisan module:enable CustomerCorrection
# Clear caches
php artisan clear-compiled
php artisan config:clear
php artisan route:clear# Check if module is enabled
php artisan module:list
# Verify command is available
php artisan list | grep fix-agent-customer-swap
# Check scheduled tasks
php artisan schedule:list
# Test with dry-run
php artisan freescout:fix-agent-customer-swap --mailbox-id=2 --agent-emails="support@company.com" --dry-run=1 --debug=1Edit Config/config.php to customize module behavior:
List of agent email addresses to detect and correct:
'agent_emails' => [
'support@yourcompany.com',
'help@yourcompany.com',
],Mailbox IDs to monitor. Leave empty [] to process all mailboxes:
'mailbox_ids' => [2, 3], // Specific mailboxes
// OR
'mailbox_ids' => [], // All mailboxesHow often to run automatic corrections:
'daily'- Runs every day at 2:00 AM'weekly'- Runs every Sunday at 2:00 AM'monthly'- Runs on the 1st of each month at 2:00 AM
'schedule_frequency' => 'weekly',Enable real-time correction when conversations are created:
'auto_fix_on_create' => false, // Recommended: falseEnable detailed logging:
'debug_enabled' => false, // Set to true for troubleshootingProcess conversations created within last X days:
'process_days' => 30, // Last 30 days
// OR
'process_days' => null, // All conversationsAccess the admin interface at: /customer-correction/settings
Step-by-Step Usage:
-
Access Settings Page
- Log in to FreeScout as administrator
- Navigate to:
https://your-freescout.com/customer-correction/settings - You'll see the Customer Correction settings page
-
Configure Agent Emails
- In the "Agent Email Addresses" field, enter agent emails (one per line)
- Example:
support@yourcompany.com help@yourcompany.com sales@yourcompany.com - These are the emails that will be detected and corrected when they appear as customers
-
Select Mailboxes to Monitor
- Choose which mailboxes to process from the dropdown
- Hold Ctrl/Cmd to select multiple mailboxes
- Leave all unselected to process all mailboxes
-
Configure Automation
- Schedule Frequency: Choose how often to run automatically
- Daily (every day at 2:00 AM)
- Weekly (every Sunday at 2:00 AM)
- Monthly (1st of each month at 2:00 AM)
- Process Last X Days: Set how many days back to check (e.g., 30)
- Real-time Correction: Enable to auto-fix on conversation creation (
⚠️ test first)
- Schedule Frequency: Choose how often to run automatically
-
Advanced Options
- Debug Mode: Enable for detailed troubleshooting logs
- Logs saved to:
storage/logs/customer-correction.log
-
Save Settings
- Click "Save Settings" button
- Settings are stored in database (higher priority than config file)
-
Manual Execution
- Scroll down to "Manual Execution" section
- Select mailbox and date range
- Click "Preview (Dry Run)" to see what would change
- Click "Fix Now" to apply corrections
- View real-time output in the browser
Web Interface Features:
- ✅ Settings Management - Configure all options via web form
- ✅ Manual Execution - Run corrections on-demand with instant feedback
- ✅ Preview Mode - Dry-run to see changes before applying
- ✅ Real-time Results - Command output shown directly in browser
- ✅ Flexible Filtering - Choose specific mailboxes and date ranges
- ✅ No File Editing - All configuration via database
The module automatically runs based on your schedule_frequency configuration. Ensure FreeScout's Laravel scheduler is running:
# Check if scheduler is active
php artisan schedule:list
# Manually trigger scheduler (for testing)
php artisan schedule:runRun the command manually as needed:
# Dry run (preview changes)
php artisan freescout:fix-agent-customer-swap \
--mailbox-id=2 \
--agent-emails="support@company.com,help@company.com" \
--dry-run=1 \
--debug=1
# Execute corrections
php artisan freescout:fix-agent-customer-swap \
--mailbox-id=2 \
--agent-emails="support@company.com" \
--force=1
# Process recent conversations only
php artisan freescout:fix-agent-customer-swap \
--mailbox-id=2 \
--agent-emails="support@company.com" \
--days=7 \
--force=1
# Fix specific conversation
php artisan freescout:fix-agent-customer-swap \
--conversation-id=500 \
--agent-emails="support@company.com" \
--force=1--mailbox-id=- ID of the mailbox to process--conversation-id=- Fix specific conversation ID--days=- Process conversations created within last X days--agent-emails=(required) - Comma-separated list of agent emails--debug=0- Enable debug mode (default: 0)--dry-run=0- Preview changes without applying (default: 0)--force=0- Required flag to actually update conversations (default: 0)
- Scans Conversations: Identifies conversations where the "customer" email matches a configured agent email
- Examines First Thread: Looks at the original email's "To" field to find the actual customer
- Swaps Roles:
- Updates conversation
customer_emailto the real customer - Changes
source_viafromCUSTOMERtoUSER(agent-initiated) - Updates thread type from
TYPE_CUSTOMERtoTYPE_MESSAGE
- Updates conversation
- Skips Internal Communications: Agent-to-agent conversations are left unchanged
- Reports Statistics: Provides detailed counts of swapped, skipped, and already-correct conversations
# Enable
php artisan module:enable CustomerCorrection
# Disable
php artisan module:disable CustomerCorrection
# Check status
php artisan module:listAfter editing Config/config.php:
php artisan config:clear
php artisan clear-compiledScheduled task output is logged to:
/www/html/storage/logs/customer-correction.log
View logs:
tail -f /www/html/storage/logs/customer-correction.log# Verify module location
ls -la /www/html/Modules/CustomerCorrection/
# Check module.json
cat /www/html/Modules/CustomerCorrection/module.json
# Enable module
php artisan module:enable CustomerCorrection
# Clear caches
php artisan clear-compiled
php artisan config:clear# Verify command file exists
ls -la /www/html/Modules/CustomerCorrection/Console/
# List available commands
php artisan list | grep customer
# Check service provider
cat /www/html/Modules/CustomerCorrection/Providers/CustomerCorrectionServiceProvider.php# Check Laravel scheduler
php artisan schedule:list
# Verify FreeScout cron is active
ps aux | grep schedule:run
# Manually test command
php artisan freescout:fix-agent-customer-swap --dry-run=1 --debug=1- Verify agent emails are configured correctly in
Config/config.php - Check that conversations exist with agents as customers
- Run with
--debug=1to see detailed processing - Ensure
--force=1flag is used (not--dry-run=1)
- Dry-Run Mode: Preview all changes before applying
- Force Flag Required: Prevents accidental data modification
- Preserves Timestamps: Original conversation dates are maintained
- Skips Internal Communications: Agent-to-agent emails are left unchanged
- Detailed Logging: Debug mode provides comprehensive operation logs
- Error Handling: Failed corrections are logged and skipped
Processing conversations for mailbox: Support (support@company.com)
Filtering to conversations created within last 30 days
Found 150 conversations to check
✅ Processing completed!
📊 Statistics:
- Total conversations checked: 150
- Matching agent emails: 25
• Customer/Agent swapped: 20
• Already correct: 3
• Skipped (errors): 2
- Non-agent conversations (skipped): 125
- FreeScout >= 1.8.0
- Laravel Scheduler must be running
- PHP 7.4+
- Write access to storage/logs directory
For issues or questions:
- Check module logs:
storage/logs/customer-correction.log - Run with
--debug=1flag for detailed output - Review FreeScout documentation: https://github.com/freescout-help-desk/freescout/wiki
This module is provided as-is for FreeScout installations. Use at your own risk.
Version: 1.0.0
- Move to Settings Sidebar: Integrate with FreeScout's main settings menu
- Appear alongside "General", "Mail Settings", "Alerts", "User Fields"
- Route change:
/customer-correction/settings→/settings/customer-correction - Use
settings.sectionsEventy filter for menu registration - Adopt FreeScout's settings layout pattern
- Benefits: Better UX, consistent navigation, easier discovery
- Bulk Operations: Process multiple mailboxes with progress tracking
- Notifications: Email alerts for scheduled task results
- Statistics Dashboard: Visual charts of corrections over time
- Undo Functionality: Revert corrections if needed
- Advanced Filtering: Filter by date range, customer domain, conversation tags
- Queue Integration: Process large batches via Laravel queue system
- Incremental Processing: Resume interrupted operations
- Caching: Cache agent email lookups for faster processing
- Background Jobs: Non-blocking manual execution for large datasets
Suggestions and contributions welcome! To propose features:
- Open an issue describing the enhancement
- Include use cases and expected behavior
- Reference version number for roadmap placement
- ✅ Initial release
- ✅ Web-based admin interface
- ✅ Manual execution with dry-run mode
- ✅ Scheduled task automation (daily/weekly/monthly)
- ✅ Database-driven configuration
- ✅ Real-time AJAX execution with output display
- ✅ Comprehensive logging and debugging
- ✅ Command-line interface with multiple options