@dialstack/sdk

中文文档
2.1.0发布于 2026/08/10MITTypeScriptESM + CJS近 30 天下载 6845

Official JavaScript SDK for DialStack - Business Voice for Vertical SaaS

此软件包已被标记为弃用

@dialstack/sdk is no longer updated. Use @dialstack/sdk-js, @dialstack/sdk-react, @dialstack/sdk-webrtc, @dialstack/sdk-server or @dialstack/sdk-native: https://docs.dialstack.ai/sdks/installation

原始使用文档
文档目录22 节
  1. Installation
  2. Quick Start
  3. React
  4. Vanilla JavaScript
  5. Components
  6. CallLogs
  7. Voicemails
  8. Theming
  9. Internationalization (i18n)
  10. Formatting
  11. Error Handling
  12. Provider Errors
  13. Network Errors
  14. Accessibility
  15. API Reference
  16. loadDialstackAndInitialize(options)
  17. DialstackComponentsProvider
  18. Authentication
  19. Browser Compatibility
  20. Documentation
  21. Support
  22. License

@dialstack/sdk

Official JavaScript SDK for DialStack - Business Voice for Vertical SaaS.

Embed voice capabilities directly into your application with ready-to-use React components for call logs, voicemails, and more.

Installation

npm install @dialstack/sdk

Quick Start

React

import { loadDialstackAndInitialize } from '@dialstack/sdk';
import { DialstackComponentsProvider, CallLogs, Voicemails } from '@dialstack/sdk/react';
import { useEffect, useState } from 'react';
import type { DialStackInstance } from '@dialstack/sdk';

function App() {
  const [dialstack, setDialstack] = useState<DialStackInstance | null>(null);

  useEffect(() => {
    // Initialize DialStack with your publishable key and session fetcher
    loadDialstackAndInitialize({
      publishableKey: 'pk_live_YOUR_PUBLISHABLE_KEY',
      fetchClientSecret: async () => {
        const res = await fetch('https://your-backend.com/api/create-session', {
          method: 'POST',
          headers: { 'Content-Type': 'application/json' },
          body: JSON.stringify({ accountId: 'acct_123' }),
        });
        const data = await res.json();
        return data.client_secret;
      },
    }).then(setDialstack);
  }, []);

  if (!dialstack) {
    return <div>Loading...</div>;
  }

  return (
    <DialstackComponentsProvider dialstack={dialstack}>
      <div>
        <h1>My Voice Dashboard</h1>
        <CallLogs />
        <Voicemails />
      </div>
    </DialstackComponentsProvider>
  );
}

Vanilla JavaScript

<!DOCTYPE html>
<html>
  <head>
    <script src="https://unpkg.com/@dialstack/sdk"></script>
  </head>
  <body>
    <dialstack-call-logs></dialstack-call-logs>
    <dialstack-voicemails></dialstack-voicemails>

    <script>
      // Initialize DialStack with session fetcher
      DialStack.loadDialstackAndInitialize({
        publishableKey: 'pk_live_YOUR_PUBLISHABLE_KEY',
        fetchClientSecret: async () => {
          const res = await fetch('https://your-backend.com/api/create-session', {
            method: 'POST',
            body: JSON.stringify({ accountId: 'acct_123' }),
          });
          const data = await res.json();
          return data.client_secret;
        },
      });
    </script>
  </body>
</html>

Components

CallLogs

Display a list of call history with details like caller, duration, and status.

<CallLogs
  dateRange={{ start: '2025-01-01', end: '2025-01-31' }}
  limit={50}
  onRowClick={(e) => console.log('Selected call:', e.callId)}
  onLoadError={(e) => console.error(e.error)}
/>

Props:

  • dateRange - Filter by date range ({ start?: string, end?: string })
  • limit - Maximum records to display (default: 20)
  • locale - Custom locale for UI strings
  • formatting - Date/phone formatting options
  • onLoaderStart - Callback when loading starts
  • onLoadError - Callback when loading fails
  • onPageChange - Callback when pagination changes
  • onRowClick - Callback when a row is clicked

Voicemails

Display a list of voicemails with playback controls.

<Voicemails
  userId="user-uuid-123"
  onVoicemailSelect={(e) => console.log('Selected:', e.voicemailId)}
  onCallBack={(e) => initiateCall(e.phoneNumber)}
/>

Props:

  • userId - User ID to fetch voicemails for (required)
  • locale - Custom locale for UI strings
  • formatting - Date/phone formatting options
  • onLoaderStart - Callback when loading starts
  • onLoadError - Callback when loading fails
  • onVoicemailSelect - Callback when a voicemail is selected
  • onVoicemailPlay - Callback when playback starts
  • onVoicemailPause - Callback when playback pauses
  • onVoicemailDelete - Callback when a voicemail is deleted
  • onCallBack - Callback when call back button is clicked

Theming

Customize component appearance using CSS variables passed via the appearance option during initialization:

const dialstack = await loadDialstackAndInitialize({
  publishableKey: 'pk_live_YOUR_KEY',
  fetchClientSecret: async () => {
    /* ... */
  },
  appearance: {
    theme: 'light', // 'light' | 'dark' | 'auto'
    variables: {
      // Colors
      colorPrimary: '#6772E5',
      colorBackground: '#ffffff',
      colorText: '#1a1a1a',
      colorDanger: '#e5484d',
      colorSuccess: '#30a46c',

      // Typography
      fontFamily: 'Inter, system-ui, sans-serif',
      fontSizeBase: '14px',

      // Spacing
      spacingUnit: '8px',
      borderRadius: '4px',
    },
  },
});

