keepkey-support-connector
v0.1.0
Published
KeepKey messaging client for WebSocket communication and support interactions
Maintainers
Readme
KeepKey Messaging Client
A TypeScript client for connecting to the KeepKey Support messaging server. This client uses standard WebSocket protocol to handle real-time messaging and status updates.
Features
- Real-time messaging over WebSocket
- Authentication and reconnection handling
- Typing indicators and status updates
- Event-based architecture
- Written in TypeScript with full type definitions
Installation
npm install @keepkey/messaging-clientOr with Yarn:
yarn add @keepkey/messaging-clientUsage
Basic Example
import { MessagingClient } from '@keepkey/messaging-client';
// Create a client
const client = new MessagingClient({
url: 'ws://localhost:4455',
debug: true
});
// Set up event handlers
client.on('connected', () => {
console.log('Connected to server!');
// Authenticate
client.authenticate('user123', 'auth-token')
.then(success => {
if (success) {
console.log('Authentication successful!');
// Send a message
return client.sendMessage('ticket-123', 'Hello, this is a test message!');
}
})
.then(messageId => {
console.log(`Message sent with ID: ${messageId}`);
});
});
client.on('message', (message) => {
console.log(`Received message: ${message.content}`);
});
// Connect to the server
client.connect();Configuration Options
The client accepts the following configuration options:
interface ClientOptions {
// The URL of the messaging server
url: string;
// Optional auth token for authentication
authToken?: string;
// Optional client ID
clientId?: string;
// Optional user ID
userId?: string;
// Skip REST API authentication check (default: false)
skipRestAuth?: boolean;
// Debug mode - enables verbose logging (default: false)
debug?: boolean;
// Auto reconnect on disconnect (default: true)
autoReconnect?: boolean;
// Maximum reconnection attempts (default: 5)
maxReconnectAttempts?: number;
// Reconnection delay in ms (default: 2000)
reconnectDelay?: number;
}Events
The client emits the following events:
connected: Fired when the WebSocket connection is establisheddisconnected: Fired when the WebSocket connection is closederror: Fired when an error occursauthenticated: Fired when authentication is successfulauth_failed: Fired when authentication failsmessage: Fired when a chat message is receivedstatus: Fired when a status update is received (e.g., typing indicators)
API Reference
Connection
connect(): Connect to the messaging serverdisconnect(): Disconnect from the messaging serverisConnected(): Check if the client is connectedisAuthenticated(): Check if the client is authenticated
Authentication
authenticate(userId: string, token: string): Authenticate with the server
Messaging
sendMessage(ticketId: string, content: string): Send a chat messagesendTypingIndicator(ticketId: string, isTyping: boolean): Send a typing indicatorping(): Send a ping message to keep the connection alive
Event Handling
on(event: string, handler: Function): Subscribe to an eventonce(event: string, handler: Function): Subscribe to an event onceoff(event: string, handler?: Function): Unsubscribe from an event
Development
Building
npm run buildTesting
npm testLicense
MIT
