UNPKG

besper-frontend-site-dev-main

Version:

Professional B-esper Frontend Site - Site-wide integration toolkit for full website bot deployment

113 lines (78 loc) 3.74 kB
# B-esper Chat Widget Implementation Flow ## Current Implementation Overview The B-esper chat widget follows a specific initialization sequence to ensure proper styling and configuration before display. ## Initialization Flow ### 1. Widget Initialization (`bsp_init_b_esperbot`) - Called by the user with `botId` and `options` - Creates a new `BesperChatWidget` instance - Calls `widget.init()` to start the initialization process ### 2. Session Creation First (`createSession`) - **CRITICAL**: Session creation happens BEFORE widget display - Makes POST request to `/create_session` endpoint - Retrieves styling information from API payload - Handles success/failure scenarios: #### Success Scenario: - Stores session data: `threadId`, `isConnected = true` - Extracts styling from API response: `data.styling` - Extracts bot configuration: `bot_name`, `bot_title`, `welcome_message`, etc. - Enables real API functionality #### Failure Scenario: - Falls back to demo mode: `isConnected = false` - Uses default styling values - Shows demo messages indicating API connection failure - Widget still functions but in offline/demo mode ### 3. Widget Creation Only After Session (`createWidget`) - **ONLY** called after `createSession()` completes (success or failure) - Creates DOM elements with styling from session data - Applies custom CSS using payload styling values - Widget is displayed with proper configuration ### 4. Styling Application (`applySessionConfiguration`) - Uses styling data retrieved from `create_session` API call - Sets CSS custom properties based on API payload - Configures colors, fonts, and visual appearance ## Questions for Clarification Based on the current implementation, the following areas could benefit from clarification: ### API Endpoint Behavior 1. **Expected Response Format**: What is the exact structure of the `create_session` response payload? - Is `data.styling` always present? - What are the required vs optional styling fields? - Should we handle partial styling data gracefully? 2. **Error Handling**: How should we handle different types of API failures? - Network timeouts - Authentication failures - Invalid bot_id - Service unavailable 3. **Fallback Behavior**: When API fails, should we: - Show an error message to the user? - Hide the widget completely? - Show demo mode (current behavior)? - Retry the connection automatically? ### Styling Requirements 4. **Required Styling Fields**: Which styling properties are mandatory vs optional? - `primary_color`, `secondary_color` - `user_message_color`, `bot_message_color` - `font_family` - Logo URLs 5. **Default Values**: Are the current default styling values appropriate? - Should they match a specific brand guideline? - Should defaults be configurable? ### User Experience 6. **Loading States**: Should we show loading indicators during session creation? - Spinner on initial load? - Progress feedback? 7. **Error Messages**: What user-friendly messages should be shown for different error states? ## Current Implementation Status**Correctly Implemented:** - Session creation happens before widget display - Styling is applied from API payload - Fallback to demo mode on API failure - Widget only shows after session establishment ❓ **Needs Clarification:** - Specific error handling requirements - Expected API response format details - User experience preferences for error states ## Code References - Main initialization: `bsp_init_b_esperbot()` (lines 1256-1280) - Session creation: `createSession()` (lines 79-147) - Widget creation: `createWidget()` (lines 149-170) - Styling application: `applySessionConfiguration()` (lines 690-695)