All components inherit appearance from the SDK instance and automatically adjust for light/dark themes.

Internationalization (i18n)

Components support full internationalization via the locale prop:

import { en } from '@dialstack/sdk/locales';

// Create a custom locale by extending the default
const fr: typeof en = {
  common: {
    loading: 'Chargement...',
    error: 'Erreur',
    // ... other translations
  },
  callLogs: {
    title: 'Journal des appels',
    // ... other translations
  },
  voicemails: {
    title: 'Messagerie vocale',
    // ... other translations
  },
};

<CallLogs locale={fr} />;

Formatting

Customize date and phone number formatting:

<CallLogs
  formatting={{
    defaultCountry: 'FR', // ISO 3166-1 alpha-2 country code
    dateLocale: 'fr-FR', // BCP 47 language tag
    use24HourTime: true, // 24-hour format
    showTimezone: false, // Hide timezone
  }}
/>

Error Handling

The SDK provides callbacks for handling errors gracefully:

<CallLogs
  onLoaderStart={({ elementTagName }) => {
    console.log(`Loading ${elementTagName}...`);
  }}
  onLoadError={({ error, elementTagName }) => {
    console.error(`Error in ${elementTagName}:`, error);
    // Show user-friendly error message or retry logic
  }}
/>

Provider Errors

If you forget to wrap your components in a DialstackComponentsProvider, you'll get a helpful error message:

Error: Could not find DialStack context; You need to wrap your app
in a <DialstackComponentsProvider> provider.
See https://docs.dialstack.ai/sdk/react for setup instructions.

Network Errors

Components automatically handle network errors and display error states. Use the onLoadError callback to implement custom error handling, retry logic, or error reporting.

Accessibility

All components are built with accessibility in mind:

  • ARIA Labels: Proper role, aria-label, and aria-live attributes
  • Keyboard Navigation: Full keyboard support (Tab, Enter, Space)
  • Focus Management: Visible focus rings via CSS variables
  • Screen Reader Support: Status announcements for loading/error states

API Reference

loadDialstackAndInitialize(options)

Initialize the DialStack SDK with your publishable key and session fetcher.

Parameters:

  • options.publishableKey (string, required): Your DialStack publishable key (starts with pk_live_ or pk_test_)
  • options.fetchClientSecret (function, required): Async function that fetches a client secret from your backend. Can return a string or { clientSecret, expiresAt }.
  • options.appearance (object, optional): Theming options
  • options.apiUrl (string, optional): Custom API endpoint URL

Returns: Promise<DialStackInstance>

DialstackComponentsProvider

React Context Provider that makes the DialStack instance and client secret available to child components.

Props:

  • dialstack (DialStackInstance, required): The DialStack instance from loadDialstackAndInitialize()
  • children (ReactNode, required): Child components

Authentication

The SDK uses account-scoped sessions for authentication. You must:

  1. Call your backend to create a session using the DialStack API:

    POST https://api.dialstack.ai/v1/account_sessions
    Authorization: Bearer sk_live_YOUR_SECRET_KEY
    DialStack-Account: acct_01h2xcejqtf2nbrexx3vqjhp41
    Content-Type: application/json
    
  2. Provide a fetchClientSecret callback when calling loadDialstackAndInitialize() that returns the client_secret from your backend.

Sessions expire after 1 hour. The SDK automatically refreshes sessions using the fetchClientSecret callback.

Security Note: Only server-side API keys can create sessions. Session tokens cannot be used to create new sessions, preventing unauthorized session extension.

Browser Compatibility

The SDK supports all modern browsers:

BrowserVersion
Chrome80+
Firefox75+
Safari13.1+
Edge80+

Requirements:

  • ES2015+ (ES6) support
  • Web Components v1 (Custom Elements, Shadow DOM)
  • Fetch API

Note: Internet Explorer is not supported.

Documentation

Full documentation is available at https://docs.dialstack.ai

Support

License

MIT - See LICENSE for details

版本与发布记录

@dialstack/sdk 共发布 21 个版本,首次发布于 2025/11/15;过去 12 个月发布了 21 个版本。

版本发布日期距今
2.1.0latest2026/08/103 个月前
2.0.02026/07/313 个月前
1.2.02026/06/234 个月前
1.1.02026/06/154 个月前
1.0.02026/06/144 个月前
0.2.2-alpha.13alpha2025/12/2410 个月前

关于 @dialstack/sdk 的常见问题

@dialstack/sdk 是什么?

Official JavaScript SDK for DialStack - Business Voice for Vertical SaaS注意:该包已被作者标记为弃用——@dialstack/sdk is no longer updated. Use @dialstack/sdk-js, @dialstack/sdk-react, @dialstack/sdk-webrtc, @dialstack/sdk-server or @dialstack/sdk-native: https://docs.dialstack.ai/sdks/installation

如何安装 @dialstack/sdk?

在项目目录运行 npm install @dialstack/sdk,或使用 pnpm add / yarn add / bun add。

@dialstack/sdk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dialstack/sdk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@dialstack/sdk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@dialstack/sdk 可以商用吗?

@dialstack/sdk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dialstack/sdk 的下载量有多少?

根据 npm 官方下载统计,@dialstack/sdk 在 2026/10/12 – 2026/11/10 这 30 天内被下载 6,845 次,日均约 228 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dialstack/sdk 还在维护吗?

最新版本 2.1.0 发布于 2026/08/10(3 个月前);至今共发布 21 个版本,其中过去 12 个月发布了 21 个;首次发布于 2025/11/15。作者已将其标记为弃用,新项目建议寻找替代方案。