Skip to main content

Overview

The AI Chat SDK (@sleek/ai-chat-sdk) enables web applications to integrate intelligent, context-aware AI chat capabilities. The SDK provides a beautiful chat interface with AI-powered recommendations and merchant offers, along with flexible entry points like floating badges and inline inputs to engage users.

Key capabilities

  • Chat interface: Full-featured chat panel with AI conversation interface
  • Multiple entry points: Floating badge and inline input to engage users
  • Context-aware AI: Optional page context for smarter, relevant responses
  • Event system: Comprehensive events for all user interactions
  • Data integration: Display offer redirect URLs and cashback offers in conversations
  • Full customization: Brand colors, logos, fonts, and light/dark mode support
  • Multiple package formats: NPM package or IIFE script injection
  • Shadow DOM isolation: Prevents styling conflicts with your application

Prerequisites

Before integrating the SDK, ensure your project meets these requirements:
  • Modern browser with ES6+ support (Chrome 100+, Firefox 100+, Safari 15+, Edge 100+)
  • Node.js 18+ and package manager (pnpm, npm, or yarn) for NPM installation

Installation

1

Configure npm registry

Add the registry to your .npmrc file:
.npmrc
@sleek:registry=https://npm.cloudsmith.io/sleek/sleek/
//npm.cloudsmith.io/sleek/sleek/:_authToken={YOUR_TOKEN_HERE}
Contact [email protected] to receive your authentication token.
2

Install the package

# Using pnpm
pnpm add @sleek/ai-chat-sdk

# Using npm
npm install @sleek/ai-chat-sdk

Quick start

Here’s a minimal example to get the SDK running in your application:
import {
  initializeAiChatSdk,
  getAiChatSdk,
  AiChatSdkEventType,
} from '@sleek/ai-chat-sdk';

// Initialize the SDK
const sdk = initializeAiChatSdk('your-api-key', {
  enableDebug: true,
  chatConfig: {
    usePageContext: true,
    brand: {
      logoUrl: 'https://your-app.com/logo.png',
      name: 'Your Brand',
    },
    styling: {
      primaryColor: '#059669',
      colorMode: 'system',
    },
    content: {
      defaultPrompts: ['Show me deals', 'Compare prices'],
      disclaimerText: 'AI responses may not always be accurate',
    },
  },
  dataProviders: {
    offerRedirectUrlProvider: async (url) => {
      return `https://offer.example.com?url=${encodeURIComponent(url)}`;
    },
    merchantCashbackProvider: async (urls) => {
      const result = {};
      for (const url of urls) {
        result[url] = { text: '5% cash back' };
      }
      return result;
    },
  },
}, [
  (event) => {
    console.log('SDK Event:', event.type, event.data);
  }
]);

// Open the chat panel with an optional initial message
sdk.initializeChat('What products are available?');

SDK methods

initializeAiChatSdk

Initializes the SDK with your API key and configuration options.
function initializeAiChatSdk(
  apiKey: string,
  options?: Partial<AiChatSdkOptions>,
  listeners?: AiChatSdkEventListener[]
): Sdk
Parameters:
  • apiKey: Your API key for authentication
  • options: Configuration options (optional)
  • listeners: Array of event listener functions (optional)
Returns: SDK instance

getAiChatSdk

Retrieves the initialized SDK instance.
function getAiChatSdk(): Sdk
Returns: SDK instance (throws error if not initialized)

initializeChat

Opens the full chat panel with an optional initial message and default prompts.
sdk.initializeChat(initialMessage?: string, defaultPrompts?: string[]): void
Parameters:
  • initialMessage: Optional message to send when opening the chat
  • defaultPrompts: Optional array of prompt suggestions to display
Example:
// Open chat with initial message
sdk.initializeChat('Show me the best deals');

// Open chat with custom prompts
sdk.initializeChat(undefined, ['Compare prices', 'Find discounts', 'Show deals']);

showBadge

Shows a floating badge with AI-generated prompt suggestions. When users interact with the badge, it opens the chat panel.
sdk.showBadge(query?: string, isOnboarding?: boolean): Promise<void>
Parameters:
  • query: Optional query to generate contextual prompts
  • isOnboarding: Whether to show onboarding content (default: false)
Example:
// Show badge with default prompts
await sdk.showBadge();

// Show badge with contextual prompts based on query
await sdk.showBadge('winter jackets');

// Show onboarding badge for new users
await sdk.showBadge(undefined, true);

showInline

Shows an inline input component that can be embedded in a container element. When users interact with the inline input, it opens the chat panel.
sdk.showInline(query?: string): Promise<void>
Parameters:
  • query: Optional query to generate contextual prompts
Example:
// First configure the inline container in options
initializeAiChatSdk('your-api-key', {
  inlineConfig: {
    layout: {
      containerSelector: '#chat-container',
    },
  },
  // ... other options
});

// Show the inline input
await sdk.showInline();

Entry points

The SDK provides multiple entry points to engage users and open the chat panel:

Direct chat

Open the chat panel directly using initializeChat(). Best for explicit “Open Chat” buttons or when you want to immediately start a conversation.
sdk.initializeChat('Hello, how can I help?');

Floating badge

A compact badge that shows AI-generated prompts. Expands on hover and opens the chat panel when clicked. Great for non-intrusive engagement that encourages users to start a conversation.
await sdk.showBadge();

Inline input

An input field that can be embedded in any container element. When users type or click a prompt, the chat panel opens. Ideal for seamless integration with existing UI layouts.
await sdk.showInline();

Build formats

The SDK is distributed in multiple formats for maximum compatibility:
FormatFileUse Case
IIFEai-chat-sdk.iife.jsScript tag or runtime script injection
ESMai-chat-sdk.jsModern bundlers (Vite, Webpack, etc.)
CJSai-chat-sdk.cjsNode or CommonJS environments
All formats include TypeScript definitions (.d.ts) for full IDE support.

Getting help

API reference

For detailed type definitions and API documentation, refer to the TypeScript definitions included with the SDK package.