The system now supports two different API endpoints for sending emails, automatically choosing the correct one based on recipient type.
Endpoint: POST /api/admin/{user.id}/message
Used for: Recipients who have user accounts in the system (have a user ID)
Request Body:
{
"message": "Email content here",
"subject": "Email Subject",
"recipient_type": "mentor|judge|volunteer|hacker|sponsor",
"recipient_id": "user_id_here"
}Endpoint: POST /api/admin/email/send
Used for: Recipients who only have email addresses (no user account)
Request Body:
{
"email": "user@example.com",
"message": "Email content here",
"subject": "Email Subject",
"recipient_type": "mentor|judge|volunteer|hacker|sponsor",
"name": "John Doe"
}The system automatically detects which endpoint to use based on these criteria:
const isEmailOnlyRecipient = !user.id || user.source === 'custom' || user.source === 'csv';Email-only endpoint used when:
- User has no ID (
!user.id) - User source is 'custom' (manually added email)
- User source is 'csv' (imported from CSV file)
User ID endpoint used when:
- User has a valid ID from the database
- User was fetched from Slack/volunteer system
- Enhanced:
sendEmailToUser()method now detects recipient type - Added: Endpoint tracking for debugging (
result.endpoint) - Improved: Error messages include endpoint context
- Enhanced:
handleSendMessage()method now uses dual-endpoint logic - Maintained: All existing functionality and UI behavior
- Flexibility: Can now send emails to both registered users and email-only recipients
- Automatic: No manual configuration needed - system detects automatically
- Debugging: Endpoint information included in results for troubleshooting
- Backward Compatible: Existing registered user email functionality unchanged
When using /admin/social-media:
- Slack Users: Will use user ID endpoint (registered users)
- Custom Email Addresses: Will use email-only endpoint (entered manually)
- CSV Imported Emails: Will use email-only endpoint (imported from file)
- Mixed Recipients: System handles both types automatically in same batch
Enhanced error messages now include endpoint context:
"Error message (via user-ID endpoint)""Error message (via email-only endpoint)"
This helps with debugging API issues and understanding which type of recipient failed.