# WebSocket API Documentation

## Overview
This WebSocket server provides AI-powered assistance for various categories including business planning, career advice, mock interviews, resume planning, market analysis, financial planning, and career transition advice.

## Connection
Connect to: `ws://localhost:5000/ws`

## Message Format
All messages should be sent as JSON strings.

### Client to Server Messages

#### Chat Message
```json
{
  "type": "chat",
  "content": "I need help with my career development",
  "conversationId": "optional-conversation-id"
}
```

**Note:** The system automatically detects the appropriate category based on your question content. No category field needed!

#### Ping Message
```json
{
  "type": "ping"
}
```

### Server to Client Messages

#### Connection Confirmation
```json
{
  "type": "connection",
  "message": "Connected to RIFI Bot - Your AI Assistant. Just ask me any career or business related question and I'll help you!",
  "clientId": "client_abc123",
  "autoDetect": true,
  "supportedTopics": [
    "Career advice and guidance",
    "Business planning and strategy", 
    "Interview preparation",
    "Resume writing and optimization",
    "Market analysis and research",
    "Financial planning and advice",
    "Career transitions and changes",
    "Current events and news"
  ]
}
```

#### AI Response
```json
{
  "type": "response",
  "category": "career-advice",
  "content": "Here is my advice for your career development...",
  "conversationId": "test-conversation",
  "timestamp": "2025-09-16T11:00:00.000Z"
}
```

**Note:** The `category` field in the response shows which category was automatically detected for your question.

#### Typing Indicator
```json
{
  "type": "typing",
  "conversationId": "test-conversation"
}
```

#### Error Message
```json
{
  "type": "error",
  "message": "Error description",
  "timestamp": "2025-09-16T11:00:00.000Z"
}
```

#### Pong Response
```json
{
  "type": "pong",
  "timestamp": 1694865600000
}
```

## Auto-Detected Categories
The system automatically detects which category your question belongs to:

1. **business-plan** - Business Plan development and strategy
2. **career-advice** - Career development and guidance  
3. **mock-interview** - Interview preparation and practice
4. **resume-planning** - Resume writing and optimization
5. **market-analysis** - Market research and analysis
6. **financial-planning** - Financial planning and advice
7. **career-transition** - Career change and transition guidance
8. **current-events** - Current events and real-time information

**Note:** You don't need to specify these categories - the system detects them automatically based on your question content!

## Testing
Open `websocket-test.html` in your browser to test the WebSocket connection and functionality.

## Security
- API keys are stored in environment variables (`.env` file)
- No hardcoded tokens in the codebase
- WebSocket connections are handled securely through the server
