docs.api.title
docs.api.intro
docs.api.methodsTitle
| docs.api.method | docs.api.parameters | docs.api.returns | docs.api.description |
|---|---|---|---|
init(config) | ChaskWidgetConfig | Promise<void> | docs.api.initDesc |
open() | - | void | docs.api.openDesc |
close() | - | void | docs.api.closeDesc |
toggle() | - | void | docs.api.toggleDesc |
send(message) | string | Promise<void> | docs.api.sendDesc |
setUser(user) | UserConfig | Promise<void> | docs.api.setUserDesc |
getState() | - | WidgetState | docs.api.getStateDesc |
showLauncher() | - | void | docs.api.showLauncherDesc |
hideLauncher() | - | void | docs.api.hideLauncherDesc |
destroy() | - | void | docs.api.destroyDesc |
isInitialized() | - | boolean | docs.api.isInitializedDesc |
Usage Examples
// Initialize the widget
await ChaskWidget.init({
apiKey: 'your-api-key',
organizationId: 'your-org-id'
});
// Open the chat window
ChaskWidget.open();
// Send a message programmatically
await ChaskWidget.send('Hello, I need help!');
// Update user information
await ChaskWidget.setUser({
id: 'user-456',
name: 'Jane Doe',
email: 'jane@example.com'
});
// Get current state
const state = ChaskWidget.getState();
console.log('Unread messages:', state.unreadCount);
// Toggle chat visibility
ChaskWidget.toggle();
// Hide the launcher button
ChaskWidget.hideLauncher();
// Cleanup when done
ChaskWidget.destroy();docs.api.stateTitle
docs.api.stateDesc
| docs.api.property | docs.configuration.type | docs.api.description |
|---|---|---|
initialized | boolean | Whether the widget is initialized |
isOpen | boolean | Whether the chat window is open |
isConnected | boolean | Whether connected to WebSocket |
unreadCount | number | Count of unread messages |
error | WidgetError | null | Current error state |
State Example
const state = ChaskWidget.getState();
if (state.isConnected) {
console.log('Connected to chat server');
console.log('Unread:', state.unreadCount);
}
if (state.error) {
console.error('Widget error:', state.error.message);
}