You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
CURRENT BEHAVIOR:
- Client fetches JWT from `/api/auth/jwt` on initialization
- Always expects `{ token: "..." }` response
- Uses token to initialize VAPI call
REQUIRED CHANGES:
1. Handle `{ error: "Usage limit exceeded" }` response from JWT endpoint
2. Show user-friendly error message instead of initializing VAPI
3. Prevent call attempts when usage limit is exceeded
4. Display appropriate UI state (disabled widget or error message)
IMPLEMENTATION:
Widget Script Changes (src/widget.js):
- Modified fetchJwt() to handle 402 status codes and { error: "..." } responses
- Added isUsageLimit flag for error classification
- Updated getUserFriendlyError() to use server's specific error messages
- Split handleInitializationError() into usage limit vs generic error paths
- Added createUsageLimitWidget() that creates disabled phone button with upgrade messaging
- Added showUsageLimitMessage() with positioned overlay based on widget location
- Added CSS .buzzwald-button-disabled class with gray styling and disabled interactions
- Fixed ensureToken() to preserve isUsageLimit flag when re-throwing errors
- Updated JWT refresh logic in VAPI error handlers for usage limit cases
Auto-Recovery Feature:
- Added startUsageLimitRetry() with 5-second interval checking (configurable)
- Added restoreWidget() method to transition back to functional state
- Added showRestoreSuccessMessage() with green success notification
- Auto-recovery attempts JWT fetch every 5 seconds up to 10 attempts
- Automatically restores widget when user upgrades (seamless UX)
- Proper cleanup of retry timers in destroy() method
Test Updates (test/test.html):
- Added testUpgrade() to simulate user upgrading their plan
- Added testRefreshAfterUpgrade() to test page refresh scenario
- Added manualRetryCheck() for debugging auto-recovery mechanism
- Fixed widget storage in window.buzzwaldWidget for debugging access
- Updated usage limit mock to return 402 status with server error format
- Added post-upgrade mock to return successful JWT tokens
EXPECTED BEHAVIOR:
✅ Success case: Normal phone button, functional calls
✅ Usage limit case: Grayed-out phone button + orange upgrade message
✅ Auto-recovery: Green success message + automatic restoration when upgraded
✅ Manual recovery: Page refresh immediately restores functionality
✅ Other errors: Red error button with technical error details
The widget now provides seamless UX where users don't need to refresh
the page after upgrading - it automatically detects the upgrade and
restores functionality within 30 seconds.
0 commit comments