Skip to content

Commit f150c55

Browse files
committed
updated widget
- now uses the ccat-api package - added new parameters - fixed css
1 parent 4699d71 commit f150c55

32 files changed

+1020
-831
lines changed

README.md

+24-14
Original file line numberDiff line numberDiff line change
@@ -30,24 +30,29 @@ And then you can import the widget (a parent div with fixed size is suggested):
3030

3131
The available attributes are:
3232

33-
| Attribute | Required | Param Type | Default value | Description |
34-
|-------------|----------|------------|---------------|---------------------------------------------|
35-
| url | true | String | | The URL to use to communicate with the Cat. |
36-
| api | true | String | | The API key for the Cat. |
37-
| dark | false | Boolean | `false` | `true` if the chat have to use the dark mode. `false` if not. |
38-
| primary | false | String | `#F3977B` | The color to use to stylize the chat. |
39-
| secure | false | Boolean | `false` | `true` if the chat have to use the dark mode. `false` if not. |
40-
| timeout | false | Number | `10000` | The delay (in milliseconds) to wait before trying again to connect. |
41-
| callback | false | String | `''` | The name of the function (declared globally) to call before passing the message to the cat. |
42-
| files | false | String[] | `["text/plain", "text/markdown", "application/pdf"]` | The accepted content types when uploading a file (must be supported by the cat). |
43-
| defaults | false | String[] | `Check stores/useMessages.ts line 14` | The default messages to show before starting the conversation with the cat. |
44-
| features | false | String[] | `['record', 'web', 'file', 'reset']` | The features that the user can use. |
33+
| Attribute | Required | Type | Default value | Description |
34+
|:-----------:|:--------:|:--------:|:-------------:|:-------------------------------------------:|
35+
| url | true | String | | The URL to use to communicate with the CCat. |
36+
| auth | true | String | | The authentication key to use for the CCat's endpoints. |
37+
| port | false | String | | The port to use in combination with the `url` to communicate with the CCat. |
38+
| dark | false | Boolean | `false` | `true` if the chat have to use the dark mode. `false` if not. |
39+
| primary | false | String | `#F3977B` | The color to use to stylize the chat. |
40+
| secure | false | Boolean | `false` | `true` if the widget should use the secure protocol (https/wss). `false` if not. |
41+
| timeout | false | Number | `10000` | The amount of time (in milliseconds) to wait before requests generate an error. |
42+
| showWhy | false | Boolean | `true` | `true` if the chat have to show the WHY button in the CCat response. `false` if not. |
43+
| wsPath | false | String | `ws` | The path to use when connecting to the WebSocket. |
44+
| wsDelay | false | Number | `2500` | The delay (in milliseconds) to wait before trying again to connect to the WebSocket. |
45+
| wsRetries | false | Number | `3` | The amount of retries (in milliseconds) to do when trying to reconnect to the WebSocket. |
46+
| callback | false | String | `''` | The name of the function (declared globally) to call before passing the message to the cat. |
47+
| files | false | String[] | `["text/plain", "text/markdown", "application/pdf"]` | The accepted content types when uploading a file (must be supported by the cat). |
48+
| defaults | false | String[] | `Check stores/useMessages.ts line 14` | The default messages to show before starting the conversation with the cat. |
49+
| features | false | String[] | `['record', 'web', 'file', 'reset', 'memory']` | The features that the user can use. |
4550

4651
An example could be:
4752

