Skip to main content

Custom Integration

Learn how to build custom integrations with ChatMaven. This guide covers advanced integration scenarios, custom implementations, and best practices for extending ChatMaven's functionality.

Overview​

Integration Types​

  1. Custom Platforms

    • Proprietary systems
    • Legacy applications
    • Custom frameworks
    • Internal tools
  2. Data Sources

    • Custom databases
    • Internal APIs
    • Third-party services
    • Data streams
  3. User Interfaces

    • Custom widgets
    • Embedded views
    • Native applications
    • Voice interfaces

Building Custom Integrations​

Architecture​

  1. Components

    // Example integration structure
    class CustomIntegration {
    constructor(config) {
    this.api = new ChatMavenAPI(config);
    this.events = new EventHandler();
    this.store = new DataStore();
    }
    }
  2. Event System

    // Custom event handling
    class EventHandler {
    subscribe(event, callback) {
    this.events[event] = callback;
    }

    emit(event, data) {
    if (this.events[event]) {
    this.events[event](data);
    }
    }
    }
  3. Data Management

    // Custom data store
    class DataStore {
    async sync() {
    const data = await this.api.fetch();
    this.store.update(data);
    }

    async push(changes) {
    await this.api.update(changes);
    this.store.commit(changes);
    }
    }

Implementation Guide​

Setup​

  1. Initialize SDK

    const chatmaven = new ChatMaven({
    apiKey: 'YOUR_API_KEY',
    customConfig: {
    endpoint: 'https://your-api.com',
    version: 'v2',
    timeout: 5000
    }
    });
  2. Configure Handlers

    chatmaven.on('custom:event', async (data) => {
    // Handle custom event
    await processCustomEvent(data);
    });

    chatmaven.interceptors.add((request) => {
    // Modify requests
    request.headers['Custom-Header'] = 'value';
    return request;
    });

Custom Features​

Data Synchronization​

class DataSync {
constructor(config) {
this.interval = config.interval || 5000;
this.lastSync = null;
}

async start() {
while (true) {
await this.sync();
await sleep(this.interval);
}
}

async sync() {
const changes = await this.getChanges();
await this.pushChanges(changes);
this.lastSync = Date.now();
}
}

Custom UI Components​

class CustomWidget extends ChatMavenWidget {
constructor(props) {
super(props);
this.customState = {};
}

render() {
return `
<div class="custom-widget">
${this.renderCustomElements()}
${super.render()}
</div>
`;
}

renderCustomElements() {
// Add custom UI elements
}
}

Advanced Features​

Custom Authentication​

class CustomAuth {
async authenticate() {
const token = await this.getCustomToken();
return {
type: 'custom',
token: token,
expires: Date.now() + 3600000
};
}

async refresh() {
// Implement token refresh
}
}

Data Transformation​

class DataTransformer {
transform(data) {
return {
id: data.custom_id,
content: this.processContent(data.body),
metadata: this.extractMetadata(data),
timestamp: new Date(data.created_at)
};
}

processContent(content) {
// Custom content processing
}

extractMetadata(data) {
// Custom metadata extraction
}
}

Best Practices​

Error Handling​

class ErrorHandler {
handle(error) {
if (error.type === 'custom') {
// Handle custom errors
this.handleCustomError(error);
} else {
// Forward to default handler
super.handle(error);
}
}

handleCustomError(error) {
// Custom error handling logic
}
}

Performance Optimization​

  1. Caching

    class CustomCache {
    async get(key) {
    // Check custom cache
    return this.cache.get(key);
    }

    async set(key, value, ttl) {
    // Set with custom TTL
    await this.cache.set(key, value, ttl);
    }
    }
  2. Rate Limiting

    class RateLimiter {
    async checkLimit(key) {
    const current = await this.getCount(key);
    if (current > this.limit) {
    throw new Error('Rate limit exceeded');
    }
    await this.increment(key);
    }
    }

Testing​

Unit Tests​

describe('CustomIntegration', () => {
it('should handle custom events', async () => {
const integration = new CustomIntegration();
const result = await integration.handleEvent({
type: 'custom',
data: {}
});
expect(result).toBeDefined();
});
});

Integration Tests​

describe('E2E Tests', () => {
it('should complete full workflow', async () => {
const client = new CustomClient();
await client.connect();
await client.sendCustomData();
const response = await client.waitForResponse();
expect(response.status).toBe('success');
});
});

Deployment​

Configuration​

const config = {
environment: process.env.NODE_ENV,
customEndpoint: process.env.CUSTOM_ENDPOINT,
apiKey: process.env.API_KEY,
options: {
timeout: 5000,
retries: 3,
customFlags: {
feature1: true,
feature2: false
}
}
};

Monitoring​

class CustomMonitor {
track(event) {
// Track custom metrics
this.metrics.increment(`custom.${event.type}`);
this.logger.log('custom_event', event);
}

alert(condition) {
// Custom alerting logic
if (this.shouldAlert(condition)) {
this.notifications.send('alert', condition);
}
}
}

Next Steps​


FAQ and troubleshooting​

When is a custom integration appropriate?​

Use a custom path when the standard widget, iframe, or REST flows do not fit your stack—for example a native mobile shell, strict CSP, or a backend that must own all user-visible tokens.

What if the embed or SDK loads but messages do not send?​

Check browser or app console for blocked requests, CORS, or mixed content. Confirm the snippet points to the correct agent or workspace ID and that the deployment environment allows the ChatMaven domains.

Can ChatMaven review my integration design?​

Contact support with architecture notes (no secrets). They can point you to the closest documented pattern—widget, iframe, API, or webhooks.