/** * @module @verba/chat-sdk/types * All public-facing types and interfaces for the Verba Chat Widget SDK. */ /** Visual theme passed to the embedded widget. */ export type Theme = 'light' | 'dark'; /** Advanced visual theme configuration passed via URL parameters. */ export interface ThemeConfig { primaryColor?: string; textColor?: string; backgroundColor?: string; fontFamily?: string; } /** Position of the floating chat bubble. */ export type BubblePosition = 'bottom-right' | 'bottom-left'; /** Floating Chat Bubble configuration */ export interface ChatBubbleConfig { /** * Corner position of the floating bubble. * @default 'bottom-right' */ position?: BubblePosition; /** * Background color of the bubble. Can be any valid CSS color or gradient. * @default '#ffffff' */ color?: string; /** * Size of the bubble in pixels (width and height). * @default 56 */ size?: number; /** * SVG string for the custom open (chat) icon. * If omitted, a default chat icon is used. */ icon?: string; /** * Color of the close (X) icon. * @default '#000000' */ closeIconColor?: string; /** * Stroke color of the chat icon. * @default '#000000' */ chatIconStrokeColor?: string; /** * Custom CSS color (rgba or hex) for the bubble's box-shadow. * Overrides the default shadow colors. */ shadowColor?: string; /** * Configuration for the first-time greeting popup shown near the bubble. */ greeting?: ChatBubbleGreetingConfig; /** * Color of the unread-message badge dot shown on the bubble. * @default '#ef4444' */ badgeColor?: string; } /** First-time greeting popup configuration. */ export interface ChatBubbleGreetingConfig { /** * The message shown the first time a visitor sees the widget. * @default 'Hey, if you need some help, ask me anything!' */ message?: string; /** * Delay (ms) before the greeting auto-appears after the widget mounts. * @default 2000 */ delay?: number; /** * Disable the first-time greeting popup entirely. * @default false */ disabled?: boolean; } /** * Configuration object accepted by the `VerbaChat` constructor. */ export interface VerbaChatConfig { /** * Your Verba tag ID — passed via the `tagId` URL parameter. */ tagId: string; /** * Visual theme of the widget. * Can be a simple string ('light' | 'dark') or an object for detailed customisation. * @default 'light' */ theme?: Theme | ThemeConfig; /** * Where to mount the widget iframe. * - A CSS selector string (e.g. `'#chat-root'`) * - An `HTMLElement` reference * - Omit for a **floating bubble** fixed to the viewport corner. */ targetElement?: string | HTMLElement; /** * Configuration for the floating bubble. * Has no effect when `targetElement` is provided. */ bubble?: ChatBubbleConfig; /** * Optional: You can change the assistants avatar * Provide a valid URL to an image if you would like to change it. */ assistantAvatar?: string; /** * Optional: Provide a token for authentication * Required for authenticated sessions, without it, the widget will not load. */ token?: string; /** * Optional: Token environment passed alongside the authentication token. * Omit to preserve existing client behaviour. */ tokenEnvironment?: string; /** * Optional: Enable thread list * If false, only a single *new* chat(thread) will be provided, if true, users will have the option to view a list of previous conversations(threads). * @default false */ withThreadList?: boolean; /** * Source URL of the widget. * @default 'https://embed.verba.chat/embeddable.html' */ src?: string; } /** * Lifecycle state of the SDK instance. * Follows the state machine: * uninitialized → ready * ↓ * destroyed */ export type WidgetState = 'uninitialized' | 'ready' | 'destroyed'; /** All message types that flow across the postMessage bridge. */ export type MessageType = 'INIT_WIDGET' | 'READY' | 'EXPAND_WIDGET' | 'SHRINK_WIDGET' | 'CLOSE_WIDGET' | 'SHOW_WIDGET_MESSAGE' | 'BUBBLE_CONFIG'; /** * Shape of every message crossing the postMessage bridge. * The `data` field is typed per `MessageType` so consumers can narrow it. */ export interface PostMessagePayload { /** Namespace guard — prevents collisions with other postMessage users. */ source: 'verba-chat-sdk'; type: MessageType; data: T; } /** Options for constructing a `Messenger` instance. */ export interface MessengerOptions { /** The `contentWindow` of the target iframe. */ targetWindow: Window; /** * The exact origin to which messages are posted. * Must match the widget's host (e.g. `https://embedded.verba.chat`). */ targetOrigin: string; /** * The origin from which incoming messages are accepted. * Messages from any other origin are silently discarded. */ allowedOrigin: string; } /** Typed handler for an incoming postMessage event. */ export type MessageHandler = (data: T) => void;