@channlize/core
v0.1.0-alpha.1
Published
Channlize Core SDK - TypeScript API wrapper for Channlize platform
Maintainers
Readme
@channlize/core
Core TypeScript SDK for the Channlize platform. Provides API client functionality for submitting contact forms and managing chat sessions.
Installation
npm install @channlize/coreUsage
Basic Setup
import { ChannlizeClient } from '@channlize/core';
const client = new ChannlizeClient({
apiKey: 'your-api-key',
projectId: 'your-project-id',
baseUrl: 'https://api.channlize.com', // optional
timeout: 10000, // optional, default 10s
});Contact Forms
// Submit a contact form
const response = await client.submitContactForm({
name: 'John Doe',
email: '[email protected]',
subject: 'Support Request',
message: 'I need help with my account',
customFields: {
department: 'support',
priority: 'high',
},
});
console.log('Submission ID:', response.id);
console.log('Slack thread:', response.slackThreadUrl);Chat Sessions
// Create a new chat session
const sessionResponse = await client.createChatSession({
userAgent: navigator.userAgent,
pageUrl: window.location.href,
});
const session = sessionResponse.session;
// Send a message
await client.sendMessage(session.id, 'Hello, I need help!');
// Send message with file attachments
const files = [document.querySelector('input[type="file"]').files[0]];
await client.sendMessage(session.id, 'Please see attached file', files);
// Get session details
const updatedSession = await client.getChatSession(session.id);
// Get messages
const messages = await client.getChatMessages(session.id, 50, 0);
// Close session
await client.closeChatSession(session.id);Error Handling
import {
ChannlizeError,
ValidationError,
AuthenticationError,
RateLimitError,
} from '@channlize/core';
try {
await client.submitContactForm(formData);
} catch (error) {
if (error instanceof ValidationError) {
console.error('Validation failed:', error.message, error.field);
} else if (error instanceof AuthenticationError) {
console.error('Authentication failed:', error.message);
} else if (error instanceof RateLimitError) {
console.error('Rate limit exceeded:', error.message);
} else if (error instanceof ChannlizeError) {
console.error('API error:', error.message, error.statusCode);
} else {
console.error('Unknown error:', error);
}
}API Reference
ChannlizeClient
Constructor Options
interface ChannlizeConfig {
apiKey: string; // Required: Your API key
projectId: string; // Required: Your project ID
baseUrl?: string; // Optional: API base URL
timeout?: number; // Optional: Request timeout in ms
}Methods
submitContactForm(data: ContactFormData): Promise<CreateContactResponse>createChatSession(metadata?: Record<string, unknown>): Promise<CreateChatSessionResponse>sendMessage(sessionId: string, content: string, attachments?: File[]): Promise<SendMessageResponse>getChatSession(sessionId: string): Promise<ChatSession>getChatMessages(sessionId: string, limit?: number, offset?: number): Promise<ChatMessage[]>closeChatSession(sessionId: string): Promise<ChatSession>
Types
All TypeScript types are exported from the package:
import type {
ChannlizeConfig,
ContactFormData,
ChatMessage,
ChatSession,
FileAttachment,
CreateContactResponse,
CreateChatSessionResponse,
SendMessageResponse,
ChannlizeError,
ValidationError,
AuthenticationError,
RateLimitError,
} from '@channlize/core';License
MIT
