@skywu/virtual-chat-sdk
v2.5.7
Published
Virtual Chat SDK - Floating chat widget with 20+ languages support for seamless website integration
Maintainers
Readme
@skywu/virtual-chat-sdk
JavaScript/TypeScript SDK for embedding a virtual chat widget into websites.
Supports floating/fullscreen modes, real-time messaging, virtual simulation, and multilingual UI.
Installation
npm install @skywu/virtual-chat-sdk
# or
yarn add @skywu/virtual-chat-sdk
# or
pnpm add @skywu/virtual-chat-sdkQuick Start (ESM)
import { ChatSDK } from '@skywu/virtual-chat-sdk'
const chat = ChatSDK.init({
container: '#chat-container',
projectId: 'YOUR_PROJECT_ID',
userId: 'user_123',
username: 'Visitor',
language: 'en',
country: 'US',
mode: 'floating',
autoJoin: true,
apiBaseUrl: 'https://YOUR_SERVER_DOMAIN',
socketUrl: 'https://YOUR_SERVER_DOMAIN',
floatingButton: {
position: 'bottom-right',
offset: { bottom: 20, right: 20 }
}
})Quick Start (UMD)
<div id="chat-container"></div>
<script src="https://YOUR_SERVER_DOMAIN/sdk/chat-sdk.umd.js"></script>
<script>
const chat = ChatSDK.init({
container: '#chat-container',
projectId: 'YOUR_PROJECT_ID',
userId: 'user_123',
username: 'Visitor',
language: 'en',
country: 'US',
mode: 'floating',
autoJoin: true,
apiBaseUrl: 'https://YOUR_SERVER_DOMAIN',
socketUrl: 'https://YOUR_SERVER_DOMAIN'
})
</script>Configuration
Required
container:string | HTMLElementprojectId:string
Core Optional
templateId?: stringuserId?: stringusername?: stringlanguage?: stringcountry?: stringtheme?: 'light' | 'dark' | 'auto'uiTemplate?: 'whatsapp' | 'telegram'primaryColor?: stringbackgroundColor?: stringapiBaseUrl?: stringsocketUrl?: stringtoken?: stringmode?: 'fullscreen' | 'floating'autoJoin?: booleanautoStart?: boolean
Floating Button
floatingButton?: {
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left'
offset?: { top?: number; right?: number; bottom?: number; left?: number }
icon?: 'chat' | string
zIndex?: number
}UI / Performance
showAvatars?: booleanshowUsernames?: booleanallowInput?: booleanenableUserInput?: booleaninitialRenderCount?: numberlazyLoadBatchSize?: numbergroupMessages?: booleangroupTimeThresholdSec?: number
Callbacks
onReady?: () => voidonOpen?: () => voidonClose?: () => voidonJoin?: (data: { userId: string; username: string }) => voidonMessage?: (message: ChatMessage) => voidonUserMessage?: (message: ChatMessage) => voidonError?: (error: Error) => voidonLanguageChange?: (language: string) => voidonThemeChange?: (theme: string) => voidonSimulationStart?: () => voidonSimulationEnd?: () => void
API Methods
chat.open()
chat.close()
chat.destroy()
chat.joinChat()
chat.leaveChat()
chat.sendMessage('Hello', 'text')
chat.startSimulation()
chat.pauseSimulation()
chat.resumeSimulation()
chat.stopSimulation()
await chat.setLanguage('zh')
chat.setTheme('dark')
chat.setUITemplate('telegram')
chat.setCustomColors({ primary: '#2481CC', background: '#FFFFFF' })
chat.setTemplate('template-id')
chat.isOpen()
chat.isJoined()
chat.getConfig()
chat.getMessages()Events
chat.on('ready', () => {})
chat.on('open', () => {})
chat.on('close', () => {})
chat.on('message', (message) => {})
chat.on('error', (error) => {})
chat.off('message')Display Modes
floating(recommended): floating launcher button; no need to callopen()manually.fullscreen: full chat UI mode; callopen()when needed.
TypeScript
import { ChatSDK, ChatSDKConfig, ChatMessage } from '@skywu/virtual-chat-sdk'
const config: ChatSDKConfig = {
container: '#chat-container',
projectId: 'YOUR_PROJECT_ID',
country: 'US',
onMessage: (message: ChatMessage) => {
console.log(message.content)
}
}
const chat = ChatSDK.init(config)Notes
- For third-party sites, always set
apiBaseUrlandsocketUrl. - Make sure your server CORS allows your site origin.
projectIdcomes from your admin project list.- Call
destroy()when unmounting in SPA frameworks.
License
MIT
