@botpress/webchat 4.0.0 → 4.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
 
2
- > @botpress/webchat@4.0.0 build /home/runner/work/genisys/genisys/packages/webchat-components
2
+ > @botpress/webchat@4.0.2 build /home/runner/work/genisys/genisys/packages/webchat-components
3
3
  > vite build
4
4
 
5
5
  vite v5.4.8 building for production...
@@ -14,8 +14,8 @@ computing gzip size...
14
14
  [vite:dts] Start rollup declaration files...
15
15
  Analysis will use the bundled TypeScript version 5.4.2
16
16
  *** The target project appears to use TypeScript 5.6.2 which is newer than the bundled compiler engine; consider upgrading API Extractor.
17
- [vite:dts] Declaration files built in 18818ms.
17
+ [vite:dts] Declaration files built in 19670ms.
18
18
 
19
19
  dist/style.css  49.55 kB │ gzip: 8.84 kB
20
20
  dist/index.umd.cjs 443.57 kB │ gzip: 145.67 kB
21
- ✓ built in 23.18s
21
+ ✓ built in 24.49s
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@botpress/webchat",
3
- "version": "4.0.0",
3
+ "version": "4.0.2",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.umd.cjs",
@@ -52,7 +52,7 @@
52
52
  "uuid": "^9.0.1",
53
53
  "zustand": "^4.4.1",
54
54
  "@botpress/webchat-client": "0.3.1",
55
- "@bpinternal/shared": "1.0.3"
55
+ "@bpinternal/shared": "1.1.0"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": "^18.0.0 || ^19.0.0",
@@ -97,8 +97,8 @@
97
97
  "vite-plugin-libcss": "^1.1.1",
98
98
  "vite-plugin-svgr": "^4.2.0",
99
99
  "vitest": "1.6.0",
100
- "@repo/eslint-config": "0.0.0",
101
- "@repo/typescript-config": "0.0.0"
100
+ "@repo/typescript-config": "0.0.0",
101
+ "@repo/eslint-config": "0.0.0"
102
102
  },
