@buni.ai/chatbot-vue 1.0.0
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/README.md +356 -0
- package/dist/components/BuniChatWidget.vue.d.ts +62 -0
- package/dist/components/BuniChatWidget.vue.d.ts.map +1 -0
- package/dist/composables/useBuniChat.d.ts +27 -0
- package/dist/composables/useBuniChat.d.ts.map +1 -0
- package/dist/composables.d.ts +40 -0
- package/dist/composables.d.ts.map +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.esm.js +116 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +127 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
- package/src/components/BuniChatWidget.vue +42 -0
package/README.md
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
# @buni.ai/chatbot-vue
|
|
2
|
+
|
|
3
|
+
Vue 3 components and composables for seamless BuniAI chat widget integration.
|
|
4
|
+
|
|
5
|
+
[](https://badge.fury.io/js/@buni.ai%2Fchatbot-vue)
|
|
6
|
+
[](https://vuejs.org/)
|
|
7
|
+
[](https://www.typescriptlang.org/)
|
|
8
|
+
|
|
9
|
+
## 🚀 Quick Start
|
|
10
|
+
|
|
11
|
+
### Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm install @buni.ai/chatbot-vue
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
### Basic Usage
|
|
18
|
+
|
|
19
|
+
#### Option 1: Using the Composable (Recommended)
|
|
20
|
+
|
|
21
|
+
```vue
|
|
22
|
+
<template>
|
|
23
|
+
<div>
|
|
24
|
+
<h1>My Vue App</h1>
|
|
25
|
+
<button @click="toggle">
|
|
26
|
+
{{ isOpen ? 'Close Chat' : 'Open Chat' }}
|
|
27
|
+
</button>
|
|
28
|
+
|
|
29
|
+
<button @click="setCustomer">
|
|
30
|
+
Set Customer Data
|
|
31
|
+
</button>
|
|
32
|
+
|
|
33
|
+
<p>Unread messages: {{ unreadCount }}</p>
|
|
34
|
+
</div>
|
|
35
|
+
</template>
|
|
36
|
+
|
|
37
|
+
<script setup>
|
|
38
|
+
import { useBuniChat } from '@buni.ai/chatbot-vue';
|
|
39
|
+
|
|
40
|
+
const {
|
|
41
|
+
isOpen,
|
|
42
|
+
unreadCount,
|
|
43
|
+
toggle,
|
|
44
|
+
setCustomerData,
|
|
45
|
+
initialize
|
|
46
|
+
} = useBuniChat();
|
|
47
|
+
|
|
48
|
+
// Initialize the widget
|
|
49
|
+
await initialize({
|
|
50
|
+
token: 'your-widget-token',
|
|
51
|
+
config: {
|
|
52
|
+
position: 'bottom-right',
|
|
53
|
+
theme: 'light',
|
|
54
|
+
primaryColor: '#007bff'
|
|
55
|
+
},
|
|
56
|
+
onReady: () => {
|
|
57
|
+
console.log('✅ BuniAI widget loaded!');
|
|
58
|
+
},
|
|
59
|
+
onNewMessage: (data) => {
|
|
60
|
+
console.log('💬 New message:', data);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
const setCustomer = () => {
|
|
65
|
+
setCustomerData({
|
|
66
|
+
name: 'John Doe',
|
|
67
|
+
email: 'john@example.com',
|
|
68
|
+
userId: '12345'
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
</script>
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
#### Option 2: Using the Vue Component
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<template>
|
|
78
|
+
<div>
|
|
79
|
+
<h1>My Vue App</h1>
|
|
80
|
+
<BuniChatWidget
|
|
81
|
+
token="your-widget-token"
|
|
82
|
+
:config="{
|
|
83
|
+
position: 'bottom-right',
|
|
84
|
+
theme: 'light'
|
|
85
|
+
}"
|
|
86
|
+
@ready="onReady"
|
|
87
|
+
@new-message="onNewMessage"
|
|
88
|
+
/>
|
|
89
|
+
</div>
|
|
90
|
+
</template>
|
|
91
|
+
|
|
92
|
+
<script setup>
|
|
93
|
+
import { BuniChatWidget } from '@buni.ai/chatbot-vue';
|
|
94
|
+
|
|
95
|
+
const onReady = () => {
|
|
96
|
+
console.log('Widget is ready!');
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const onNewMessage = (data) => {
|
|
100
|
+
console.log('New message received:', data);
|
|
101
|
+
};
|
|
102
|
+
</script>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
#### Option 3: Using as a Vue Plugin
|
|
106
|
+
|
|
107
|
+
```javascript
|
|
108
|
+
// main.js
|
|
109
|
+
import { createApp } from 'vue';
|
|
110
|
+
import { BuniChatPlugin } from '@buni.ai/chatbot-vue';
|
|
111
|
+
import App from './App.vue';
|
|
112
|
+
|
|
113
|
+
const app = createApp(App);
|
|
114
|
+
app.use(BuniChatPlugin);
|
|
115
|
+
app.mount('#app');
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```vue
|
|
119
|
+
<!-- Now you can use the component globally -->
|
|
120
|
+
<template>
|
|
121
|
+
<div>
|
|
122
|
+
<BuniChatWidget token="your-widget-token" />
|
|
123
|
+
</div>
|
|
124
|
+
</template>
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
## 📖 API Reference
|
|
128
|
+
|
|
129
|
+
### `useBuniChat(options?)`
|
|
130
|
+
|
|
131
|
+
A Vue 3 composable for managing the BuniAI chat widget.
|
|
132
|
+
|
|
133
|
+
#### Parameters
|
|
134
|
+
|
|
135
|
+
| Parameter | Type | Description |
|
|
136
|
+
|-----------|------|-------------|
|
|
137
|
+
| `options` | `BuniChatOptions` | Optional initialization options |
|
|
138
|
+
|
|
139
|
+
#### Returns
|
|
140
|
+
|
|
141
|
+
```typescript
|
|
142
|
+
{
|
|
143
|
+
// Reactive state
|
|
144
|
+
state: BuniChatState,
|
|
145
|
+
isOpen: Ref<boolean>,
|
|
146
|
+
isLoaded: Ref<boolean>,
|
|
147
|
+
isMinimized: Ref<boolean>,
|
|
148
|
+
unreadCount: Ref<number>,
|
|
149
|
+
|
|
150
|
+
// Methods
|
|
151
|
+
initialize: (options: BuniChatOptions) => Promise<void>,
|
|
152
|
+
show: () => void,
|
|
153
|
+
hide: () => void,
|
|
154
|
+
toggle: () => void,
|
|
155
|
+
minimize: () => void,
|
|
156
|
+
maximize: () => void,
|
|
157
|
+
destroy: () => void,
|
|
158
|
+
|
|
159
|
+
// Data management
|
|
160
|
+
setCustomerData: (data: CustomerData) => void,
|
|
161
|
+
getCustomerData: () => CustomerData | null,
|
|
162
|
+
setSessionVariables: (variables: SessionVariables) => void,
|
|
163
|
+
getSessionVariables: () => SessionVariables | null,
|
|
164
|
+
|
|
165
|
+
// Chat actions
|
|
166
|
+
sendMessage: (message: string) => void,
|
|
167
|
+
clearChat: () => void
|
|
168
|
+
}
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
### `<BuniChatWidget>`
|
|
172
|
+
|
|
173
|
+
Vue component for rendering the chat widget.
|
|
174
|
+
|
|
175
|
+
#### Props
|
|
176
|
+
|
|
177
|
+
| Prop | Type | Default | Description |
|
|
178
|
+
|------|------|---------|-------------|
|
|
179
|
+
| `token` | `string` | - | Your BuniAI widget token (required) |
|
|
180
|
+
| `config` | `object` | `{}` | Widget configuration options |
|
|
181
|
+
| `onReady` | `function` | - | Callback when widget is ready |
|
|
182
|
+
| `onNewMessage` | `function` | - | Callback for new messages |
|
|
183
|
+
| `onVisibilityChanged` | `function` | - | Callback for visibility changes |
|
|
184
|
+
| `onError` | `function` | - | Callback for errors |
|
|
185
|
+
|
|
186
|
+
### Configuration Options
|
|
187
|
+
|
|
188
|
+
```typescript
|
|
189
|
+
interface BuniChatOptions {
|
|
190
|
+
token: string;
|
|
191
|
+
config?: {
|
|
192
|
+
position?: 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
|
|
193
|
+
theme?: 'light' | 'dark' | 'auto';
|
|
194
|
+
primaryColor?: string;
|
|
195
|
+
welcomeMessage?: string;
|
|
196
|
+
placeholder?: string;
|
|
197
|
+
showBranding?: boolean;
|
|
198
|
+
};
|
|
199
|
+
onReady?: (data: any) => void;
|
|
200
|
+
onNewMessage?: (data: any) => void;
|
|
201
|
+
onVisibilityChanged?: (data: any) => void;
|
|
202
|
+
onError?: (error: Error) => void;
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## 🎯 Advanced Examples
|
|
207
|
+
|
|
208
|
+
### Custom Customer Data Management
|
|
209
|
+
|
|
210
|
+
```vue
|
|
211
|
+
<script setup>
|
|
212
|
+
import { useBuniChat } from '@buni.ai/chatbot-vue';
|
|
213
|
+
import { ref, watch } from 'vue';
|
|
214
|
+
|
|
215
|
+
const user = ref({
|
|
216
|
+
name: '',
|
|
217
|
+
email: '',
|
|
218
|
+
plan: 'free'
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
const { initialize, setCustomerData } = useBuniChat();
|
|
222
|
+
|
|
223
|
+
// Initialize widget
|
|
224
|
+
await initialize({
|
|
225
|
+
token: 'your-token',
|
|
226
|
+
config: { position: 'bottom-right' }
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
// Watch for user changes and update widget
|
|
230
|
+
watch(user, (newUser) => {
|
|
231
|
+
setCustomerData({
|
|
232
|
+
name: newUser.name,
|
|
233
|
+
email: newUser.email,
|
|
234
|
+
customFields: {
|
|
235
|
+
plan: newUser.plan,
|
|
236
|
+
lastLogin: new Date().toISOString()
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
}, { deep: true });
|
|
240
|
+
</script>
|
|
241
|
+
```
|
|
242
|
+
|
|
243
|
+
### Event Handling
|
|
244
|
+
|
|
245
|
+
```vue
|
|
246
|
+
<script setup>
|
|
247
|
+
import { useBuniChat } from '@buni.ai/chatbot-vue';
|
|
248
|
+
import { ref } from 'vue';
|
|
249
|
+
|
|
250
|
+
const chatHistory = ref([]);
|
|
251
|
+
const notifications = ref([]);
|
|
252
|
+
|
|
253
|
+
const { initialize } = useBuniChat();
|
|
254
|
+
|
|
255
|
+
await initialize({
|
|
256
|
+
token: 'your-token',
|
|
257
|
+
onNewMessage: (data) => {
|
|
258
|
+
chatHistory.value.push(data);
|
|
259
|
+
|
|
260
|
+
if (data.isFromBot) {
|
|
261
|
+
notifications.value.push({
|
|
262
|
+
message: `New message: ${data.message}`,
|
|
263
|
+
timestamp: Date.now()
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
},
|
|
267
|
+
onVisibilityChanged: (data) => {
|
|
268
|
+
console.log('Chat visibility:', data.visibility);
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
</script>
|
|
272
|
+
```
|
|
273
|
+
|
|
274
|
+
### Integration with Pinia Store
|
|
275
|
+
|
|
276
|
+
```javascript
|
|
277
|
+
// stores/chat.js
|
|
278
|
+
import { defineStore } from 'pinia';
|
|
279
|
+
import { useBuniChat } from '@buni.ai/chatbot-vue';
|
|
280
|
+
|
|
281
|
+
export const useChatStore = defineStore('chat', () => {
|
|
282
|
+
const {
|
|
283
|
+
isOpen,
|
|
284
|
+
unreadCount,
|
|
285
|
+
initialize,
|
|
286
|
+
toggle,
|
|
287
|
+
setCustomerData
|
|
288
|
+
} = useBuniChat();
|
|
289
|
+
|
|
290
|
+
const initializeWidget = async (token) => {
|
|
291
|
+
await initialize({
|
|
292
|
+
token,
|
|
293
|
+
onNewMessage: (data) => {
|
|
294
|
+
// Handle new messages in store
|
|
295
|
+
console.log('Store received message:', data);
|
|
296
|
+
}
|
|
297
|
+
});
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
return {
|
|
301
|
+
isOpen,
|
|
302
|
+
unreadCount,
|
|
303
|
+
initializeWidget,
|
|
304
|
+
toggle,
|
|
305
|
+
setCustomerData
|
|
306
|
+
};
|
|
307
|
+
});
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
## 🔧 TypeScript Support
|
|
311
|
+
|
|
312
|
+
Full TypeScript support is included:
|
|
313
|
+
|
|
314
|
+
```typescript
|
|
315
|
+
import type {
|
|
316
|
+
BuniChatOptions,
|
|
317
|
+
CustomerData,
|
|
318
|
+
SessionVariables
|
|
319
|
+
} from '@buni.ai/chatbot-vue';
|
|
320
|
+
|
|
321
|
+
const options: BuniChatOptions = {
|
|
322
|
+
token: 'your-token',
|
|
323
|
+
config: {
|
|
324
|
+
position: 'bottom-right',
|
|
325
|
+
theme: 'light'
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
const customerData: CustomerData = {
|
|
330
|
+
name: 'John Doe',
|
|
331
|
+
email: 'john@example.com',
|
|
332
|
+
userId: '12345'
|
|
333
|
+
};
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
## 🤝 Requirements
|
|
337
|
+
|
|
338
|
+
- Vue 3.0+
|
|
339
|
+
- Modern browser with ES2020 support
|
|
340
|
+
|
|
341
|
+
## 📝 License
|
|
342
|
+
|
|
343
|
+
MIT © BuniAI
|
|
344
|
+
|
|
345
|
+
## 🔗 Links
|
|
346
|
+
|
|
347
|
+
- [Documentation](https://docs.buni.ai/widgets/vue)
|
|
348
|
+
- [GitHub Repository](https://github.com/buni-ai/chatbot-vue)
|
|
349
|
+
- [NPM Package](https://www.npmjs.com/package/@buni.ai/chatbot-vue)
|
|
350
|
+
- [BuniAI Platform](https://buni.ai)
|
|
351
|
+
|
|
352
|
+
## 🆘 Support
|
|
353
|
+
|
|
354
|
+
- [GitHub Issues](https://github.com/buni-ai/chatbot-vue/issues)
|
|
355
|
+
- [Discord Community](https://discord.gg/buni-ai)
|
|
356
|
+
- [Documentation](https://docs.buni.ai)
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
declare const _default: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
|
+
token: {
|
|
3
|
+
type: StringConstructor;
|
|
4
|
+
required: false;
|
|
5
|
+
default: string;
|
|
6
|
+
};
|
|
7
|
+
config: {
|
|
8
|
+
type: null;
|
|
9
|
+
required: false;
|
|
10
|
+
default: () => {};
|
|
11
|
+
};
|
|
12
|
+
onReady: {
|
|
13
|
+
type: null;
|
|
14
|
+
required: false;
|
|
15
|
+
};
|
|
16
|
+
onNewMessage: {
|
|
17
|
+
type: null;
|
|
18
|
+
required: false;
|
|
19
|
+
};
|
|
20
|
+
onVisibilityChanged: {
|
|
21
|
+
type: null;
|
|
22
|
+
required: false;
|
|
23
|
+
};
|
|
24
|
+
onError: {
|
|
25
|
+
type: null;
|
|
26
|
+
required: false;
|
|
27
|
+
};
|
|
28
|
+
}>, (_ctx: any, _cache: any) => import("vue").VNode<import("vue").RendererNode, import("vue").RendererElement, {
|
|
29
|
+
[key: string]: any;
|
|
30
|
+
}>, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
31
|
+
token: {
|
|
32
|
+
type: StringConstructor;
|
|
33
|
+
required: false;
|
|
34
|
+
default: string;
|
|
35
|
+
};
|
|
36
|
+
config: {
|
|
37
|
+
type: null;
|
|
38
|
+
required: false;
|
|
39
|
+
default: () => {};
|
|
40
|
+
};
|
|
41
|
+
onReady: {
|
|
42
|
+
type: null;
|
|
43
|
+
required: false;
|
|
44
|
+
};
|
|
45
|
+
onNewMessage: {
|
|
46
|
+
type: null;
|
|
47
|
+
required: false;
|
|
48
|
+
};
|
|
49
|
+
onVisibilityChanged: {
|
|
50
|
+
type: null;
|
|
51
|
+
required: false;
|
|
52
|
+
};
|
|
53
|
+
onError: {
|
|
54
|
+
type: null;
|
|
55
|
+
required: false;
|
|
56
|
+
};
|
|
57
|
+
}>> & Readonly<{}>, {
|
|
58
|
+
config: any;
|
|
59
|
+
token: string;
|
|
60
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
61
|
+
export default _default;
|
|
62
|
+
//# sourceMappingURL=BuniChatWidget.vue?vue&type=script&setup=true&lang.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BuniChatWidget.vue?vue&type=script&setup=true&lang.d.ts","sourceRoot":"","sources":["../../src/components/BuniChatWidget.vue?vue&type=script&setup=true&lang.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;WAoDc,GAAG,UAAS,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAjC7B,wBAsCE"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BuniChatOptions, CustomerData, SessionVariables } from '@buni.ai/chatbot-core';
|
|
2
|
+
export declare function useBuniChat(options?: BuniChatOptions): {
|
|
3
|
+
state: {
|
|
4
|
+
isOpen: boolean;
|
|
5
|
+
isLoaded: boolean;
|
|
6
|
+
isMinimized: boolean;
|
|
7
|
+
unreadCount: number;
|
|
8
|
+
};
|
|
9
|
+
isOpen: import("vue").Ref<boolean, boolean>;
|
|
10
|
+
isLoaded: import("vue").Ref<boolean, boolean>;
|
|
11
|
+
isMinimized: import("vue").Ref<boolean, boolean>;
|
|
12
|
+
unreadCount: import("vue").Ref<number, number>;
|
|
13
|
+
initialize: (initOptions: BuniChatOptions) => Promise<void>;
|
|
14
|
+
show: () => void | undefined;
|
|
15
|
+
hide: () => void | undefined;
|
|
16
|
+
toggle: () => void | undefined;
|
|
17
|
+
minimize: () => void | undefined;
|
|
18
|
+
maximize: () => void | undefined;
|
|
19
|
+
destroy: () => void;
|
|
20
|
+
setCustomerData: (data: CustomerData) => void | undefined;
|
|
21
|
+
getCustomerData: () => CustomerData | null | undefined;
|
|
22
|
+
setSessionVariables: (variables: SessionVariables) => void | undefined;
|
|
23
|
+
getSessionVariables: () => SessionVariables | null | undefined;
|
|
24
|
+
sendMessage: (message: string) => void | undefined;
|
|
25
|
+
clearChat: () => void | undefined;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=useBuniChat.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useBuniChat.d.ts","sourceRoot":"","sources":["../../src/composables/useBuniChat.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EAEf,YAAY,EACZ,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAI/B,wBAAgB,WAAW,CAAC,OAAO,CAAC,EAAE,eAAe;;;;;;;;;;;8BAQZ,eAAe;;;;;;;4BAyD5B,YAAY;;qCAEH,gBAAgB;;2BAI1B,MAAM;;EAGhC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
import { BuniChatWidget, BuniChatOptions, CustomerData, SessionVariables } from '@buni.ai/chatbot-core';
|
|
3
|
+
export declare function useBuniChat(options: BuniChatOptions): {
|
|
4
|
+
isOpen: import("vue").ComputedRef<boolean>;
|
|
5
|
+
isLoaded: import("vue").ComputedRef<boolean>;
|
|
6
|
+
isMinimized: import("vue").ComputedRef<boolean>;
|
|
7
|
+
unreadCount: import("vue").ComputedRef<number>;
|
|
8
|
+
isReady: Ref<boolean, boolean>;
|
|
9
|
+
show: () => void;
|
|
10
|
+
hide: () => void;
|
|
11
|
+
toggle: () => void;
|
|
12
|
+
minimize: () => void;
|
|
13
|
+
maximize: () => void;
|
|
14
|
+
setCustomerData: (data: CustomerData) => void;
|
|
15
|
+
setSessionVariables: (variables: SessionVariables) => void;
|
|
16
|
+
sendMessage: (message: string) => void;
|
|
17
|
+
widget: BuniChatWidget;
|
|
18
|
+
};
|
|
19
|
+
export declare function useWidgetEvents(widget: Ref<BuniChatWidget | null>): {
|
|
20
|
+
on: (event: string, callback: Function) => void;
|
|
21
|
+
off: (event: string, callback?: Function) => void;
|
|
22
|
+
};
|
|
23
|
+
export declare function useCustomerData(widget: Ref<BuniChatWidget | null>): {
|
|
24
|
+
customerData: Ref<{
|
|
25
|
+
name?: string | undefined;
|
|
26
|
+
email?: string | undefined;
|
|
27
|
+
phone?: string | undefined;
|
|
28
|
+
userId?: string | undefined;
|
|
29
|
+
customAttributes?: Record<string, any> | undefined;
|
|
30
|
+
} | null, CustomerData | {
|
|
31
|
+
name?: string | undefined;
|
|
32
|
+
email?: string | undefined;
|
|
33
|
+
phone?: string | undefined;
|
|
34
|
+
userId?: string | undefined;
|
|
35
|
+
customAttributes?: Record<string, any> | undefined;
|
|
36
|
+
} | null>;
|
|
37
|
+
setCustomerData: (data: CustomerData) => void;
|
|
38
|
+
getCustomerData: () => CustomerData | null;
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=composables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composables.d.ts","sourceRoot":"","sources":["../src/composables.ts"],"names":[],"mappings":"AAEA,OAAO,EAAyC,GAAG,EAAE,MAAM,KAAK,CAAC;AACjE,OAAO,EACL,cAAc,EACd,eAAe,EAEf,YAAY,EACZ,gBAAgB,EACjB,MAAM,uBAAuB,CAAC;AAG/B,wBAAgB,WAAW,CAAC,OAAO,EAAE,eAAe;;;;;;;;;;;4BAwCnB,YAAY;qCAIH,gBAAgB;2BAI1B,MAAM;;EAyBrC;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC;gBAC7C,MAAM,YAAY,QAAQ;iBAIzB,MAAM,aAAa,QAAQ;EAKhD;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,CAAC;;;;;;;;;;;;;;4BAGjC,YAAY;;EA4B5C"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { useBuniChat } from './composables/useBuniChat';
|
|
2
|
+
export declare const BuniChatWidget: import("vue").DefineComponent<{}, {}, any>;
|
|
3
|
+
import type { App } from 'vue';
|
|
4
|
+
export declare const BuniChatPlugin: {
|
|
5
|
+
install(app: App): void;
|
|
6
|
+
};
|
|
7
|
+
export type { BuniChatConfig, BuniChatOptions, BuniChatState, CustomerData, SessionVariables, BuniChatAPI, BuniChatEvents } from '@buni.ai/chatbot-core';
|
|
8
|
+
export { BuniChatWidget as BuniChatWidgetCore, createBuniChatWidget } from '@buni.ai/chatbot-core';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAIxD,eAAO,MAAM,cAAc,4CAA0B,CAAC;AAGtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B,eAAO,MAAM,cAAc;iBACZ,GAAG;CAGjB,CAAC;AAGF,YAAY,EACV,cAAc,EACd,eAAe,EACf,aAAa,EACb,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { reactive, ref, defineComponent, onMounted, onUnmounted, openBlock, createElementBlock } from 'vue';
|
|
2
|
+
import { BuniChatWidget as BuniChatWidget$1 } from '@buni.ai/chatbot-core';
|
|
3
|
+
export { BuniChatWidget as BuniChatWidgetCore, createBuniChatWidget } from '@buni.ai/chatbot-core';
|
|
4
|
+
|
|
5
|
+
let widgetInstance = null;
|
|
6
|
+
function useBuniChat(options) {
|
|
7
|
+
const state = reactive({
|
|
8
|
+
isOpen: false,
|
|
9
|
+
isLoaded: false,
|
|
10
|
+
isMinimized: false,
|
|
11
|
+
unreadCount: 0,
|
|
12
|
+
});
|
|
13
|
+
const initialize = async (initOptions) => {
|
|
14
|
+
if (!widgetInstance) {
|
|
15
|
+
widgetInstance = new BuniChatWidget$1();
|
|
16
|
+
// Set up event listeners to update reactive state
|
|
17
|
+
widgetInstance.on('visibility_changed', (data) => {
|
|
18
|
+
state.isOpen = data.visibility === 'visible';
|
|
19
|
+
});
|
|
20
|
+
widgetInstance.on('ready', () => {
|
|
21
|
+
state.isLoaded = true;
|
|
22
|
+
});
|
|
23
|
+
widgetInstance.on('minimized', () => {
|
|
24
|
+
state.isMinimized = true;
|
|
25
|
+
});
|
|
26
|
+
widgetInstance.on('maximized', () => {
|
|
27
|
+
state.isMinimized = false;
|
|
28
|
+
});
|
|
29
|
+
widgetInstance.on('new_message', (data) => {
|
|
30
|
+
if (data.isFromBot) {
|
|
31
|
+
state.unreadCount++;
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
await widgetInstance.initialize(initOptions);
|
|
36
|
+
};
|
|
37
|
+
// Auto-initialize if options provided
|
|
38
|
+
if (options) {
|
|
39
|
+
initialize(options);
|
|
40
|
+
}
|
|
41
|
+
return {
|
|
42
|
+
// Reactive state
|
|
43
|
+
state,
|
|
44
|
+
isOpen: ref(state.isOpen),
|
|
45
|
+
isLoaded: ref(state.isLoaded),
|
|
46
|
+
isMinimized: ref(state.isMinimized),
|
|
47
|
+
unreadCount: ref(state.unreadCount),
|
|
48
|
+
// Methods
|
|
49
|
+
initialize,
|
|
50
|
+
show: () => widgetInstance?.show(),
|
|
51
|
+
hide: () => widgetInstance?.hide(),
|
|
52
|
+
toggle: () => widgetInstance?.toggle(),
|
|
53
|
+
minimize: () => widgetInstance?.minimize(),
|
|
54
|
+
maximize: () => widgetInstance?.maximize(),
|
|
55
|
+
destroy: () => {
|
|
56
|
+
widgetInstance?.destroy();
|
|
57
|
+
widgetInstance = null;
|
|
58
|
+
},
|
|
59
|
+
// Data management
|
|
60
|
+
setCustomerData: (data) => widgetInstance?.setCustomerData(data),
|
|
61
|
+
getCustomerData: () => widgetInstance?.getCustomerData(),
|
|
62
|
+
setSessionVariables: (variables) => widgetInstance?.setSessionVariables(variables),
|
|
63
|
+
getSessionVariables: () => widgetInstance?.getSessionVariables(),
|
|
64
|
+
// Chat actions
|
|
65
|
+
sendMessage: (message) => widgetInstance?.sendMessage(message),
|
|
66
|
+
clearChat: () => widgetInstance?.clearChat(),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const _hoisted_1 = { id: "buni-chat-widget-container" };
|
|
71
|
+
var script = /*@__PURE__*/ defineComponent({
|
|
72
|
+
__name: 'BuniChatWidget',
|
|
73
|
+
props: {
|
|
74
|
+
token: { type: String, required: false, default: '' },
|
|
75
|
+
config: { type: null, required: false, default: () => ({}) },
|
|
76
|
+
onReady: { type: null, required: false },
|
|
77
|
+
onNewMessage: { type: null, required: false },
|
|
78
|
+
onVisibilityChanged: { type: null, required: false },
|
|
79
|
+
onError: { type: null, required: false }
|
|
80
|
+
},
|
|
81
|
+
setup(__props) {
|
|
82
|
+
const props = __props;
|
|
83
|
+
const { initialize, destroy } = useBuniChat();
|
|
84
|
+
onMounted(async () => {
|
|
85
|
+
if (props.token) {
|
|
86
|
+
await initialize({
|
|
87
|
+
token: props.token,
|
|
88
|
+
config: props.config,
|
|
89
|
+
onReady: props.onReady,
|
|
90
|
+
onNewMessage: props.onNewMessage,
|
|
91
|
+
onVisibilityChanged: props.onVisibilityChanged,
|
|
92
|
+
onError: props.onError,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
onUnmounted(() => {
|
|
97
|
+
destroy();
|
|
98
|
+
});
|
|
99
|
+
return (_ctx, _cache) => {
|
|
100
|
+
return (openBlock(), createElementBlock("div", _hoisted_1));
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
script.__file = "src/components/BuniChatWidget.vue";
|
|
106
|
+
|
|
107
|
+
// Main exports for @buni.ai/chatbot-vue
|
|
108
|
+
const BuniChatWidget = script;
|
|
109
|
+
const BuniChatPlugin = {
|
|
110
|
+
install(app) {
|
|
111
|
+
app.component('BuniChatWidget', script);
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export { BuniChatPlugin, BuniChatWidget, useBuniChat };
|
|
116
|
+
//# sourceMappingURL=index.esm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.esm.js","sources":["../src/composables/useBuniChat.ts","../src/components/BuniChatWidget.vue","../src/index.ts"],"sourcesContent":["import { ref, reactive } from 'vue';\nimport { BuniChatWidget } from '@buni.ai/chatbot-core';\nimport type { \n BuniChatOptions, \n BuniChatState, \n CustomerData, \n SessionVariables \n} from '@buni.ai/chatbot-core';\n\nlet widgetInstance: BuniChatWidget | null = null;\n\nexport function useBuniChat(options?: BuniChatOptions) {\n const state = reactive<BuniChatState>({\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n });\n\n const initialize = async (initOptions: BuniChatOptions) => {\n if (!widgetInstance) {\n widgetInstance = new BuniChatWidget();\n \n // Set up event listeners to update reactive state\n widgetInstance.on('visibility_changed', (data: any) => {\n state.isOpen = data.visibility === 'visible';\n });\n \n widgetInstance.on('ready', () => {\n state.isLoaded = true;\n });\n \n widgetInstance.on('minimized', () => {\n state.isMinimized = true;\n });\n \n widgetInstance.on('maximized', () => {\n state.isMinimized = false;\n });\n \n widgetInstance.on('new_message', (data: any) => {\n if (data.isFromBot) {\n state.unreadCount++;\n }\n });\n }\n \n await widgetInstance.initialize(initOptions);\n };\n\n // Auto-initialize if options provided\n if (options) {\n initialize(options);\n }\n\n return {\n // Reactive state\n state,\n isOpen: ref(state.isOpen),\n isLoaded: ref(state.isLoaded),\n isMinimized: ref(state.isMinimized),\n unreadCount: ref(state.unreadCount),\n \n // Methods\n initialize,\n show: () => widgetInstance?.show(),\n hide: () => widgetInstance?.hide(),\n toggle: () => widgetInstance?.toggle(),\n minimize: () => widgetInstance?.minimize(),\n maximize: () => widgetInstance?.maximize(),\n destroy: () => {\n widgetInstance?.destroy();\n widgetInstance = null;\n },\n \n // Data management\n setCustomerData: (data: CustomerData) => widgetInstance?.setCustomerData(data),\n getCustomerData: () => widgetInstance?.getCustomerData(),\n setSessionVariables: (variables: SessionVariables) => widgetInstance?.setSessionVariables(variables),\n getSessionVariables: () => widgetInstance?.getSessionVariables(),\n \n // Chat actions\n sendMessage: (message: string) => widgetInstance?.sendMessage(message),\n clearChat: () => widgetInstance?.clearChat(),\n };\n}","<template>\n <div id=\"buni-chat-widget-container\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { onMounted, onUnmounted } from 'vue';\nimport { useBuniChat } from '../composables/useBuniChat';\nimport type { BuniChatOptions } from '@buni.ai/chatbot-core';\n\ninterface Props {\n token?: string;\n config?: BuniChatOptions['config'];\n onReady?: BuniChatOptions['onReady'];\n onNewMessage?: BuniChatOptions['onNewMessage'];\n onVisibilityChanged?: BuniChatOptions['onVisibilityChanged'];\n onError?: BuniChatOptions['onError'];\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n token: '',\n config: () => ({})\n});\n\nconst { initialize, destroy } = useBuniChat();\n\nonMounted(async () => {\n if (props.token) {\n await initialize({\n token: props.token,\n config: props.config,\n onReady: props.onReady,\n onNewMessage: props.onNewMessage,\n onVisibilityChanged: props.onVisibilityChanged,\n onError: props.onError,\n });\n }\n});\n\nonUnmounted(() => {\n destroy();\n});\n</script>","// Main exports for @buni.ai/chatbot-vue\n\nexport { useBuniChat } from './composables/useBuniChat';\n\n// Export Vue component\nimport BuniChatWidgetComponent from './components/BuniChatWidget.vue';\nexport const BuniChatWidget = BuniChatWidgetComponent;\n\n// Create a Vue plugin for easy installation\nimport type { App } from 'vue';\n\nexport const BuniChatPlugin = {\n install(app: App) {\n app.component('BuniChatWidget', BuniChatWidgetComponent);\n }\n};\n\n// Re-export core types for convenience\nexport type {\n BuniChatConfig,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n BuniChatAPI,\n BuniChatEvents\n} from '@buni.ai/chatbot-core';\n\n// Export core widget class for manual use\nexport { BuniChatWidget as BuniChatWidgetCore, createBuniChatWidget } from '@buni.ai/chatbot-core';\n"],"names":["BuniChatWidget","_openBlock","_createElementBlock","BuniChatWidgetComponent"],"mappings":";;;;AASA,IAAI,cAAc,GAA0B,IAAI,CAAC;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AAK,EAAE;AACf,gBAAA,MAAM,UAAU,CAAC;oBACf,KAAK,EAAE,KAAK,CAAC,KAAK;oBAClB,MAAM,EAAE,KAAK,CAAC,MAAM;oBACpB,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,YAAY,EAAE,KAAK,CAAC,YAAY;oBAChC,mBAAmB,EAAE,KAAK,CAAC,mBAAmB;oBAC9C,OAAO,EAAE,KAAK,CAAC,OAAO;AACvB,iBAAA,CAAC,CAAA;aACJ;AACF,SAAC,CAAC,CAAA;QAEF,WAAW,CAAC,MAAK;AACf,YAAA,OAAO,EAAE,CAAA;AACX,SAAC,CAAC,CAAA;;YAvCA,QAAAC,SAAA,EAAA,EAAAC,kBAAA,CAAuC,OAAvC,UAAuC,CAAA,EAAA;;;;;;;ACDzC;AAMO,MAAM,cAAc,GAAGC,OAAwB;AAKzC,MAAA,cAAc,GAAG;AAC5B,IAAA,OAAO,CAAC,GAAQ,EAAA;AACd,QAAA,GAAG,CAAC,SAAS,CAAC,gBAAgB,EAAEA,MAAuB,CAAC,CAAC;KAC1D;;;;;"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vue = require('vue');
|
|
4
|
+
var chatbotCore = require('@buni.ai/chatbot-core');
|
|
5
|
+
|
|
6
|
+
let widgetInstance = null;
|
|
7
|
+
function useBuniChat(options) {
|
|
8
|
+
const state = vue.reactive({
|
|
9
|
+
isOpen: false,
|
|
10
|
+
isLoaded: false,
|
|
11
|
+
isMinimized: false,
|
|
12
|
+
unreadCount: 0,
|
|
13
|
+
});
|
|
14
|
+
const initialize = async (initOptions) => {
|
|
15
|
+
if (!widgetInstance) {
|
|
16
|
+
widgetInstance = new chatbotCore.BuniChatWidget();
|
|
17
|
+
// Set up event listeners to update reactive state
|
|
18
|
+
widgetInstance.on('visibility_changed', (data) => {
|
|
19
|
+
state.isOpen = data.visibility === 'visible';
|
|
20
|
+
});
|
|
21
|
+
widgetInstance.on('ready', () => {
|
|
22
|
+
state.isLoaded = true;
|
|
23
|
+
});
|
|
24
|
+
widgetInstance.on('minimized', () => {
|
|
25
|
+
state.isMinimized = true;
|
|
26
|
+
});
|
|
27
|
+
widgetInstance.on('maximized', () => {
|
|
28
|
+
state.isMinimized = false;
|
|
29
|
+
});
|
|
30
|
+
widgetInstance.on('new_message', (data) => {
|
|
31
|
+
if (data.isFromBot) {
|
|
32
|
+
state.unreadCount++;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
await widgetInstance.initialize(initOptions);
|
|
37
|
+
};
|
|
38
|
+
// Auto-initialize if options provided
|
|
39
|
+
if (options) {
|
|
40
|
+
initialize(options);
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
// Reactive state
|
|
44
|
+
state,
|
|
45
|
+
isOpen: vue.ref(state.isOpen),
|
|
46
|
+
isLoaded: vue.ref(state.isLoaded),
|
|
47
|
+
isMinimized: vue.ref(state.isMinimized),
|
|
48
|
+
unreadCount: vue.ref(state.unreadCount),
|
|
49
|
+
// Methods
|
|
50
|
+
initialize,
|
|
51
|
+
show: () => widgetInstance?.show(),
|
|
52
|
+
hide: () => widgetInstance?.hide(),
|
|
53
|
+
toggle: () => widgetInstance?.toggle(),
|
|
54
|
+
minimize: () => widgetInstance?.minimize(),
|
|
55
|
+
maximize: () => widgetInstance?.maximize(),
|
|
56
|
+
destroy: () => {
|
|
57
|
+
widgetInstance?.destroy();
|
|
58
|
+
widgetInstance = null;
|
|
59
|
+
},
|
|
60
|
+
// Data management
|
|
61
|
+
setCustomerData: (data) => widgetInstance?.setCustomerData(data),
|
|
62
|
+
getCustomerData: () => widgetInstance?.getCustomerData(),
|
|
63
|
+
setSessionVariables: (variables) => widgetInstance?.setSessionVariables(variables),
|
|
64
|
+
getSessionVariables: () => widgetInstance?.getSessionVariables(),
|
|
65
|
+
// Chat actions
|
|
66
|
+
sendMessage: (message) => widgetInstance?.sendMessage(message),
|
|
67
|
+
clearChat: () => widgetInstance?.clearChat(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const _hoisted_1 = { id: "buni-chat-widget-container" };
|
|
72
|
+
var script = /*@__PURE__*/ vue.defineComponent({
|
|
73
|
+
__name: 'BuniChatWidget',
|
|
74
|
+
props: {
|
|
75
|
+
token: { type: String, required: false, default: '' },
|
|
76
|
+
config: { type: null, required: false, default: () => ({}) },
|
|
77
|
+
onReady: { type: null, required: false },
|
|
78
|
+
onNewMessage: { type: null, required: false },
|
|
79
|
+
onVisibilityChanged: { type: null, required: false },
|
|
80
|
+
onError: { type: null, required: false }
|
|
81
|
+
},
|
|
82
|
+
setup(__props) {
|
|
83
|
+
const props = __props;
|
|
84
|
+
const { initialize, destroy } = useBuniChat();
|
|
85
|
+
vue.onMounted(async () => {
|
|
86
|
+
if (props.token) {
|
|
87
|
+
await initialize({
|
|
88
|
+
token: props.token,
|
|
89
|
+
config: props.config,
|
|
90
|
+
onReady: props.onReady,
|
|
91
|
+
onNewMessage: props.onNewMessage,
|
|
92
|
+
onVisibilityChanged: props.onVisibilityChanged,
|
|
93
|
+
onError: props.onError,
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
vue.onUnmounted(() => {
|
|
98
|
+
destroy();
|
|
99
|
+
});
|
|
100
|
+
return (_ctx, _cache) => {
|
|
101
|
+
return (vue.openBlock(), vue.createElementBlock("div", _hoisted_1));
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
script.__file = "src/components/BuniChatWidget.vue";
|
|
107
|
+
|
|
108
|
+
// Main exports for @buni.ai/chatbot-vue
|
|
109
|
+
const BuniChatWidget = script;
|
|
110
|
+
const BuniChatPlugin = {
|
|
111
|
+
install(app) {
|
|
112
|
+
app.component('BuniChatWidget', script);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
Object.defineProperty(exports, 'BuniChatWidgetCore', {
|
|
117
|
+
enumerable: true,
|
|
118
|
+
get: function () { return chatbotCore.BuniChatWidget; }
|
|
119
|
+
});
|
|
120
|
+
Object.defineProperty(exports, 'createBuniChatWidget', {
|
|
121
|
+
enumerable: true,
|
|
122
|
+
get: function () { return chatbotCore.createBuniChatWidget; }
|
|
123
|
+
});
|
|
124
|
+
exports.BuniChatPlugin = BuniChatPlugin;
|
|
125
|
+
exports.BuniChatWidget = BuniChatWidget;
|
|
126
|
+
exports.useBuniChat = useBuniChat;
|
|
127
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/composables/useBuniChat.ts","../src/components/BuniChatWidget.vue","../src/index.ts"],"sourcesContent":["import { ref, reactive } from 'vue';\nimport { BuniChatWidget } from '@buni.ai/chatbot-core';\nimport type { \n BuniChatOptions, \n BuniChatState, \n CustomerData, \n SessionVariables \n} from '@buni.ai/chatbot-core';\n\nlet widgetInstance: BuniChatWidget | null = null;\n\nexport function useBuniChat(options?: BuniChatOptions) {\n const state = reactive<BuniChatState>({\n isOpen: false,\n isLoaded: false,\n isMinimized: false,\n unreadCount: 0,\n });\n\n const initialize = async (initOptions: BuniChatOptions) => {\n if (!widgetInstance) {\n widgetInstance = new BuniChatWidget();\n \n // Set up event listeners to update reactive state\n widgetInstance.on('visibility_changed', (data: any) => {\n state.isOpen = data.visibility === 'visible';\n });\n \n widgetInstance.on('ready', () => {\n state.isLoaded = true;\n });\n \n widgetInstance.on('minimized', () => {\n state.isMinimized = true;\n });\n \n widgetInstance.on('maximized', () => {\n state.isMinimized = false;\n });\n \n widgetInstance.on('new_message', (data: any) => {\n if (data.isFromBot) {\n state.unreadCount++;\n }\n });\n }\n \n await widgetInstance.initialize(initOptions);\n };\n\n // Auto-initialize if options provided\n if (options) {\n initialize(options);\n }\n\n return {\n // Reactive state\n state,\n isOpen: ref(state.isOpen),\n isLoaded: ref(state.isLoaded),\n isMinimized: ref(state.isMinimized),\n unreadCount: ref(state.unreadCount),\n \n // Methods\n initialize,\n show: () => widgetInstance?.show(),\n hide: () => widgetInstance?.hide(),\n toggle: () => widgetInstance?.toggle(),\n minimize: () => widgetInstance?.minimize(),\n maximize: () => widgetInstance?.maximize(),\n destroy: () => {\n widgetInstance?.destroy();\n widgetInstance = null;\n },\n \n // Data management\n setCustomerData: (data: CustomerData) => widgetInstance?.setCustomerData(data),\n getCustomerData: () => widgetInstance?.getCustomerData(),\n setSessionVariables: (variables: SessionVariables) => widgetInstance?.setSessionVariables(variables),\n getSessionVariables: () => widgetInstance?.getSessionVariables(),\n \n // Chat actions\n sendMessage: (message: string) => widgetInstance?.sendMessage(message),\n clearChat: () => widgetInstance?.clearChat(),\n };\n}","<template>\n <div id=\"buni-chat-widget-container\" />\n</template>\n\n<script setup lang=\"ts\">\nimport { onMounted, onUnmounted } from 'vue';\nimport { useBuniChat } from '../composables/useBuniChat';\nimport type { BuniChatOptions } from '@buni.ai/chatbot-core';\n\ninterface Props {\n token?: string;\n config?: BuniChatOptions['config'];\n onReady?: BuniChatOptions['onReady'];\n onNewMessage?: BuniChatOptions['onNewMessage'];\n onVisibilityChanged?: BuniChatOptions['onVisibilityChanged'];\n onError?: BuniChatOptions['onError'];\n}\n\nconst props = withDefaults(defineProps<Props>(), {\n token: '',\n config: () => ({})\n});\n\nconst { initialize, destroy } = useBuniChat();\n\nonMounted(async () => {\n if (props.token) {\n await initialize({\n token: props.token,\n config: props.config,\n onReady: props.onReady,\n onNewMessage: props.onNewMessage,\n onVisibilityChanged: props.onVisibilityChanged,\n onError: props.onError,\n });\n }\n});\n\nonUnmounted(() => {\n destroy();\n});\n</script>","// Main exports for @buni.ai/chatbot-vue\n\nexport { useBuniChat } from './composables/useBuniChat';\n\n// Export Vue component\nimport BuniChatWidgetComponent from './components/BuniChatWidget.vue';\nexport const BuniChatWidget = BuniChatWidgetComponent;\n\n// Create a Vue plugin for easy installation\nimport type { App } from 'vue';\n\nexport const BuniChatPlugin = {\n install(app: App) {\n app.component('BuniChatWidget', BuniChatWidgetComponent);\n }\n};\n\n// Re-export core types for convenience\nexport type {\n BuniChatConfig,\n BuniChatOptions,\n BuniChatState,\n CustomerData,\n SessionVariables,\n BuniChatAPI,\n BuniChatEvents\n} from '@buni.ai/chatbot-core';\n\n// Export core widget class for manual use\nexport { BuniChatWidget as BuniChatWidgetCore, createBuniChatWidget } from '@buni.ai/chatbot-core';\n"],"names":["reactive","BuniChatWidget","ref","onMounted","onUnmounted","_openBlock","_createElementBlock","BuniChatWidgetComponent"],"mappings":";;;;;AASA,IAAI,cAAc,GAA0B,IAAI,CAAC;AAE3C,SAAU,WAAW,CAAC,OAAyB,EAAA;IACnD,MAAM,KAAK,GAAGA,YAAQ,CAAgB;AACpC,QAAA,MAAM,EAAE,KAAK;AACb,QAAA,QAAQ,EAAE,KAAK;AACf,QAAA,WAAW,EAAE,KAAK;AAClB,QAAA,WAAW,EAAE,CAAC;AACf,KAAA,CAAC,CAAC;AAEH,IAAA,MAAM,UAAU,GAAG,OAAO,WAA4B,KAAI;QACxD,IAAI,CAAC,cAAc,EAAE;AACnB,YAAA,cAAc,GAAG,IAAIC,0BAAc,EAAE,CAAC;;YAGtC,cAAc,CAAC,EAAE,CAAC,oBAAoB,EAAE,CAAC,IAAS,KAAI;gBACpD,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,UAAU,KAAK,SAAS,CAAC;AAC/C,aAAC,CAAC,CAAC;AAEH,YAAA,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,MAAK;AAC9B,gBAAA,KAAK,CAAC,QAAQ,GAAG,IAAI,CAAC;AACxB,aAAC,CAAC,CAAC;AAEH,YAAA,cAAc,CAAC,EAAE,CAAC,WAAW,EAAE,MAAK;AAClC,gBAAA,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;AAC3B,aAAC,CAAC,CAAC;AAEH,YAAA,cAAc,CAAC,EAAE,CAAC,WAAW,EAAE,MAAK;AAClC,gBAAA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ables for BuniAI chat widget",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "dist/index.js",
|
|
7
|
+
"module": "dist/index.esm.js",
|
|
8
|
+
"types": "dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"import": "./dist/index.esm.js",
|
|
12
|
+
"require": "./dist/index.js",
|
|
13
|
+
"types": "./dist/index.d.ts"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist",
|
|
18
|
+
"src/components"
|
|
19
|
+
],
|
|
20
|
+
"scripts": {
|
|
21
|
+
"build": "rollup -c rollup.config.mjs",
|
|
22
|
+
"dev": "rollup -c rollup.config.mjs -w",
|
|
23
|
+
"test": "vitest",
|
|
24
|
+
"lint": "eslint src --ext .ts,.vue",
|
|
25
|
+
"lint:fix": "eslint src --ext .ts,.vue --fix",
|
|
26
|
+
"prepublishOnly": "npm run build"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"vue",
|
|
30
|
+
"vue3",
|
|
31
|
+
"chat",
|
|
32
|
+
"widget",
|
|
33
|
+
"buni",
|
|
34
|
+
"ai",
|
|
35
|
+
"customer-support",
|
|
36
|
+
"composable"
|
|
37
|
+
],
|
|
38
|
+
"author": "BuniAI",
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"peerDependencies": {
|
|
41
|
+
"vue": ">=3.0.0"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {
|
|
44
|
+
"@buni.ai/chatbot-core": "^1.0.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@rollup/plugin-commonjs": "^24.0.0",
|
|
48
|
+
"@rollup/plugin-node-resolve": "^15.0.0",
|
|
49
|
+
"@rollup/plugin-typescript": "^11.0.0",
|
|
50
|
+
"@vue/compiler-sfc": "^3.3.0",
|
|
51
|
+
"rollup": "^3.20.0",
|
|
52
|
+
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
53
|
+
"rollup-plugin-typescript2": "^0.36.0",
|
|
54
|
+
"rollup-plugin-vue": "^6.0.0",
|
|
55
|
+
"tslib": "^2.5.0",
|
|
56
|
+
"typescript": "^5.0.0",
|
|
57
|
+
"vue": "^3.3.0"
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div id="buni-chat-widget-container" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script setup lang="ts">
|
|
6
|
+
import { onMounted, onUnmounted } from 'vue';
|
|
7
|
+
import { useBuniChat } from '../composables/useBuniChat';
|
|
8
|
+
import type { BuniChatOptions } from '@buni.ai/chatbot-core';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
token?: string;
|
|
12
|
+
config?: BuniChatOptions['config'];
|
|
13
|
+
onReady?: BuniChatOptions['onReady'];
|
|
14
|
+
onNewMessage?: BuniChatOptions['onNewMessage'];
|
|
15
|
+
onVisibilityChanged?: BuniChatOptions['onVisibilityChanged'];
|
|
16
|
+
onError?: BuniChatOptions['onError'];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
20
|
+
token: '',
|
|
21
|
+
config: () => ({})
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const { initialize, destroy } = useBuniChat();
|
|
25
|
+
|
|
26
|
+
onMounted(async () => {
|
|
27
|
+
if (props.token) {
|
|
28
|
+
await initialize({
|
|
29
|
+
token: props.token,
|
|
30
|
+
config: props.config,
|
|
31
|
+
onReady: props.onReady,
|
|
32
|
+
onNewMessage: props.onNewMessage,
|
|
33
|
+
onVisibilityChanged: props.onVisibilityChanged,
|
|
34
|
+
onError: props.onError,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
onUnmounted(() => {
|
|
40
|
+
destroy();
|
|
41
|
+
});
|
|
42
|
+
</script>
|