Wonderful SDK for TypeScript
A TypeScript SDK for integrating Wonderful’s contact center capabilities into your mobile apps and web clients. Supports real-time WebSocket chat, JWT authentication, session recovery, and communication history.Installation
Add the Wonderful registry to your project’s.npmrc:
Quick Start
SDK Initialization
SDKConfig
token, signedToken, or apiKey. Use apiKey on the backend only; use signedToken (with refreshToken) on the frontend.
Initialization Examples
Default Behavior
| Setting | Default | Description |
|---|---|---|
| Request timeout | 30,000ms | HTTP request timeout |
| Max retries | 3 | Automatic retry on network errors |
| Retry delay | 1,000ms | Initial delay (exponential backoff) |
| WebSocket ping | 30,000ms | Keep-alive interval |
| Max reconnect attempts | 5 | WebSocket reconnection limit |
Modules
| Module | Description | Docs |
|---|---|---|
sdk.auth | Sign JWTs for end-user authentication (backend only, requires apiKey) | Authentication |
sdk.chat | Start, recover, and manage real-time chat sessions via WebSocket | Chat |
sdk.communications | Query communication history with filtering and pagination | Communications |
Additional Methods
| Property / Method | Description |
|---|---|
sdk.config | Current SDK configuration (read-only copy) |
sdk.setToken(token) | Update the authentication token at runtime |
sdk.clearAuth() | Clear all auth credentials from the SDK |
WonderfulSDK.version | SDK version string |
Backend Integration
The SDK uses a backend + frontend architecture. Your backend signs JWTs using an API key (never exposed to browsers), and your frontend uses those tokens to connect.Express.js Token Endpoint
Frontend Connection
Complete Example
Mobile App Recovery Pattern
Error Handling
Error Codes
| Code | Description | Recoverable |
|---|---|---|
INVALID_REQUEST | Missing required field or invalid parameter | No |
MISSING_PARTICIPANT | from and fromType are required | No |
SESSION_NOT_FOUND | Session does not exist or was not initialized | No |
SESSION_ENDED | Session has already ended | No |
PII_MASKING_ENABLED | Live streaming blocked due to PII masking | No |
NETWORK_ERROR | Network request failed | Yes |
AUTH_ERROR | Missing or invalid authentication credentials | No |
AUTH_EXPIRED | JWT token expired | Yes (refresh) |
UNAUTHORIZED | Invalid or missing API key | No |
FORBIDDEN | Insufficient permissions (HTTP 403) | No |
VALIDATION_ERROR | Request validation failed (invalid params, metadata too large) | No |
RATE_LIMITED | Too many requests | Yes (retry) |
UNKNOWN_ERROR | Unexpected error occurred | Depends |
Exported Types
All types are exported for TypeScript users:Feature Support
| Feature | Status | Notes |
|---|---|---|
| Text messages | Supported | Send and receive |
| Image messages | Supported | Via mediaUrl |
| Document messages | Supported | Via mediaUrl + fileName |
| Voice/Audio messages | Receive only | Cannot send via SDK |
| Location messages | Receive only | Cannot send via SDK |
| Session metadata | Supported | Custom key-value pairs on start |
| Message metadata | Supported | Custom data per message |
| Session recovery | Supported | sdk.chat.recover(sessionId) |
| Session forwarding | Supported | session.forward(destination) |
| Auto-reconnect | Supported | Exponential backoff (max 5 attempts) |
| Token refresh | Supported | Via refreshToken callback |
| Typing indicators | Not available | Platform feature only |
| Read receipts | Not available | Platform feature only |
| Presence status | Not available | Not implemented |