103
103
  "scripts": {
104
104
  "check:type": "tsc --noEmit",
package/readme.md CHANGED
@@ -1,56 +1,215 @@
1
- # Webchat
1
+ # @botpress/webchat
2
+
3
+ A fully customizable React library that lets you seamlessly integrate Botpress Webchat into your React applications.
4
+
5
+ ## Features
6
+
7
+ - 🎨 **Fully Customizable** - Style and configure every aspect of the webchat experience
8
+ - 🔌 **Easy Integration** - Simple installation and setup process
9
+ - 🛠️ **Flexible Architecture** - Use pre-built components or build custom implementations
10
+ - 📱 **Responsive** - Works seamlessly across desktop and mobile devices
2
11
 
3
12
  ## Installation
4
13
 
5
14
  ```bash
6
- npm install @botpress/webchat # for npm
7
- yarn add @botpress/webchat # for yarn
8
- pnpm add @botpress/webchat # for pnpm
15
+ # npm
16
+ npm install @botpress/webchat
17
+
18
+ # yarn
19
+ yarn add @botpress/webchat
20
+
21
+ # pnpm
22
+ pnpm install @botpress/webchat
9
23
  ```
10
24
 
11
- ## Usage
25
+ ## Requirements
12
26
 
13
- ```tsx
14
- import { useEffect, useState } from 'react'
15
- import { getClient, Webchat, WebchatProvider, WebchatClient, Configuration } from '@botpress/webchat'
27
+ - React 18 or higher
28
+ - A published Botpress bot
29
+ - Your bot's Client ID
16
30
 
17
- // also known as the webhookId; You can copy it from the Botpress Dashboard
18
- const clientId = '$CLIENT_ID'
31
+ ## Quick Start
19
32
 
20
- const userData = { foo: 'bar' }
21
- const configuration: Configuration = {
22
- botAvatar: 'https://upload.wikimedia.org/wikipedia/commons/9/91/T-bone-raw-MCB.jpg',
23
- botDescription: 'Hello, world!',
24
- botName: 'Hello Bot',
25
- }
33
+ ### Get Your Client ID
34
+
35
+ 1. Open your bot in the [Botpress Dashboard](https://app.botpress.cloud)
36
+ 2. Navigate to **Webchat** in the left sidebar
37
+ 3. Open the **Features** sub menu
38
+ 4. Go to the **Advanced Settings** tab
39
+ 5. Copy your **Client ID**
40
+
41
+ ### Basic Implementation
42
+
43
+ ```jsx
44
+ import { Fab, Webchat } from '@botpress/webchat'
45
+ import { useState } from 'react'
26
46
 
27
47
  function App() {
28
- const [client, setClient] = useState<WebchatClient | null>(null)
48
+ const [isWebchatOpen, setIsWebchatOpen] = useState(false)
29
49
 
30
- useEffect(() => {
31
- const client = getClient({ clientId })
32
- setClient(client)
50
+ return (
51
+ <>
52
+ <Webchat
53
+ clientId="YOUR_CLIENT_ID"
54
+ style={{
55
+ width: '400px',
56
+ height: '600px',
57
+ display: isWebchatOpen ? 'flex' : 'none',
58
+ position: 'fixed',
59
+ bottom: '90px',
60
+ right: '20px',
61
+ }}
62
+ />
63
+ <Fab
64
+ onClick={() => setIsWebchatOpen(!isWebchatOpen)}
65
+ style={{
66
+ position: 'fixed',
67
+ bottom: '20px',
68
+ right: '20px',
69
+ width: '64px',
70
+ height: '64px',
71
+ }}
72
+ />
73
+ </>
74
+ )
75
+ }
76
+ ```
77
+
78
+ ## Advanced Usage
79
+
80
+ ### Custom Webchat Implementation
33
81
 
34
- // You can listen on events sent by the Webchat backend like this:
35
- client.on('*', (ev) => {
36
- console.log('Event:', ev)
82
+ For more control over the webchat experience, build it manually using individual components:
37
83
 
38
- // You can also call the Webchat backend API like this:
39
- client.getUser().then((user) => {
40
- console.log('User:', user)
41
- })
42
- })
43
- }, [])
84
+ ```jsx
85
+ import { Container, Header, MessageList, Composer, useWebchat, Fab } from '@botpress/webchat'
86
+ import { useState, useMemo } from 'react'
44
87
 
45
- if (!client) {
46
- return <div>Loading...</div>
88
+ function App() {
89
+ const [isWebchatOpen, setIsWebchatOpen] = useState(false)
90
+ const { client, messages, isTyping, user, clientState, newConversation } = useWebchat({
91
+ clientId: 'YOUR_CLIENT_ID',
92
+ })
93
+
94
+ const config = {
95
+ botName: 'SupportBot',
96
+ botAvatar: 'https://example.com/avatar.png',
97
+ botDescription: 'Your virtual assistant',
47
98
  }
99
+
100
+ const enrichedMessages = useMemo(
101
+ () =>
102
+ messages.map((message) => {
103
+ const direction = message.authorId === user?.userId ? 'outgoing' : 'incoming'
104
+ return {
105
+ ...message,
106
+ direction,
107
+ sender:
108
+ direction === 'outgoing'
109
+ ? { name: user?.name ?? 'You', avatar: user?.pictureUrl }
110
+ : { name: config.botName, avatar: config.botAvatar },
111
+ }
112
+ }),
113
+ [messages, user, config]
114
+ )
115
+
48
116
  return (
49
- <WebchatProvider client={client} configuration={configuration} userData={userData}>
50
- <Webchat />
51
- </WebchatProvider>
117
+ <>
118
+ <Container
119
+ connected={clientState !== 'disconnected'}
120
+ style={{
121
+ width: '500px',
122
+ height: '800px',
123
+ display: isWebchatOpen ? 'flex' : 'none',
124
+ position: 'fixed',
125
+ bottom: '90px',
126
+ right: '20px',
127
+ }}
128
+ >
129
+ <Header
130
+ closeWindow={() => setIsWebchatOpen(false)}
131
+ restartConversation={newConversation}
132
+ configuration={{
133
+ botName: config.botName,
134
+ botAvatar: config.botAvatar,
135
+ botDescription: config.botDescription,
136
+ }}
137
+ />
138
+ <MessageList
139
+ botName={config.botName}
140
+ botDescription={config.botDescription}
141
+ isTyping={isTyping}
142
+ messages={enrichedMessages}
143
+ sendMessage={client?.sendMessage}
144
+ />
145
+ <Composer
146
+ connected={clientState !== 'disconnected'}
147
+ sendMessage={client?.sendMessage}
148
+ uploadFile={client?.uploadFile}
149
+ composerPlaceholder="Type a message..."
150
+ />
151
+ </Container>
152
+ <Fab
153
+ onClick={() => setIsWebchatOpen(!isWebchatOpen)}
154
+ style={{
155
+ position: 'fixed',
156
+ bottom: '20px',
157
+ right: '20px',
158
+ }}
159
+ />
160
+ </>
52
161
  )
53
162
  }
163
+ ```
164
+
165
+ ## Configuration
166
+
167
+ ### Using the Webchat Component
168
+
169
+ Pass configuration through the `configuration` prop:
170
+
171
+ ```jsx
172
+ <Webchat
173
+ clientId="YOUR_CLIENT_ID"
174
+ configuration={{
175
+ botName: 'My Bot',
176
+ botAvatar: 'https://example.com/avatar.png',
177
+ botDescription: 'Here to help!',
178
+ }}
179
+ />
180
+ ```
181
+
182
+ ### Custom Styling
183
+
184
+ Use the `StylesheetProvider` component for custom themes:
54
185
 
55
- export default App
186
+ ```jsx
187
+ import { StylesheetProvider } from '@botpress/webchat'
188
+ ;<StylesheetProvider>{/* Your webchat components */}</StylesheetProvider>
56
189
  ```
190
+
191
+ ## Components
192
+
193
+ - **Webchat** - All-in-one webchat component
194
+ - **Container** - Webchat container wrapper
195
+ - **Header** - Customizable header with bot info
196
+ - **MessageList** - Message display area
197
+ - **Composer** - Message input and file upload
198
+ - **Fab** - Floating action button
199
+ - **StylesheetProvider** - Custom styling provider
200
+ - **useWebchat** - Hook for webchat state and methods
201
+
202
+ ## Documentation
203
+
204
+ For detailed documentation, examples, and API reference, visit:
205
+
206
+ **[Botpress Webchat React Library Documentation](https://www.botpress.com/docs/webchat/react-library/get-started)**
207
+
208
+ ## Support
209
+
210
+ - 📖 [Documentation](https://www.botpress.com/docs)
211
+ - 💬 [Discord Community](https://discord.com/invite/botpress)
212
+
213
+ ## License
214
+
215
+ This library is part of the Botpress ecosystem. See the [Botpress repository](https://github.com/botpress/botpress) for license information.