ChatBotKit Node SDK
    Preparing search index...

    Module @chatbotkit/widget

    ChatBotKit CBK.AI Follow on Twitter NPM Email Discord

    ChatBotKit Widget Types

    Type definitions for the ChatBotKit widget custom element. This package provides TypeScript types for interacting with the ChatBotKit widget (v2).

    • ChatBotKitWidgetElementV2: The main widget custom element interface with all available methods and properties
    • ChatBotKitGlobalObject: The global window.chatbotkitWidget object interface
    • Message: Type for conversation messages
    • FunctionDefinition: Type for registering custom functions with the widget
    • NotificationDefinition: Type for widget notifications
    • Contact: Type for contact information
    • Meta: Type for session metadata
    npm install @chatbotkit/widget
    

    Import the types directly:

    import type {
    ChatBotKitWidgetElementV2,
    ChatBotKitGlobalObject,
    FunctionDefinition,
    Message,
    } from '@chatbotkit/widget'

    // Access the widget instance
    const widget = window.chatbotkitWidget.instance

    // Or wait for it to be ready
    const widget = await window.chatbotkitWidget.instancePromise

    // Register custom functions
    const myFunction: FunctionDefinition = {
    description: 'Get the current user name',
    parameters: {},
    handler: async () => {
    return 'John Doe'
    },
    }

    widget.registerFunctions({ getUserName: myFunction })

    // Send a message
    widget.sendMessage({ text: 'Hello!' })

    // Listen to messages
    console.log(widget.messages)

    The types augment the global Window interface, so you can access window.chatbotkitWidget with full type safety:

    import '@chatbotkit/widget'

    // Now window.chatbotkitWidget is typed
    window.chatbotkitWidget.instancePromise.then((widget) => {
    widget.open = true
    widget.sendMessage({ text: 'Hello from TypeScript!' })
    })

    For React integration, consider using the @chatbotkit/react package which includes hooks like:

    • useWidgetInstance - Access the widget instance
    • useWidgetInstanceFunctions - Register functions with the widget
    • useWidgetInstanceNotifications - Manage widget notifications

    For more information about the ChatBotKit widget, visit:

    Found a bug or wish to contribute? We welcome your input! Please open an issue or submit a pull request on our official GitHub repository.

    Modules

    v2