@botpress/webchat 2.1.14 → 2.1.16
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/dist/index.js +1508 -1490
- package/dist/index.umd.cjs +34 -34
- package/package.json +1 -1
- package/readme.md +56 -0
package/package.json
CHANGED
package/readme.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# Webchat
|
|
2
|
+
|
|
3
|
+
## Installation
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npm install @botpress/webchat # for npm
|
|
7
|
+
yarn add @botpress/webchat # for yarn
|
|
8
|
+
pnpm add @botpress/webchat # for pnpm
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```tsx
|
|
14
|
+
import { useEffect, useState } from 'react'
|
|
15
|
+
import { getClient, Webchat, WebchatProvider, WebchatClient, Configuration } from '@botpress/webchat'
|
|
16
|
+
|
|
17
|
+
// also known as the webhookId; You can copy it from the Botpress Dashboard
|
|
18
|
+
const clientId = '$CLIENT_ID'
|
|
19
|
+
|
|
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
|
+
}
|
|
26
|
+
|
|
27
|
+
function App() {
|
|
28
|
+
const [client, setClient] = useState<WebchatClient | null>(null)
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
const client = getClient({ clientId })
|
|
32
|
+
setClient(client)
|
|
33
|
+
|
|
34
|
+
// You can listen on events sent by the Webchat backend like this:
|
|
35
|
+
client.on('*', (ev) => {
|
|
36
|
+
console.log('Event:', ev)
|
|
37
|
+
|
|
38
|
+
// You can also call the Webchat backend API like this:
|
|
39
|
+
client.getUser().then((user) => {
|
|
40
|
+
console.log('User:', user)
|
|
41
|
+
})
|
|
42
|
+
})
|
|
43
|
+
}, [])
|
|
44
|
+
|
|
45
|
+
if (!client) {
|
|
46
|
+
return <div>Loading...</div>
|
|
47
|
+
}
|
|
48
|
+
return (
|
|
49
|
+
<WebchatProvider theme={{}} client={client} configuration={configuration} userData={userData}>
|
|
50
|
+
<Webchat />
|
|
51
|
+
</WebchatProvider>
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default App
|
|
56
|
+
```
|