besper-frontend-site-dev-main
Version:
Professional B-esper Frontend Site - Site-wide integration toolkit for full website bot deployment
180 lines (131 loc) • 6.28 kB
Markdown
# My Bots Page - Developer Guide
## Overview
Centralized bot management functionality with comprehensive APIM integration, internationalization, and advanced bot lifecycle management.
## Architecture
### Core Components
- **MyBotsPage**: Main page class with bulletproof loading pattern
- **BotManagementSystem**: Comprehensive bot management with APIM integration
- **Authentication Integration**: Smart token coordination with multiple authentication strategies
- **Internationalization**: Complete German/English support with dynamic switching
## Business Context References
### Bot Management Business Logic
For detailed business requirements and context:
- **Source**: `infra/besper_site_serversite/storage/my-bots/BUSINESS_CONTEXT.md`
- **Developer Guide**: `infra/besper_site_serversite/storage/my-bots/DEVELOPER_GUIDE.md`
- **Migration Guide**: `infra/besper_site_serversite/storage/my-bots/MIGRATION_GUIDE.md`
## Key Features
### Comprehensive Bot Management
- **Bot Lifecycle Operations**: Create, read, update, delete operations via APIM
- **Performance Monitoring**: Real-time performance metrics, success rates, and analytics
- **Status Management**: Comprehensive status tracking with visual indicators
- **Type Management**: Support for multiple bot types (chatbot, workflow, data processor, API bot)
### Advanced UI Features
- **Interactive Dashboard**: KPI cards with real-time statistics and performance metrics
- **Advanced Filtering**: Multi-field search and filtering across bot properties
- **Visual Performance Indicators**: Performance bars, status badges, and visual feedback
- **Action Management**: Comprehensive action buttons for bot operations
### APIM Integration
- **Dynamic API Detection**: Environment-aware API endpoint detection
- **Authentication Flow**: Multi-layer authentication with comprehensive fallback
- **Data Processing**: Robust data processing from Dataverse and APIM APIs
- **Error Recovery**: Graceful fallback to demo data with user-friendly error handling
## API Integration
### Bot Management Endpoints
- `GET /api/admin/bots/list` - Comprehensive bot listing with full metadata
- `POST /api/admin/bots/create` - Bot creation with configuration validation
- `GET /api/admin/costpools/list` - Cost pool integration for bot assignment
- Individual bot management endpoints for detailed operations
### Data Processing Flow
1. **Authentication**: Smart token coordination with multiple fallback strategies
2. **API Detection**: Dynamic API base URL detection based on environment
3. **Data Retrieval**: Comprehensive bot data loading with error handling
4. **Data Processing**: Transformation of Dataverse data to UI-friendly format
5. **UI Update**: Real-time UI updates with performance optimization
## Implementation Notes
### Page Structure
```javascript
class MyBotsPage {
// Bulletproof initialization
constructor(options = {})
async initialize(data = {})
// Comprehensive bot management
initializeComprehensiveBotManagement()
async loadBotsFromAPI(token)
processBotData(rawBots)
// Bot operations
createBotWithForm()
openBotDetails(botId)
manageBotRedirect()
// Data management
async loadBotDataFromAPIM()
exportData()
}
```
### Key Methods
- **initializeComprehensiveBotManagement()**: Sets up full bot management system
- **loadBotsFromAPI()**: Loads bot data from APIM with comprehensive error handling
- **processBotData()**: Transforms raw API data to standardized format
- **createBotWithForm()**: Handles bot creation with form validation and API integration
### Data Processing Pipeline
- **Raw Data Input**: Bot data from Dataverse entities via APIM
- **Field Mapping**: Comprehensive mapping of Dataverse fields to UI properties
- **Status Conversion**: Converting numeric status codes to user-friendly strings
- **Performance Calculation**: Real-time performance metrics and statistics
- **Avatar Generation**: Dynamic avatar generation from bot names
## Internationalization Support
### Language Features
- **Complete Translations**: German and English translations for all UI elements
- **Dynamic Switching**: Runtime language switching with persistent preferences
- **Cultural Adaptation**: Localized date formatting, number formatting, and conventions
- **Browser Detection**: Automatic language detection based on browser preferences
### Translation Structure
```javascript
const translations = {
en: {
/* Complete English translations */
},
de: {
/* Complete German translations */
},
};
```
## Development Guidelines
### Bot Data Structure
```javascript
{
id: 'bot-001',
name: 'Customer Support Bot',
type: 'chatbot',
status: 'active',
performance: 92,
workspace: 'Enterprise Division',
costPool: 'Operations',
conversations: 3847,
licenseUsed: '85%',
lastActive: '2 minutes ago',
avgResponseTime: '1.6s',
successRate: '94.2%',
allocatedLicenses: 100
}
```
### Error Handling Strategy
- **API Failures**: Graceful fallback to demo data with user notification
- **Authentication Issues**: Clear error messages with recovery guidance
- **Data Processing Errors**: Robust error handling with logging and user feedback
- **Network Issues**: Retry mechanisms and offline capability indicators
### Performance Optimization
- **Immediate Rendering**: UI displays instantly without blocking on API calls
- **Background Loading**: Data loading occurs in background with progressive enhancement
- **Efficient Updates**: Minimal DOM manipulation with smart update strategies
- **Memory Management**: Proper cleanup and resource management
## Testing Notes
### Demo Data Features
- **Realistic Data**: Demo data mirrors production data structure and relationships
- **Multiple Bot Types**: Coverage of all supported bot types and statuses
- **Performance Metrics**: Realistic performance data for UI testing
- **Error Scenarios**: Built-in error simulation for testing error handling
### Development Features
- **Comprehensive Logging**: Detailed logging for debugging and development
- **API Mocking**: Automatic fallback when APIs are unavailable
- **Error Simulation**: Built-in error scenarios for testing robustness
- **Performance Monitoring**: Built-in performance monitoring and debugging tools