CommandBar JavaScript SDK

1.14.0 · active · verified Sun Apr 19

CommandBar is a JavaScript/TypeScript SDK designed to embed an AI-powered command bar and user assistance platform into web and mobile applications. It allows developers to add contextual help, searchable commands, in-app guides, checklists, nudges, and product tours, acting as a dynamic, embedded wiki for application functionality and support. The current stable npm package version is 1.14.0. While the npm package itself was last published two years ago, the underlying CommandBar service and its features, such as the AI Copilot and mobile support, are actively developed. Key differentiators include its AI capabilities for user assistance, robust mobile application support via dedicated SDKs (iOS, Android, React Native), and a comprehensive suite of tools for digital adoption and user engagement, contrasting with simpler command palettes or generic UI libraries.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the CommandBar SDK with an organization ID and then 'boot' it for a specific user, including how to add a custom command. This sequence is essential for the CommandBar UI to appear and function correctly in your application.

import { init } from 'commandbar';

// Initialize CommandBar with your organization ID.
// This should typically run once when your application starts.
const MY_ORG_ID = process.env.COMMANDBAR_ORG_ID ?? 'YOUR_ORGANIZATION_ID'; // Replace with your actual ID
init(MY_ORG_ID);

// Simulate a user authentication flow and boot CommandBar for the identified user.
function initializeUserCommandBar(userID: string) {
  if (typeof window.CommandBar !== 'undefined' && window.CommandBar.boot) {
    window.CommandBar.boot(userID, { 
      // Optional user properties for analytics and targeting
      plan: 'pro', 
      signedUpDate: new Date().toISOString() 
    });
    console.log(`CommandBar booted for user: ${userID}`);

    // Example of adding a custom command
    window.CommandBar.addCommands([
      {
        id: 'navigate-dashboard',
        name: 'Go to Dashboard',
        description: 'Navigates to the main user dashboard.',
        handler: () => {
          alert('Navigating to dashboard...');
          // In a real app, you'd use your router here: e.g., router.push('/dashboard');
        },
        // You can add additional metadata for filtering, etc.
        category: 'Navigation'
      }
    ]);
    console.log('Custom command added: Go to Dashboard');
  } else {
    console.error('CommandBar is not initialized or available globally.');
  }
}

// Example usage: Call this function after a user logs in or is identified.
const authenticatedUserID = 'user_12345'; // Replace with actual authenticated user ID
initializeUserCommandBar(authenticatedUserID);

// You can also boot for anonymous users if needed (pass null or an empty string for userID)
// initializeUserCommandBar(null);

view raw JSON →