This feature enables automatic enrollment of new users into the conversation flow when they send their first message to the system. When enabled, users who are not yet enrolled will be automatically registered with an empty profile, and their first message will be handled by the conversation flow (intake/feedback modules).
AUTO_ENROLL_NEW_USERS=true- Default:
false(disabled by default) - Type: Boolean
- Description: When set to
true, any user who sends a message without being enrolled will be automatically enrolled in the conversation flow.
./build/promptpipe --auto-enroll-new-users=true- Flag:
--auto-enroll-new-users - Default:
false - Description: Overrides the environment variable setting.
User sends message
↓
Response Handler receives message
↓
Auto-enrollment enabled? → No → Process normally
↓ Yes
↓
User already enrolled? → Yes → Process normally
↓ No
↓
Create empty participant profile
↓
Set conversation state to ACTIVE
↓
Register conversation hook
↓
Process message with conversation flow
-
Message Reception: When a user sends a message, the
ResponseHandler.ProcessResponsemethod is called.- Auto-enrollment is only triggered via the messaging service response handler (not via the
POST /responseAPI).
- Auto-enrollment is only triggered via the messaging service response handler (not via the
-
Auto-Enrollment Check: Before processing the message, if
autoEnrollNewUsersis enabled, the system checks if the user is already enrolled. -
Profile Creation: If the user is not enrolled, the system creates a new
ConversationParticipantwith:- Auto-generated participant ID (format:
p_<random_hex>) - Phone number (canonicalized)
- Empty profile fields (Name, Gender, Ethnicity, Background)
- Status:
ACTIVE - Current timestamp for EnrolledAt, CreatedAt, UpdatedAt
- Auto-generated participant ID (format:
-
State Initialization: The conversation flow state is initialized to
CONVERSATION_ACTIVE. -
Hook Registration: A persistent conversation hook is registered for the participant, enabling the conversation flow to handle all subsequent messages.
-
First Message: The user's first message is processed by the conversation flow. The flow determines the reply based on the intake/feedback state; no extra welcome message is sent outside that flow.
-
cmd/PromptPipe/main.go- Added
AutoEnrollNewUsersfield toConfigstruct - Added
autoEnrollNewUsersfield toFlagsstruct - Added environment variable parsing in
loadEnvironmentConfig - Added command line flag parsing in
parseCommandLineFlags - Added option passing in
buildAPIOptions
- Added
-
internal/api/api.go- Added
AutoEnrollNewUsersfield toOptsstruct - Added
autoEnrollNewUsersfield toServerstruct - Created
WithAutoEnrollNewUsersoption function - Updated
createAndConfigureServerto pass flag to ResponseHandler
- Added
-
internal/messaging/response_handler.go- Added
autoEnrollNewUsersfield toResponseHandlerstruct - Updated
NewResponseHandlersignature to acceptautoEnrollNewUsersparameter - Implemented
autoEnrollIfNeededmethod for auto-enrollment logic - Updated
ProcessResponseto call auto-enrollment before processing messages
- Added
-
Test Files
- Updated all test files to pass
falseforautoEnrollNewUsersparameter to maintain existing test behavior
- Updated all test files to pass
Using Environment Variable:
export AUTO_ENROLL_NEW_USERS=true
./build/promptpipeUsing Command Line Flag:
./build/promptpipe --auto-enroll-new-users=trueUsing .env File:
AUTO_ENROLL_NEW_USERS=true# Don't set the environment variable or explicitly set to false
export AUTO_ENROLL_NEW_USERS=false
./build/promptpipe- User sends first message: "Hello"
- System automatically:
- Creates participant profile with empty fields
- Enrolls user in conversation flow
- Initializes conversation state
- Conversation Flow responds based on intake/feedback logic
- User receives the flow response and conversation begins
- User sends first message: "Hello"
- System responds with default message: "📝 Your message has been recorded. Thank you for your response!"
- User must be manually enrolled via API to join conversation flow
- Auto-enrollment is disabled by default to prevent unauthorized access
- Phone numbers are validated and canonicalized before enrollment
- All enrollment operations are logged for audit purposes
- Empty profiles are created to minimize data collection until user provides information
The system logs the following events related to auto-enrollment:
ResponseHandler auto-enrolled new participant- Successful auto-enrollmentResponseHandler autoEnrollIfNeeded: participant already enrolled- Skip for existing usersResponseHandler autoEnrollIfNeeded: failed to check existing participant- Error checking enrollmentResponseHandler autoEnrollIfNeeded: save failed- Error saving participantResponseHandler auto-enrollment complete, conversation flow will handle first message- Ready to process
This feature is fully backward compatible:
- Default behavior is unchanged (auto-enrollment disabled)
- Existing tests continue to pass with
autoEnrollNewUsers=false - Manual enrollment via API continues to work as before
- No database schema changes required
Potential improvements for this feature:
- Configurable Welcome Message: Allow customization of auto-enrollment welcome message
- Rate Limiting: Prevent abuse by limiting auto-enrollments per time period
- Whitelist/Blacklist: Support phone number filtering for auto-enrollment
- Pre-populated Profiles: Option to pre-fill profile data from external sources
- Analytics: Track auto-enrollment rates and user engagement metrics