@botpress/webchat

中文文档
5.5.8发布于 2026/10/17MITTypeScriptESM + CJS近 30 天下载 2.5万

A fully customizable React library that lets you seamlessly integrate Botpress Webchat into your React applications.

原始使用文档
文档目录15 节
  1. Features
  2. Installation
  3. Requirements
  4. Quick Start
  5. Get Your Client ID
  6. Basic Implementation
  7. Advanced Usage
  8. Custom Webchat Implementation
  9. Configuration
  10. Using the Webchat Component
  11. Custom Styling
  12. Components
  13. Documentation
  14. Support
  15. License

@botpress/webchat

A fully customizable React library that lets you seamlessly integrate Botpress Webchat into your React applications.

Features

  • 🎨 Fully Customizable - Style and configure every aspect of the webchat experience
  • 🔌 Easy Integration - Simple installation and setup process
  • 🛠️ Flexible Architecture - Use pre-built components or build custom implementations
  • 📱 Responsive - Works seamlessly across desktop and mobile devices

Installation

# npm
npm install @botpress/webchat

# yarn
yarn add @botpress/webchat

# pnpm
pnpm install @botpress/webchat

Requirements

  • React 18 or higher
  • A published Botpress bot
  • Your bot's Client ID

Quick Start

Get Your Client ID

  1. Open your bot in the Botpress Dashboard
  2. Navigate to Webchat in the left sidebar
  3. Open the Features sub menu
  4. Go to the Advanced Settings tab
  5. Copy your Client ID

Basic Implementation

import { Fab, Webchat } from '@botpress/webchat'
import { useState } from 'react'

function App() {
  const [isWebchatOpen, setIsWebchatOpen] = useState(false)

  return (
    <>
      <Webchat
        clientId="YOUR_CLIENT_ID"
        style={{
          width: '400px',
          height: '600px',
          display: isWebchatOpen ? 'flex' : 'none',
          position: 'fixed',
          bottom: '90px',
          right: '20px',
        }}
      />
      <Fab
        onClick={() => setIsWebchatOpen(!isWebchatOpen)}
        style={{
          position: 'fixed',
          bottom: '20px',
          right: '20px',
          width: '64px',
          height: '64px',
        }}
      />
    </>
  )
}

Advanced Usage

Custom Webchat Implementation

For more control over the webchat experience, build it manually using individual components:

import { Container, Header, MessageList, Composer, useWebchat, Fab } from '@botpress/webchat'
import { useState, useMemo } from 'react'

function App() {
  const [isWebchatOpen, setIsWebchatOpen] = useState(false)
  const { client, messages, isTyping, user, clientState, newConversation } = useWebchat({
    clientId: 'YOUR_CLIENT_ID',
  })

  const config = {
    botName: 'SupportBot',
    botAvatar: 'https://example.com/avatar.png',
    botDescription: 'Your virtual assistant',
  }

  const enrichedMessages = useMemo(
    () =>
      messages.map((message) => {
        const direction = message.authorId === user?.userId ? 'outgoing' : 'incoming'
        return {
          ...message,
          direction,
          sender:
            direction === 'outgoing'
              ? { name: user?.name ?? 'You', avatar: user?.pictureUrl }
              : { name: config.botName, avatar: config.botAvatar },
        }
      }),
    [messages, user, config]
  )

  return (
    <>
      <Container
        connected={clientState !== 'disconnected'}
        style={{
          width: '500px',
          height: '800px',
          display: isWebchatOpen ? 'flex' : 'none',
          position: 'fixed',
          bottom: '90px',
          right: '20px',
        }}
      >
        <Header
          closeWindow={() => setIsWebchatOpen(false)}
          restartConversation={newConversation}
          configuration={{
            botName: config.botName,
            botAvatar: config.botAvatar,
            botDescription: config.botDescription,
          }}
        />
        <MessageList
          botName={config.botName}
          botDescription={config.botDescription}
          isTyping={isTyping}
          messages={enrichedMessages}
          sendMessage={client?.sendMessage}
        />
        <Composer
          connected={clientState !== 'disconnected'}
          sendMessage={client?.sendMessage}
          uploadFile={client?.uploadFile}
          composerPlaceholder="Type a message..."
        />
      </Container>
      <Fab
        onClick={() => setIsWebchatOpen(!isWebchatOpen)}
        style={{
          position: 'fixed',
          bottom: '20px',
          right: '20px',
        }}
      />
    </>
  )
}

Configuration

Using the Webchat Component

Pass configuration through the configuration prop:

<Webchat
  clientId="YOUR_CLIENT_ID"
  configuration={{
    botName: 'My Bot',
    botAvatar: 'https://example.com/avatar.png',
    botDescription: 'Here to help!',
  }}
/>

Custom Styling

Use the StylesheetProvider component for custom themes:

import { StylesheetProvider } from '@botpress/webchat'
;<StylesheetProvider />
{
  /* Your webchat components */
}

Components

  • Webchat - All-in-one webchat component
  • Container - Webchat container wrapper
  • Header - Customizable header with bot info
  • MessageList - Message display area
  • Composer - Message input and file upload
  • Fab - Floating action button
  • StylesheetProvider - Custom styling provider
  • useWebchat - Hook for webchat state and methods

Documentation

For detailed documentation, examples, and API reference, visit:

Botpress Webchat React Library Documentation

Support

License

This library is part of the Botpress ecosystem. See the Botpress repository for license information.

版本与发布记录

@botpress/webchat 共发布 168 个版本,首次发布于 2021/11/11;过去 12 个月发布了 29 个版本。

版本发布日期距今
5.5.8latest2026/10/1722 天前
5.5.72026/10/1523 天前
5.5.52026/10/071 个月前
5.5.32026/09/101 个月前
5.5.12026/07/243 个月前
5.3.22026/06/194 个月前

关于 @botpress/webchat 的常见问题

@botpress/webchat 是什么?

A fully customizable React library that lets you seamlessly integrate Botpress Webchat into your React applications.

如何安装 @botpress/webchat?

在项目目录运行 npm install @botpress/webchat,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:react(^18.0.0 || ^19.0.0)、react-dom(^18.0.0 || ^19.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@botpress/webchat 支持 TypeScript 吗?

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

@botpress/webchat 支持 ESM 还是 CommonJS?

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

@botpress/webchat 可以商用吗?

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

@botpress/webchat 的下载量有多少?

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

@botpress/webchat 还在维护吗?

最新版本 5.5.8 发布于 2026/10/17(22 天前);至今共发布 168 个版本,其中过去 12 个月发布了 29 个;首次发布于 2021/11/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。