4853
```html
4954
<div class="w-96 h-96 m-auto">
50-
<cheshire-cat-chat id="cat-chat" api="none" url="localhost:1865" callback="myCallback" dark />
55+
<cheshire-cat-chat id="cat-chat" auth="meow" url="localhost" port="1865" callback="myCallback" dark />
5156
</div>
5257
<script>
5358
const catChat = document.querySelector("#cat-chat")
@@ -69,7 +74,7 @@ You also have access to some events:
6974

7075
```html
7176
<div class="w-96 h-96 m-auto">
72-
<cheshire-cat-chat id="cat-chat" api="none" url="localhost:1865" />
77+
<cheshire-cat-chat id="cat-chat" auth="meow" url="localhost" port="1865" />
7378
</div>
7479
<script>
7580
const catChat = document.querySelector("#cat-chat")
@@ -85,6 +90,10 @@ catChat.addEventListener("upload", ({ detail }) => {
8590
catChat.addEventListener("notification", ({ detail }) => {
8691
console.log("Notification:", detail.text)
8792
})
93+
94+
catChat.addEventListener("failed", () => {
95+
console.log("Failed to connect WebSocket after 3 retries.")
96+
})
8897
</script>
8998
```
9099

@@ -95,3 +104,4 @@ The available events are:
95104
| message | `Message` | Return the message every time a new one is dispatched. |
96105
| upload | `File` / `string` | Return the uploaded content every time a new one is dispatched. It can be either a file object or a url. |
97106
| notification | `Notification` | Return the notification every time a new one is dispatched. |
107+
| failed | | Fired when the WebSocket fails to connect after `x` retries. |

components.d.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,26 @@
33
// @ts-nocheck
44
// Generated by unplugin-vue-components
55
// Read more: https://github.com/vuejs/core/pull/3399
6-
import '@vue/runtime-core'
7-
86
export {}
97

10-
declare module '@vue/runtime-core' {
8+
declare module 'vue' {
119
export interface GlobalComponents {
1210
Dialog: typeof import('@headlessui/vue')['Dialog']
1311
DialogPanel: typeof import('@headlessui/vue')['DialogPanel']
1412
DialogTitle: typeof import('@headlessui/vue')['DialogTitle']
1513
HeroiconsArrowDown20Solid: typeof import('~icons/heroicons/arrow-down20-solid')['default']
14+
HeroiconsBoltSolid: typeof import('~icons/heroicons/bolt-solid')['default']
1615
HeroiconsDocumentTextSolid: typeof import('~icons/heroicons/document-text-solid')['default']
1716
HeroiconsGlobeAlt: typeof import('~icons/heroicons/globe-alt')['default']
1817
HeroiconsMicrophoneSolid: typeof import('~icons/heroicons/microphone-solid')['default']
1918
HeroiconsPaperAirplaneSolid: typeof import('~icons/heroicons/paper-airplane-solid')['default']
20-
HeroiconsPaperClip20Solid: typeof import('~icons/heroicons/paper-clip20-solid')['default']
2119
HeroiconsTrashSolid: typeof import('~icons/heroicons/trash-solid')['default']
2220
HeroiconsXMark20Solid: typeof import('~icons/heroicons/x-mark20-solid')['default']
21+
MemorySelect: typeof import('./src/components/MemorySelect.vue')['default']
2322
MessageBox: typeof import('./src/components/MessageBox.vue')['default']
2423
ModalBox: typeof import('./src/components/ModalBox.vue')['default']
2524
NotificationStack: typeof import('./src/components/NotificationStack.vue')['default']
25+
PhBrainFill: typeof import('~icons/ph/brain-fill')['default']
2626
SidePanel: typeof import('./src/components/SidePanel.vue')['default']
2727
TransitionChild: typeof import('@headlessui/vue')['TransitionChild']
2828
TransitionRoot: typeof import('@headlessui/vue')['TransitionRoot']

example/index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
flex-direction: column;
1212
padding: 0.5rem;
1313
height: 100vh;
14+
max-height: 100vh;
15+
min-height: 100vh;
1416
}
1517
.chat-title {
1618
font-size: 3rem;
@@ -28,23 +30,24 @@
2830
<h1 class="chat-title">Cat ready to hack!</h1>
2931
<cheshire-cat-chat
3032
id="cat-chat"
31-
api="none"
33+
auth="meow"
3234
callback="myCallback"
3335
timeout="5000"
34-
url="localhost:1865"
36+
url="localhost"
37+
port="1865"
3538
primary="#00ff00"
3639
/>
3740

3841
<script>
3942
const catChat = document.querySelector("#cat-chat")
4043

41-
catChat.defaults = ['Ehy, ciao!', 'Come va?', 'Chi sei?', 'Mostrami cosa sai fare', 'Dammi il cinque!']
44+
catChat.defaults = ['Is everything ok?', 'Who are you?', 'What time is it?', 'What\'s up?', 'Hello Cheshire Cat!']
4245
catChat.features = ['record', 'web', 'file', 'reset']
4346
catChat.files = ['text/plain', 'application/pdf']
4447

4548
function myCallback(message) {
4649
console.log("Callback called.")
47-
return `Talk in italian. ${message}`
50+
return `Let's have a chat. ${message}`
4851
}
4952

5053
catChat.addEventListener("message", ({ detail }) => {
@@ -58,6 +61,10 @@ <h1 class="chat-title">Cat ready to hack!</h1>
5861
catChat.addEventListener("notification", ({ detail }) => {
5962
console.log("Notification:", detail.text)
6063
})
64+
65+
catChat.addEventListener("failed", () => {
66+
console.log("Failed to connect WebSocket after 3 retries.")
67+
})
6168
</script>
6269
</body>
6370
</html>

example/widget.css

+11-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/widget.js

+87-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
/// <reference types="vite/client" />
2-
31
declare module 'vue3-webcomponent-wrapper';

index.html

+11-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
flex-direction: column;
1212
padding: 0.5rem;
1313
height: 100vh;
14+
max-height: 100vh;
15+
min-height: 100vh;
1416
}
1517
.chat-title {
1618
font-size: 3rem;
@@ -26,23 +28,24 @@
2628
<h1 class="chat-title">Cat ready to hack!</h1>
2729
<cheshire-cat-chat
2830
id="cat-chat"
29-
api="none"
31+
auth="meow"
3032
callback="myCallback"
3133
timeout="5000"
32-
url="localhost:1865"
34+
url="localhost"
35+
port="1865"
3336
primary="#00ff00"
3437
/>
3538
<script type="module" src="/src/main.ts"></script>
3639
<script>
3740
const catChat = document.querySelector("#cat-chat")
3841

39-
catChat.defaults = ['Ehy, ciao!', 'Come va?', 'Chi sei?', 'Mostrami cosa sai fare', 'Dammi il cinque!']
42+
catChat.defaults = ['Is everything ok?', 'Who are you?', 'What time is it?', 'What\'s up?', 'Hello Cheshire Cat!']
4043
catChat.features = ['record', 'web', 'file', 'reset']
4144
catChat.files = ['text/plain', 'application/pdf']
4245

4346
function myCallback(message) {
4447
console.log("Callback called.")
45-
return `Talk in italian. ${message}`
48+
return `Let's have a chat. ${message}`
4649
}
4750

4851
catChat.addEventListener("message", ({ detail }) => {
@@ -56,6 +59,10 @@ <h1 class="chat-title">Cat ready to hack!</h1>
5659
catChat.addEventListener("notification", ({ detail }) => {
5760
console.log("Notification:", detail.text)
5861
})
62+
63+
catChat.addEventListener("failed", () => {
64+
console.log("Failed to connect WebSocket after 3 retries.")
65+
})
5966
</script>
6067
</body>
6168
</html>

0 commit comments

Comments
 (0)