@botpress/webchat 4.0.1 → 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.
- package/.turbo/turbo-build.log +5 -5
- package/package.json +3 -3
- package/readme.md +194 -35
package/.turbo/turbo-build.log
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
|
|
2
|
-
> @botpress/webchat@4.0.
|
|
2
|
+
> @botpress/webchat@4.0.2 build /home/runner/work/genisys/genisys/packages/webchat-components
|
|
3
3
|
> vite build
|
|
4
4
|
|
|
5
5
|
[36mvite v5.4.8 [32mbuilding for production...[36m[39m
|
|
@@ -9,13 +9,13 @@ rendering chunks...
|
|
|
9
9
|
|
|
10
10
|
[vite:dts] Start generate declaration files...
|
|
11
11
|
computing gzip size...
|
|
12
|
+
[2mdist/[22m[35mstyle.css [39m[1m[2m 49.55 kB[22m[1m[22m[2m │ gzip: 8.84 kB[22m
|
|
13
|
+
[2mdist/[22m[36mindex.js [39m[1m[33m666.14 kB[39m[22m[2m │ gzip: 180.07 kB[22m
|
|
12
14
|
[vite:dts] Start rollup declaration files...
|
|
13
15
|
Analysis will use the bundled TypeScript version 5.4.2
|
|
14
16
|
*** The target project appears to use TypeScript 5.6.2 which is newer than the bundled compiler engine; consider upgrading API Extractor.
|
|
15
|
-
|
|
16
|
-
[2mdist/[22m[36mindex.js [39m[1m[33m666.14 kB[39m[22m[2m │ gzip: 180.07 kB[22m
|
|
17
|
-
[vite:dts] Declaration files built in 20920ms.
|
|
17
|
+
[vite:dts] Declaration files built in 19670ms.
|
|
18
18
|
|
|
19
19
|
[2mdist/[22m[35mstyle.css [39m[1m[2m 49.55 kB[22m[1m[22m[2m │ gzip: 8.84 kB[22m
|
|
20
20
|
[2mdist/[22m[36mindex.umd.cjs [39m[1m[2m443.57 kB[22m[1m[22m[2m │ gzip: 145.67 kB[22m
|
|
21
|
-
[32m✓ built in
|
|
21
|
+
[32m✓ built in 24.49s[39m
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botpress/webchat",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/index.umd.cjs",
|
|
@@ -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/
|
|
101
|
-
"@repo/
|
|
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
|
-
#
|
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
-
##
|
|
25
|
+
## Requirements
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
27
|
+
- React 18 or higher
|
|
28
|
+
- A published Botpress bot
|
|
29
|
+
- Your bot's Client ID
|
|
16
30
|
|
|
17
|
-
|
|
18
|
-
const clientId = '$CLIENT_ID'
|
|
31
|
+
## Quick Start
|
|
19
32
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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 [
|
|
48
|
+
const [isWebchatOpen, setIsWebchatOpen] = useState(false)
|
|
29
49
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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
|
-
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
46
|
-
|
|
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
|
-
|
|
50
|
-
<
|
|
51
|
-
|
|
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
|
-
|
|
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.
|