@botpress/webchat 1.0.0 → 1.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/package.json +2 -1
- package/dist/vite.svg +0 -1
- package/index.html +0 -18
- package/public/vite.svg +0 -1
- package/src/App.tsx +0 -41
- package/src/Utils/colors.ts +0 -45
- package/src/Utils/eventEmitter.ts +0 -31
- package/src/Utils/index.ts +0 -2
- package/src/assets/check-circle-bold.svg +0 -5
- package/src/assets/chevron-up.svg +0 -3
- package/src/assets/file-05.svg +0 -6
- package/src/assets/globe-02.svg +0 -6
- package/src/assets/help-circle.svg +0 -3
- package/src/assets/info-circle.svg +0 -3
- package/src/assets/lock-01.svg +0 -4
- package/src/assets/mail-01.svg +0 -6
- package/src/assets/minus-circle.svg +0 -3
- package/src/assets/phone.svg +0 -6
- package/src/assets/send-03.svg +0 -4
- package/src/assets/share-04.svg +0 -5
- package/src/assets/slash-circle-01.svg +0 -3
- package/src/assets/x-circle-bold.svg +0 -5
- package/src/assets/x-close.svg +0 -3
- package/src/assets/x.svg +0 -3
- package/src/client/MessagingClient.ts +0 -87
- package/src/client/adapters/Audio.ts +0 -10
- package/src/client/adapters/Card.ts +0 -104
- package/src/client/adapters/Carousel.ts +0 -11
- package/src/client/adapters/Choice.ts +0 -48
- package/src/client/adapters/Dropdown.ts +0 -39
- package/src/client/adapters/File.ts +0 -10
- package/src/client/adapters/Image.ts +0 -10
- package/src/client/adapters/Location.ts +0 -18
- package/src/client/adapters/Message.ts +0 -26
- package/src/client/adapters/Text.ts +0 -11
- package/src/client/adapters/Utils.ts +0 -11
- package/src/client/adapters/Video.ts +0 -10
- package/src/client/adapters/Voice.ts +0 -9
- package/src/client/adapters/index.ts +0 -12
- package/src/client/index.ts +0 -2
- package/src/components/Avatar.tsx +0 -22
- package/src/components/Block.tsx +0 -17
- package/src/components/Composer.tsx +0 -115
- package/src/components/Container.tsx +0 -17
- package/src/components/Header.tsx +0 -141
- package/src/components/LoadingIndicator.tsx +0 -15
- package/src/components/Message.tsx +0 -52
- package/src/components/MessageList.tsx +0 -75
- package/src/components/Modal.tsx +0 -49
- package/src/components/RestartConversation.tsx +0 -52
- package/src/components/Webchat.tsx +0 -68
- package/src/components/dev-tools/DevTools.tsx +0 -496
- package/src/components/dev-tools/configuration.tsx +0 -27
- package/src/components/dev-tools/helpers.ts +0 -21
- package/src/components/index.ts +0 -12
- package/src/components/renderers/Audio.tsx +0 -11
- package/src/components/renderers/Bubble.tsx +0 -12
- package/src/components/renderers/Button.tsx +0 -59
- package/src/components/renderers/Carousel.tsx +0 -51
- package/src/components/renderers/Column.tsx +0 -22
- package/src/components/renderers/Dropdown.tsx +0 -170
- package/src/components/renderers/File.tsx +0 -13
- package/src/components/renderers/Image.tsx +0 -63
- package/src/components/renderers/Location.tsx +0 -16
- package/src/components/renderers/Row.tsx +0 -22
- package/src/components/renderers/Text.tsx +0 -32
- package/src/components/renderers/Video.tsx +0 -11
- package/src/components/renderers/index.ts +0 -28
- package/src/contexts/ComposerContext.ts +0 -16
- package/src/contexts/MessageContext.ts +0 -16
- package/src/contexts/ModalContext.ts +0 -19
- package/src/contexts/WebchatContext.ts +0 -61
- package/src/contexts/index.ts +0 -4
- package/src/hooks/index.ts +0 -3
- package/src/hooks/useImageSize.ts +0 -30
- package/src/hooks/useRefresh.ts +0 -33
- package/src/hooks/useWebchatStore.ts +0 -45
- package/src/index.css +0 -18
- package/src/index.ts +0 -3
- package/src/main.tsx +0 -33
- package/src/providers/ModalProvider.tsx +0 -35
- package/src/providers/WebchatProvider.tsx +0 -107
- package/src/providers/index.ts +0 -2
- package/src/schemas/index.ts +0 -1
- package/src/schemas/theme.ts +0 -188
- package/src/services/clipboard.ts +0 -8
- package/src/services/images.ts +0 -39
- package/src/services/index.ts +0 -3
- package/src/services/toast.tsx +0 -71
- package/src/themes/dawn.ts +0 -277
- package/src/themes/duskTheme.ts +0 -349
- package/src/themes/eggplant.ts +0 -353
- package/src/themes/galaxy.ts +0 -323
- package/src/themes/index.ts +0 -6
- package/src/themes/midnight.ts +0 -276
- package/src/themes/prism.ts +0 -349
- package/src/twind.config.ts +0 -31
- package/src/types/block-type.ts +0 -150
- package/src/types/image.ts +0 -10
- package/src/types/index.ts +0 -2
- package/src/vite-env.d.ts +0 -1
- package/tailwind.config.js +0 -0
- package/tsconfig.json +0 -30
- package/tsconfig.node.json +0 -10
- package/vite.config.ts +0 -31
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { Container } from './Container'
|
|
2
|
-
import { Header } from './Header'
|
|
3
|
-
import { RestartConversation } from './RestartConversation'
|
|
4
|
-
import { MessageList } from './MessageList'
|
|
5
|
-
import { Composer, ComposerButton, ComposerInput } from './Composer'
|
|
6
|
-
import { DocumentTextIcon, EnvelopeIcon, GlobeAltIcon, LockClosedIcon, PhoneIcon } from '@heroicons/react/24/solid'
|
|
7
|
-
import { Configuration } from '../contexts'
|
|
8
|
-
|
|
9
|
-
type Props = {
|
|
10
|
-
configuration: Configuration
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export const Webchat = ({ configuration }: Props) => {
|
|
14
|
-
return (
|
|
15
|
-
<Container>
|
|
16
|
-
<Header>
|
|
17
|
-
<Header.Content>
|
|
18
|
-
<Header.Avatar src={configuration.botAvatar}>{(configuration.botName || 'My Bot').slice(0, 2)}</Header.Avatar>
|
|
19
|
-
<Header.Title>{configuration.botName || 'My Bot'}</Header.Title>
|
|
20
|
-
<Header.Description>{configuration.botDescription}</Header.Description>
|
|
21
|
-
<Header.Actions>
|
|
22
|
-
<RestartConversation />
|
|
23
|
-
</Header.Actions>
|
|
24
|
-
</Header.Content>
|
|
25
|
-
<Header.ExpandedContent>
|
|
26
|
-
<Header.DescriptionItem
|
|
27
|
-
data-email=""
|
|
28
|
-
icon={EnvelopeIcon}
|
|
29
|
-
title={configuration.email?.title}
|
|
30
|
-
link={configuration.email?.link}
|
|
31
|
-
/>
|
|
32
|
-
|
|
33
|
-
<Header.DescriptionItem
|
|
34
|
-
data-phone=""
|
|
35
|
-
icon={PhoneIcon}
|
|
36
|
-
title={configuration.phone?.title}
|
|
37
|
-
link={configuration.phone?.link}
|
|
38
|
-
/>
|
|
39
|
-
|
|
40
|
-
<Header.DescriptionItem
|
|
41
|
-
data-website=""
|
|
42
|
-
link={configuration.website?.link}
|
|
43
|
-
icon={GlobeAltIcon}
|
|
44
|
-
title={configuration.website?.title}
|
|
45
|
-
/>
|
|
46
|
-
|
|
47
|
-
<Header.DescriptionItem
|
|
48
|
-
data-terms=""
|
|
49
|
-
link={configuration.termsOfService?.link}
|
|
50
|
-
icon={DocumentTextIcon}
|
|
51
|
-
title={configuration.termsOfService?.title}
|
|
52
|
-
/>
|
|
53
|
-
<Header.DescriptionItem
|
|
54
|
-
data-privacy=""
|
|
55
|
-
link={configuration.privacyPolicy?.link}
|
|
56
|
-
icon={LockClosedIcon}
|
|
57
|
-
title={configuration.privacyPolicy?.title}
|
|
58
|
-
/>
|
|
59
|
-
</Header.ExpandedContent>
|
|
60
|
-
</Header>
|
|
61
|
-
<MessageList />
|
|
62
|
-
<Composer>
|
|
63
|
-
<ComposerInput placeholder={configuration.composerPlaceholder || 'Type your message'} />
|
|
64
|
-
<ComposerButton />
|
|
65
|
-
</Composer>
|
|
66
|
-
</Container>
|
|
67
|
-
)
|
|
68
|
-
}
|
|
@@ -1,496 +0,0 @@
|
|
|
1
|
-
import { tx } from '@twind/core'
|
|
2
|
-
import { useState } from 'react'
|
|
3
|
-
import { HexColorPicker } from 'react-colorful'
|
|
4
|
-
import { z } from 'zod'
|
|
5
|
-
import { useWebchatContext } from '../../contexts'
|
|
6
|
-
import { ThemeSchema } from '../../schemas'
|
|
7
|
-
import { buildDawnTheme, buildMidnightTheme, duskTheme, eggplantTheme, galaxyTheme, prismTheme } from '../../themes'
|
|
8
|
-
import { MessageObject } from '../../types'
|
|
9
|
-
import { messageInBubble } from './helpers'
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
const messagesToSend: Record<string, MessageObject> = {
|
|
13
|
-
shortText: messageInBubble({
|
|
14
|
-
type: 'text',
|
|
15
|
-
text: 'Hello, World!',
|
|
16
|
-
}),
|
|
17
|
-
md: messageInBubble({
|
|
18
|
-
type: 'text',
|
|
19
|
-
//text example using multiple markdown features
|
|
20
|
-
text: '# Hello, World! \n ## This is a markdown message. \n\n ### Heading 3 \n\n You can use **bold**, _italic_, and `code`.\n\nYou can also use [links](https://www.google.com) and\n\n- Lists\n- Like\n- This\n\nAnd even\n1. Numbered\n2. Lists\n3. Like\n4. This',
|
|
21
|
-
}),
|
|
22
|
-
longText: messageInBubble({
|
|
23
|
-
type: 'text',
|
|
24
|
-
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec euismod, nisl eget tempor aliquam, nisl nisl aliquet nisl, eget aliquam nisl nisl eget nisl. Donec euismod, nisl eget tempor aliquam, nisl nisl aliquet nisl, eget aliquam nisl nisl eget nisl.',
|
|
25
|
-
}),
|
|
26
|
-
portraitImage: {
|
|
27
|
-
direction: 'incoming',
|
|
28
|
-
sender: {
|
|
29
|
-
name: 'Bot',
|
|
30
|
-
},
|
|
31
|
-
timestamp: new Date(),
|
|
32
|
-
|
|
33
|
-
block: {
|
|
34
|
-
type: 'image',
|
|
35
|
-
url: `https://picsum.photos/1080/1920`,
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
landscapeImage: {
|
|
39
|
-
direction: 'incoming',
|
|
40
|
-
sender: {
|
|
41
|
-
name: 'Bot',
|
|
42
|
-
},
|
|
43
|
-
timestamp: new Date(),
|
|
44
|
-
block: {
|
|
45
|
-
type: 'image',
|
|
46
|
-
url: `https://picsum.photos/1920/1080`,
|
|
47
|
-
},
|
|
48
|
-
},
|
|
49
|
-
squareImage: {
|
|
50
|
-
direction: 'incoming',
|
|
51
|
-
sender: {
|
|
52
|
-
name: 'Bot',
|
|
53
|
-
},
|
|
54
|
-
timestamp: new Date(),
|
|
55
|
-
|
|
56
|
-
block: {
|
|
57
|
-
type: 'image',
|
|
58
|
-
url: `https://picsum.photos/1920/1920`,
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
video: {
|
|
62
|
-
direction: 'incoming',
|
|
63
|
-
sender: {
|
|
64
|
-
name: 'Bot',
|
|
65
|
-
},
|
|
66
|
-
timestamp: new Date(),
|
|
67
|
-
block: {
|
|
68
|
-
type: 'video',
|
|
69
|
-
url: 'https://spg-test-public-files.s3.us-east-1.amazonaws.com/sample-mp4-file-small.mp4',
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
audio: {
|
|
73
|
-
direction: 'incoming',
|
|
74
|
-
sender: {
|
|
75
|
-
name: 'Bot',
|
|
76
|
-
},
|
|
77
|
-
timestamp: new Date(),
|
|
78
|
-
block: {
|
|
79
|
-
type: 'audio',
|
|
80
|
-
url: 'https://soundbible.com/mp3/MP5_SMG-GunGuru-703432894.mp3',
|
|
81
|
-
},
|
|
82
|
-
},
|
|
83
|
-
button: {
|
|
84
|
-
direction: 'incoming',
|
|
85
|
-
sender: {
|
|
86
|
-
name: 'Bot',
|
|
87
|
-
},
|
|
88
|
-
timestamp: new Date(),
|
|
89
|
-
block: {
|
|
90
|
-
type: 'button',
|
|
91
|
-
variant: 'action',
|
|
92
|
-
text: 'Button',
|
|
93
|
-
buttonValue: 'Hello, World!',
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
disableInput: {
|
|
97
|
-
direction: 'incoming',
|
|
98
|
-
disableInput: true,
|
|
99
|
-
sender: {
|
|
100
|
-
name: 'Bot',
|
|
101
|
-
},
|
|
102
|
-
timestamp: new Date(),
|
|
103
|
-
block: {
|
|
104
|
-
type: 'button',
|
|
105
|
-
variant: 'action',
|
|
106
|
-
text: 'Button',
|
|
107
|
-
buttonValue: 'Hello, World!',
|
|
108
|
-
},
|
|
109
|
-
},
|
|
110
|
-
location: {
|
|
111
|
-
direction: 'incoming',
|
|
112
|
-
sender: {
|
|
113
|
-
name: 'Bot',
|
|
114
|
-
},
|
|
115
|
-
timestamp: new Date(),
|
|
116
|
-
block: {
|
|
117
|
-
type: 'location',
|
|
118
|
-
latitude: 40.7128,
|
|
119
|
-
longitude: -74.006,
|
|
120
|
-
title: 'New York, NY',
|
|
121
|
-
},
|
|
122
|
-
},
|
|
123
|
-
rowOfButtons: {
|
|
124
|
-
direction: 'incoming',
|
|
125
|
-
sender: {
|
|
126
|
-
name: 'Bot',
|
|
127
|
-
},
|
|
128
|
-
timestamp: new Date(),
|
|
129
|
-
block: {
|
|
130
|
-
type: 'row',
|
|
131
|
-
blocks: [
|
|
132
|
-
{
|
|
133
|
-
type: 'button',
|
|
134
|
-
variant: 'action',
|
|
135
|
-
groupId: 'group1',
|
|
136
|
-
text: 'Button 1',
|
|
137
|
-
buttonValue: 'Button 1',
|
|
138
|
-
},
|
|
139
|
-
{
|
|
140
|
-
type: 'button',
|
|
141
|
-
variant: 'action',
|
|
142
|
-
groupId: 'group1',
|
|
143
|
-
text: 'Button 2',
|
|
144
|
-
buttonValue: 'Button 2',
|
|
145
|
-
},
|
|
146
|
-
{
|
|
147
|
-
type: 'button',
|
|
148
|
-
variant: 'link',
|
|
149
|
-
groupId: 'group1',
|
|
150
|
-
text: 'Button 3',
|
|
151
|
-
buttonValue: 'Button 3',
|
|
152
|
-
},
|
|
153
|
-
],
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
card: messageInBubble({
|
|
157
|
-
type: 'column',
|
|
158
|
-
horizontalAlignment: 'center',
|
|
159
|
-
blocks: [
|
|
160
|
-
{
|
|
161
|
-
type: 'image',
|
|
162
|
-
url: 'https://picsum.photos/700/350',
|
|
163
|
-
},
|
|
164
|
-
{
|
|
165
|
-
type: 'text',
|
|
166
|
-
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
|
|
167
|
-
},
|
|
168
|
-
{
|
|
169
|
-
type: 'row',
|
|
170
|
-
horizontalAlignment: 'center',
|
|
171
|
-
blocks: [
|
|
172
|
-
{
|
|
173
|
-
type: 'button',
|
|
174
|
-
text: 'Button A',
|
|
175
|
-
variant: 'action',
|
|
176
|
-
groupId: 'group1',
|
|
177
|
-
buttonValue: 'Button A',
|
|
178
|
-
},
|
|
179
|
-
{
|
|
180
|
-
type: 'button',
|
|
181
|
-
text: 'Button B',
|
|
182
|
-
variant: 'action',
|
|
183
|
-
groupId: 'group1',
|
|
184
|
-
buttonValue: 'Button B',
|
|
185
|
-
},
|
|
186
|
-
{
|
|
187
|
-
type: 'button',
|
|
188
|
-
text: 'Button C',
|
|
189
|
-
variant: 'link',
|
|
190
|
-
groupId: 'group1',
|
|
191
|
-
buttonValue: 'Button C',
|
|
192
|
-
},
|
|
193
|
-
],
|
|
194
|
-
},
|
|
195
|
-
],
|
|
196
|
-
}),
|
|
197
|
-
carousel: {
|
|
198
|
-
direction: 'incoming',
|
|
199
|
-
sender: {
|
|
200
|
-
name: 'Bot',
|
|
201
|
-
},
|
|
202
|
-
timestamp: new Date(),
|
|
203
|
-
block: {
|
|
204
|
-
type: 'carousel',
|
|
205
|
-
blocks: [
|
|
206
|
-
{
|
|
207
|
-
type: 'image',
|
|
208
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
209
|
-
},
|
|
210
|
-
{
|
|
211
|
-
type: 'image',
|
|
212
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
213
|
-
},
|
|
214
|
-
{
|
|
215
|
-
type: 'image',
|
|
216
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
type: 'image',
|
|
220
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
221
|
-
},
|
|
222
|
-
{
|
|
223
|
-
type: 'image',
|
|
224
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
225
|
-
},
|
|
226
|
-
{
|
|
227
|
-
type: 'image',
|
|
228
|
-
url: `https://picsum.photos/${Math.floor(Math.random() * 1920)}/${Math.floor(Math.random() * 1920)}`,
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
type: 'column',
|
|
232
|
-
horizontalAlignment: 'center',
|
|
233
|
-
blocks: [
|
|
234
|
-
{
|
|
235
|
-
type: 'image',
|
|
236
|
-
url: 'https://picsum.photos/300/350',
|
|
237
|
-
},
|
|
238
|
-
{
|
|
239
|
-
type: 'text',
|
|
240
|
-
text: 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
|
|
241
|
-
},
|
|
242
|
-
{
|
|
243
|
-
type: 'row',
|
|
244
|
-
horizontalAlignment: 'center',
|
|
245
|
-
blocks: [
|
|
246
|
-
{
|
|
247
|
-
type: 'button',
|
|
248
|
-
text: 'Button A',
|
|
249
|
-
variant: 'action',
|
|
250
|
-
groupId: 'group1',
|
|
251
|
-
buttonValue: 'Button A',
|
|
252
|
-
},
|
|
253
|
-
{
|
|
254
|
-
type: 'button',
|
|
255
|
-
text: 'Button B',
|
|
256
|
-
variant: 'action',
|
|
257
|
-
groupId: 'group1',
|
|
258
|
-
buttonValue: 'Button B',
|
|
259
|
-
},
|
|
260
|
-
{
|
|
261
|
-
type: 'button',
|
|
262
|
-
text: 'Button C',
|
|
263
|
-
variant: 'link',
|
|
264
|
-
groupId: 'group1',
|
|
265
|
-
buttonValue: 'Button C',
|
|
266
|
-
},
|
|
267
|
-
{
|
|
268
|
-
type: 'button',
|
|
269
|
-
text: 'Button C',
|
|
270
|
-
variant: 'link',
|
|
271
|
-
groupId: 'group1',
|
|
272
|
-
buttonValue: 'Button C',
|
|
273
|
-
},
|
|
274
|
-
{
|
|
275
|
-
type: 'button',
|
|
276
|
-
text: 'Button C',
|
|
277
|
-
variant: 'link',
|
|
278
|
-
groupId: 'group1',
|
|
279
|
-
buttonValue: 'Button C',
|
|
280
|
-
},
|
|
281
|
-
{
|
|
282
|
-
type: 'button',
|
|
283
|
-
text: 'Button C',
|
|
284
|
-
variant: 'link',
|
|
285
|
-
groupId: 'group1',
|
|
286
|
-
buttonValue: 'Button C',
|
|
287
|
-
},
|
|
288
|
-
],
|
|
289
|
-
},
|
|
290
|
-
],
|
|
291
|
-
},
|
|
292
|
-
],
|
|
293
|
-
},
|
|
294
|
-
},
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const configSchema = z
|
|
298
|
-
.object({
|
|
299
|
-
composerPlaceholder: z.string().optional(),
|
|
300
|
-
botConversationDescription: z.string().optional(),
|
|
301
|
-
botId: z.string().optional(),
|
|
302
|
-
hostUrl: z.string().optional(),
|
|
303
|
-
messagingUrl: z.string(),
|
|
304
|
-
clientId: z.string(),
|
|
305
|
-
lazySocket: z.boolean().optional(),
|
|
306
|
-
botName: z.string().optional(),
|
|
307
|
-
avatarUrl: z.string().optional(),
|
|
308
|
-
phoneNumber: z
|
|
309
|
-
.string()
|
|
310
|
-
.optional()
|
|
311
|
-
.transform((val) => {
|
|
312
|
-
if (val) {
|
|
313
|
-
return { title: val }
|
|
314
|
-
}
|
|
315
|
-
}),
|
|
316
|
-
termsConditions: z
|
|
317
|
-
.string()
|
|
318
|
-
.optional()
|
|
319
|
-
.transform((val) => {
|
|
320
|
-
if (val) {
|
|
321
|
-
return { title: val, link: val }
|
|
322
|
-
}
|
|
323
|
-
}),
|
|
324
|
-
privacyPolicy: z
|
|
325
|
-
.string()
|
|
326
|
-
.optional()
|
|
327
|
-
.transform((val) => {
|
|
328
|
-
if (val) {
|
|
329
|
-
return { title: val, link: val }
|
|
330
|
-
}
|
|
331
|
-
}),
|
|
332
|
-
emailAddress: z
|
|
333
|
-
.string()
|
|
334
|
-
.optional()
|
|
335
|
-
.transform((val) => {
|
|
336
|
-
if (val) {
|
|
337
|
-
return { title: val }
|
|
338
|
-
}
|
|
339
|
-
}),
|
|
340
|
-
website: z
|
|
341
|
-
.string()
|
|
342
|
-
.optional()
|
|
343
|
-
.transform((val) => {
|
|
344
|
-
if (val) {
|
|
345
|
-
return { title: val, link: val }
|
|
346
|
-
}
|
|
347
|
-
}),
|
|
348
|
-
showPoweredBy: z.boolean().optional(),
|
|
349
|
-
})
|
|
350
|
-
.transform((val) => {
|
|
351
|
-
console.log(val)
|
|
352
|
-
return {
|
|
353
|
-
...val,
|
|
354
|
-
...(val.avatarUrl && { botAvatar: val.avatarUrl }),
|
|
355
|
-
...(val.botConversationDescription && { botDescription: val.botConversationDescription }),
|
|
356
|
-
...(val.emailAddress && { email: val.emailAddress }),
|
|
357
|
-
...(val.termsConditions && { termsOfService: val.termsConditions }),
|
|
358
|
-
...(val.phoneNumber && { phone: val.phoneNumber }),
|
|
359
|
-
}
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
function parseWebchatScript(script: string) {
|
|
363
|
-
const scriptRegex = /<script\b[^>]*>([\s\S]*?)<\/script>/gm
|
|
364
|
-
const initRegex = /window\.botpressWebChat\.init\(([\s\S]*?)\);/gm
|
|
365
|
-
|
|
366
|
-
let match
|
|
367
|
-
let initObject
|
|
368
|
-
|
|
369
|
-
while ((match = scriptRegex.exec(script)) !== null) {
|
|
370
|
-
const scriptContent = match[1]
|
|
371
|
-
const initMatch = initRegex.exec(scriptContent)
|
|
372
|
-
|
|
373
|
-
if (initMatch !== null) {
|
|
374
|
-
initObject = JSON.parse(initMatch[1])
|
|
375
|
-
break
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
const config = configSchema.parse(initObject)
|
|
380
|
-
|
|
381
|
-
return config
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
export const DevTools = () => {
|
|
385
|
-
const [newMessageDirection, setNewMessageDirection] = useState<MessageObject['direction']>('incoming')
|
|
386
|
-
const { setTheme: setStyles, setConfiguration } = useWebchatContext()
|
|
387
|
-
const [currentTheme, setCurrentTheme] = useState<'dawn' | 'midnight' | 'prism' | 'galaxy' | 'eggplant' | 'dusk'>(
|
|
388
|
-
'prism'
|
|
389
|
-
)
|
|
390
|
-
const [color, setColor] = useState<string>()
|
|
391
|
-
|
|
392
|
-
const [webchatScript, setWebchatScript] = useState('')
|
|
393
|
-
|
|
394
|
-
const themes = {
|
|
395
|
-
dawn: buildDawnTheme('#dc2626'),
|
|
396
|
-
midnight: buildMidnightTheme('#dc2626'),
|
|
397
|
-
prism: prismTheme,
|
|
398
|
-
galaxy: galaxyTheme,
|
|
399
|
-
eggplant: eggplantTheme,
|
|
400
|
-
dusk: duskTheme,
|
|
401
|
-
} as const
|
|
402
|
-
|
|
403
|
-
return (
|
|
404
|
-
<div>
|
|
405
|
-
<div className="item flex flex-wrap gap-4 rounded-lg border border-gray-200 bg-gray-50 p-2">
|
|
406
|
-
<div className="flex w-fit items-center">
|
|
407
|
-
<input
|
|
408
|
-
type="checkbox"
|
|
409
|
-
className="mr-2 h-4 w-4 rounded"
|
|
410
|
-
checked={newMessageDirection === 'outgoing'}
|
|
411
|
-
onChange={() => setNewMessageDirection((direction) => (direction === 'incoming' ? 'outgoing' : 'incoming'))}
|
|
412
|
-
/>
|
|
413
|
-
<label className="font-medium capitalize text-gray-700">{newMessageDirection}</label>
|
|
414
|
-
</div>
|
|
415
|
-
<div className="flex w-fit items-center">
|
|
416
|
-
<label className="font-medium capitalize text-gray-700">Theme</label>
|
|
417
|
-
<select
|
|
418
|
-
className="ml-2 rounded-lg border border-gray-200 bg-gray-50 p-1 px-3 text-sm capitalize"
|
|
419
|
-
onChange={(e) => {
|
|
420
|
-
setStyles(ThemeSchema.parse(themes[e.target.value as keyof typeof themes]))
|
|
421
|
-
setCurrentTheme(e.target.value as keyof typeof themes)
|
|
422
|
-
}}
|
|
423
|
-
>
|
|
424
|
-
<option value="prism">Prism</option>
|
|
425
|
-
<option value="galaxy">Galaxy</option>
|
|
426
|
-
<option value="eggplant">Eggplant</option>
|
|
427
|
-
<option value="dusk">Dusk</option>
|
|
428
|
-
<option value="dawn">Dawn</option>
|
|
429
|
-
<option value="midnight">Midnight</option>
|
|
430
|
-
</select>
|
|
431
|
-
</div>
|
|
432
|
-
|
|
433
|
-
{/* {Object.entries(messagesToSend).map(([key, message]) => (
|
|
434
|
-
<button
|
|
435
|
-
key={key}
|
|
436
|
-
className={tx(' rounded-lg border p-1 px-3 text-sm capitalize', {
|
|
437
|
-
'border-gray-200 bg-white text-gray-800': newMessageDirection === 'incoming',
|
|
438
|
-
'border-blue-600 bg-blue-600 font-medium text-white': newMessageDirection === 'outgoing',
|
|
439
|
-
})}
|
|
440
|
-
onClick={() => client.addMessage({ ...message, direction: newMessageDirection })}
|
|
441
|
-
>
|
|
442
|
-
{splitCamelCase(key)}
|
|
443
|
-
</button>
|
|
444
|
-
))}
|
|
445
|
-
<button className="rounded-lg p-1 px-3 font-medium text-red-600" onClick={() => client.clearMessages()}>
|
|
446
|
-
Clear
|
|
447
|
-
</button> */}
|
|
448
|
-
</div>
|
|
449
|
-
<div className="flex items-center gap-6">
|
|
450
|
-
<textarea
|
|
451
|
-
value={webchatScript}
|
|
452
|
-
onChange={(e) => setWebchatScript(e.target.value)}
|
|
453
|
-
className="grow whitespace-pre-wrap border border-gray-300 bg-gray-50 font-mono"
|
|
454
|
-
/>
|
|
455
|
-
<button
|
|
456
|
-
onClick={() => {
|
|
457
|
-
try {
|
|
458
|
-
const config = parseWebchatScript(webchatScript)
|
|
459
|
-
console.log(config)
|
|
460
|
-
// setClient(new WebchatClient({ clientId: config.clientId, url: config.messagingUrl }))
|
|
461
|
-
setConfiguration((prevConfig) => {
|
|
462
|
-
return {
|
|
463
|
-
...prevConfig,
|
|
464
|
-
...config,
|
|
465
|
-
}
|
|
466
|
-
})
|
|
467
|
-
} catch (err) {
|
|
468
|
-
console.error(err)
|
|
469
|
-
}
|
|
470
|
-
}}
|
|
471
|
-
className={tx(
|
|
472
|
-
'h-fit rounded-lg border p-1 px-3 py-2 text-sm capitalize hover:bg-gray-100 active:bg-gray-200',
|
|
473
|
-
{
|
|
474
|
-
'border-gray-200 bg-white text-gray-800': newMessageDirection === 'incoming',
|
|
475
|
-
'border-blue-600 bg-blue-600 font-medium text-white': newMessageDirection === 'outgoing',
|
|
476
|
-
}
|
|
477
|
-
)}
|
|
478
|
-
>
|
|
479
|
-
Update webchat
|
|
480
|
-
</button>
|
|
481
|
-
</div>
|
|
482
|
-
{(currentTheme === 'dawn' || currentTheme === 'midnight') && (
|
|
483
|
-
<div className="flex w-fit flex-wrap items-center gap-4">
|
|
484
|
-
<HexColorPicker
|
|
485
|
-
color={color}
|
|
486
|
-
onChange={(color) => {
|
|
487
|
-
setColor(color)
|
|
488
|
-
currentTheme === 'dawn' && setStyles(buildDawnTheme(color))
|
|
489
|
-
currentTheme === 'midnight' && setStyles(buildMidnightTheme(color))
|
|
490
|
-
}}
|
|
491
|
-
/>
|
|
492
|
-
</div>
|
|
493
|
-
)}
|
|
494
|
-
</div>
|
|
495
|
-
)
|
|
496
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { Configuration } from '../../contexts'
|
|
2
|
-
|
|
3
|
-
export const defaultConfiguration: Configuration = {
|
|
4
|
-
composerPlaceholder: 'What would you like to know?',
|
|
5
|
-
botName: 'Customer service',
|
|
6
|
-
botAvatar: 'https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50',
|
|
7
|
-
botDescription:
|
|
8
|
-
'Welcome to webchat this is some description talking about what it is. This might be a bit longer when expanded.',
|
|
9
|
-
email: {
|
|
10
|
-
title: 'christophe.sirois@botpress.com',
|
|
11
|
-
},
|
|
12
|
-
phone: {
|
|
13
|
-
title: '581-456-8631',
|
|
14
|
-
},
|
|
15
|
-
website: {
|
|
16
|
-
title: 'https://botpress.com',
|
|
17
|
-
link: 'https://botpress.com',
|
|
18
|
-
},
|
|
19
|
-
termsOfService: {
|
|
20
|
-
title: 'Terms of service',
|
|
21
|
-
link: 'https://botpress.com/terms',
|
|
22
|
-
},
|
|
23
|
-
privacyPolicy: {
|
|
24
|
-
title: 'Privacy policy',
|
|
25
|
-
link: 'https://botpress.com/privacy',
|
|
26
|
-
},
|
|
27
|
-
} as const
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { BlockObject, MessageObject } from '../../types'
|
|
2
|
-
|
|
3
|
-
type Direction = 'incoming' | 'outgoing' | 'system'
|
|
4
|
-
|
|
5
|
-
export function messageInBubble(block: BlockObject, direction?: Direction): MessageObject {
|
|
6
|
-
return {
|
|
7
|
-
direction: direction || 'incoming',
|
|
8
|
-
sender: {
|
|
9
|
-
name: 'Bot',
|
|
10
|
-
},
|
|
11
|
-
timestamp: new Date(),
|
|
12
|
-
block: {
|
|
13
|
-
type: 'bubble',
|
|
14
|
-
block,
|
|
15
|
-
},
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export function splitCamelCase(text: string): string {
|
|
20
|
-
return text.replace(/([a-z])([A-Z])/g, '$1 $2')
|
|
21
|
-
}
|
package/src/components/index.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export * from './Avatar'
|
|
2
|
-
export * from './Block'
|
|
3
|
-
export * from './Composer'
|
|
4
|
-
export * from './Container'
|
|
5
|
-
export * from './Header'
|
|
6
|
-
export * from './LoadingIndicator'
|
|
7
|
-
export * from './Message'
|
|
8
|
-
export * from './MessageList'
|
|
9
|
-
export * from './Modal'
|
|
10
|
-
export * from './RestartConversation'
|
|
11
|
-
export * from './Webchat'
|
|
12
|
-
export * from './renderers'
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import { forwardRef } from 'react'
|
|
2
|
-
import { CommonBlockProps, AudioBlock } from '../../types'
|
|
3
|
-
|
|
4
|
-
type Props = CommonBlockProps & AudioBlock
|
|
5
|
-
export const Audio = forwardRef<HTMLAudioElement, Props>(({ url, type, styles, ...props }, ref) => {
|
|
6
|
-
return (
|
|
7
|
-
<div>
|
|
8
|
-
<audio {...props} controls src={url} {...styles?.[type]} ref={ref} />
|
|
9
|
-
</div>
|
|
10
|
-
)
|
|
11
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ComponentProps, forwardRef } from 'react'
|
|
2
|
-
import { BubbleBlock, CommonBlockProps } from '../../types'
|
|
3
|
-
import { Block } from '../Block'
|
|
4
|
-
|
|
5
|
-
type Props = CommonBlockProps & BubbleBlock & ComponentProps<'div'>
|
|
6
|
-
export const Bubble = forwardRef<HTMLDivElement, Props>(({ block, styles, type, ...props }, ref) => {
|
|
7
|
-
return (
|
|
8
|
-
<div {...props} {...styles?.[type]} ref={ref}>
|
|
9
|
-
<Block styles={styles} block={block} />
|
|
10
|
-
</div>
|
|
11
|
-
)
|
|
12
|
-
})
|