@blockspark/chat-widget 1.0.3 → 1.0.5
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 +148 -288
- package/dist/adapters/vue/index.d.ts +7 -0
- package/dist/adapters/vue/index.d.ts.map +1 -0
- package/dist/adapters/vue/useChatMode.d.ts +21 -0
- package/dist/adapters/vue/useChatMode.d.ts.map +1 -0
- package/dist/core/stateManager.d.ts +136 -0
- package/dist/core/stateManager.d.ts.map +1 -0
- package/dist/core/types.d.ts +66 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/entry/next.d.ts +9 -0
- package/dist/entry/next.d.ts.map +1 -0
- package/dist/entry/nuxt.d.ts +7 -0
- package/dist/entry/nuxt.d.ts.map +1 -0
- package/dist/entry/react.d.ts +10 -0
- package/dist/entry/react.d.ts.map +1 -0
- package/dist/entry/vanilla.d.ts +33 -0
- package/dist/entry/vanilla.d.ts.map +1 -0
- package/dist/entry/vite.d.ts +11 -0
- package/dist/entry/vite.d.ts.map +1 -0
- package/dist/entry/vue.d.ts +9 -0
- package/dist/entry/vue.d.ts.map +1 -0
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.LICENSE.txt +27 -0
- package/dist/index.d.ts +18 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2 -0
- package/dist/index.esm.js.LICENSE.txt +27 -0
- package/dist/index.umd.js +2 -0
- package/dist/index.umd.js.LICENSE.txt +27 -0
- package/dist/react.cjs.js +2 -0
- package/dist/react.cjs.js.LICENSE.txt +9 -0
- package/dist/react.esm.js +2 -0
- package/dist/react.esm.js.LICENSE.txt +9 -0
- package/dist/styles.css +11 -0
- package/dist/utils/frameworkDetector.d.ts +17 -0
- package/dist/utils/frameworkDetector.d.ts.map +1 -0
- package/dist/vue.cjs.js +1 -0
- package/dist/vue.esm.js +1 -0
- package/package.json +109 -40
- package/types/vue.d.ts +0 -8
package/README.md
CHANGED
|
@@ -1,346 +1,201 @@
|
|
|
1
1
|
# BlockSpark Chat Widget
|
|
2
2
|
|
|
3
|
-
A reusable chat widget
|
|
3
|
+
A reusable React chat widget component that connects directly with Dialogflow CX - no backend API required!
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
7
|
-
Install from
|
|
7
|
+
### Option 1: Install from Local Path (Recommended for Development)
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
# In your website project directory
|
|
11
|
+
npm install /path/to/blockspark-chat-widget
|
|
12
|
+
# or
|
|
13
|
+
npm install ../blockspark-chat-widget
|
|
11
14
|
```
|
|
12
15
|
|
|
13
|
-
|
|
14
|
-
- **Vue 3**: You also need `vue`. The widget bundles React internally for the Vue build, so you do **not** need to install React.
|
|
16
|
+
### Option 2: Use npm link (For Development)
|
|
15
17
|
|
|
16
18
|
```bash
|
|
17
|
-
#
|
|
18
|
-
npm
|
|
19
|
+
# In the blockspark-chat-widget directory
|
|
20
|
+
npm link
|
|
19
21
|
|
|
20
|
-
#
|
|
21
|
-
npm
|
|
22
|
+
# In your website project directory
|
|
23
|
+
npm link @blockspark/chat-widget
|
|
22
24
|
```
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
### Option 3: Publish to npm (For Production)
|
|
25
27
|
|
|
26
28
|
```bash
|
|
27
|
-
#
|
|
28
|
-
npm
|
|
29
|
-
|
|
29
|
+
# Build the library first
|
|
30
|
+
npm run build
|
|
31
|
+
|
|
32
|
+
# Publish to npm (make sure you're logged in)
|
|
33
|
+
npm publish
|
|
30
34
|
```
|
|
31
35
|
|
|
32
|
-
|
|
36
|
+
Then install in your project:
|
|
37
|
+
```bash
|
|
38
|
+
npm install @blockspark/chat-widget
|
|
39
|
+
```
|
|
33
40
|
|
|
34
41
|
## Usage
|
|
35
42
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
---
|
|
43
|
+
### Vue.js Usage (Quick Start)
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
```bash
|
|
46
|
+
# Install
|
|
47
|
+
npm install @blockspark/chat-widget
|
|
48
|
+
```
|
|
41
49
|
|
|
42
|
-
|
|
50
|
+
```vue
|
|
51
|
+
<template>
|
|
52
|
+
<ChatWidget
|
|
53
|
+
:df-project-id="'your-project-id'"
|
|
54
|
+
:df-agent-id="'your-agent-id'"
|
|
55
|
+
:service-account-key="serviceAccountKey"
|
|
56
|
+
/>
|
|
57
|
+
</template>
|
|
43
58
|
|
|
44
|
-
|
|
45
|
-
import ChatWidget from '@blockspark/chat-widget';
|
|
59
|
+
<script setup>
|
|
60
|
+
import ChatWidget from '@blockspark/chat-widget/vue';
|
|
46
61
|
import '@blockspark/chat-widget/dist/styles.css';
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
function App() {
|
|
51
|
-
return (
|
|
52
|
-
<ChatWidget
|
|
53
|
-
dfProjectId="your-project-id"
|
|
54
|
-
dfLocation="us-central1"
|
|
55
|
-
dfAgentId="your-agent-id"
|
|
56
|
-
serviceAccountKey={serviceAccountKey}
|
|
57
|
-
// accessToken="your-token" // use instead of serviceAccountKey if you have a token
|
|
58
|
-
languageCode="en"
|
|
59
|
-
title="💬 BlockSpark AI Assistant"
|
|
60
|
-
subtitle="We're here to help"
|
|
61
|
-
welcomeTitle="👋 Welcome to Blockspark"
|
|
62
|
-
welcomeMessage="My name is BlockSpark AI Assistant and I'll guide you."
|
|
63
|
-
welcomeCta="💬 Click here to start chatting!"
|
|
64
|
-
showWelcomePopup={true}
|
|
65
|
-
welcomePopupDelay={1500}
|
|
66
|
-
fallbackWelcomeMessage="Hello! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
67
|
-
inputPlaceholder="Type your message..."
|
|
68
|
-
emptyStateMessage="Hi! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
69
|
-
debug={false}
|
|
70
|
-
backendBaseUrl="http://localhost:8012"
|
|
71
|
-
backendWsUrl="ws://localhost:8012"
|
|
72
|
-
/>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
62
|
+
import serviceAccountKey from './service-account-key.json';
|
|
63
|
+
</script>
|
|
75
64
|
```
|
|
76
65
|
|
|
77
|
-
|
|
66
|
+
**📚 For detailed Vue.js setup guide, see [VUE_INSTALLATION_GUIDE.md](./VUE_INSTALLATION_GUIDE.md)**
|
|
78
67
|
|
|
79
|
-
|
|
68
|
+
---
|
|
80
69
|
|
|
81
|
-
|
|
70
|
+
### React/Next.js Usage
|
|
82
71
|
|
|
83
|
-
|
|
84
|
-
'use client';
|
|
72
|
+
### Basic Usage
|
|
85
73
|
|
|
86
|
-
|
|
74
|
+
```tsx
|
|
75
|
+
import ChatWidget from '@blockspark/chat-widget';
|
|
87
76
|
import '@blockspark/chat-widget/dist/styles.css';
|
|
88
77
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
{ ssr: false }
|
|
92
|
-
);
|
|
93
|
-
|
|
94
|
-
export default function Page() {
|
|
95
|
-
const serviceAccountKey = {
|
|
96
|
-
/* your key object, or load from env/server */
|
|
97
|
-
};
|
|
78
|
+
// Load your Google Cloud service account key
|
|
79
|
+
import serviceAccountKey from './path/to/service-account-key.json';
|
|
98
80
|
|
|
81
|
+
function App() {
|
|
99
82
|
return (
|
|
100
83
|
<div>
|
|
101
|
-
<h1>My Page</h1>
|
|
102
84
|
<ChatWidget
|
|
103
85
|
dfProjectId="your-project-id"
|
|
104
86
|
dfLocation="us-central1"
|
|
105
87
|
dfAgentId="your-agent-id"
|
|
106
88
|
serviceAccountKey={serviceAccountKey}
|
|
107
89
|
languageCode="en"
|
|
108
|
-
title="💬 BlockSpark AI Assistant"
|
|
109
|
-
subtitle="We're here to help"
|
|
110
|
-
welcomeTitle="👋 Welcome to Blockspark"
|
|
111
|
-
welcomeMessage="My name is BlockSpark AI Assistant and I'll guide you."
|
|
112
|
-
welcomeCta="💬 Click here to start chatting!"
|
|
113
|
-
showWelcomePopup={true}
|
|
114
|
-
welcomePopupDelay={1500}
|
|
115
|
-
fallbackWelcomeMessage="Hello! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
116
|
-
inputPlaceholder="Type your message..."
|
|
117
|
-
emptyStateMessage="Hi! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
118
|
-
debug={false}
|
|
119
|
-
backendBaseUrl="http://localhost:8012"
|
|
120
|
-
backendWsUrl="ws://localhost:8012"
|
|
121
90
|
/>
|
|
122
91
|
</div>
|
|
123
92
|
);
|
|
124
93
|
}
|
|
125
94
|
```
|
|
126
95
|
|
|
127
|
-
|
|
96
|
+
### Using Access Token (Alternative)
|
|
97
|
+
|
|
98
|
+
If you prefer to manage authentication yourself:
|
|
128
99
|
|
|
129
100
|
```tsx
|
|
130
|
-
import
|
|
101
|
+
import ChatWidget from '@blockspark/chat-widget';
|
|
131
102
|
import '@blockspark/chat-widget/dist/styles.css';
|
|
132
103
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
{ ssr: false }
|
|
136
|
-
);
|
|
104
|
+
function App() {
|
|
105
|
+
const [accessToken, setAccessToken] = useState<string>('');
|
|
137
106
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
107
|
+
// Get access token from your backend or OAuth flow
|
|
108
|
+
useEffect(() => {
|
|
109
|
+
// Your token fetching logic here
|
|
110
|
+
fetchAccessToken().then(setAccessToken);
|
|
111
|
+
}, []);
|
|
142
112
|
|
|
143
113
|
return (
|
|
144
114
|
<ChatWidget
|
|
145
115
|
dfProjectId="your-project-id"
|
|
146
116
|
dfLocation="us-central1"
|
|
147
117
|
dfAgentId="your-agent-id"
|
|
148
|
-
|
|
118
|
+
accessToken={accessToken}
|
|
149
119
|
languageCode="en"
|
|
150
|
-
title="💬 BlockSpark AI Assistant"
|
|
151
|
-
subtitle="We're here to help"
|
|
152
|
-
welcomeTitle="👋 Welcome to Blockspark"
|
|
153
|
-
welcomeMessage="My name is BlockSpark AI Assistant and I'll guide you."
|
|
154
|
-
welcomeCta="💬 Click here to start chatting!"
|
|
155
|
-
showWelcomePopup={true}
|
|
156
|
-
welcomePopupDelay={1500}
|
|
157
|
-
fallbackWelcomeMessage="Hello! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
158
|
-
inputPlaceholder="Type your message..."
|
|
159
|
-
emptyStateMessage="Hi! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
160
|
-
debug={false}
|
|
161
|
-
backendBaseUrl="http://localhost:8012"
|
|
162
|
-
backendWsUrl="ws://localhost:8012"
|
|
163
120
|
/>
|
|
164
121
|
);
|
|
165
122
|
}
|
|
166
123
|
```
|
|
167
124
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
### Vue 3
|
|
171
|
-
|
|
172
|
-
Use either the global plugin or the component directly.
|
|
125
|
+
### With Custom Configuration
|
|
173
126
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
```js
|
|
177
|
-
import { createApp } from 'vue';
|
|
178
|
-
import App from './App.vue';
|
|
179
|
-
import BlockSparkChatWidget from '@blockspark/chat-widget/vue';
|
|
127
|
+
```tsx
|
|
128
|
+
import ChatWidget from '@blockspark/chat-widget';
|
|
180
129
|
import '@blockspark/chat-widget/dist/styles.css';
|
|
130
|
+
import serviceAccountKey from './service-account-key.json';
|
|
181
131
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
:welcomePopupDelay="1500"
|
|
204
|
-
fallbackWelcomeMessage="Hello! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
205
|
-
inputPlaceholder="Type your message..."
|
|
206
|
-
emptyStateMessage="Hi! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
207
|
-
:debug="false"
|
|
208
|
-
backendBaseUrl="http://localhost:8012"
|
|
209
|
-
backendWsUrl="ws://localhost:8012"
|
|
210
|
-
/>
|
|
211
|
-
</template>
|
|
132
|
+
function App() {
|
|
133
|
+
return (
|
|
134
|
+
<ChatWidget
|
|
135
|
+
dfProjectId="your-project-id"
|
|
136
|
+
dfLocation="us-central1"
|
|
137
|
+
dfAgentId="your-agent-id"
|
|
138
|
+
serviceAccountKey={serviceAccountKey}
|
|
139
|
+
languageCode="en"
|
|
140
|
+
title="💬 My Chat Assistant"
|
|
141
|
+
subtitle="How can I help you?"
|
|
142
|
+
welcomeTitle="👋 Welcome!"
|
|
143
|
+
welcomeMessage="I'm here to help you with any questions."
|
|
144
|
+
welcomeCta="Start chatting"
|
|
145
|
+
showWelcomePopup={true}
|
|
146
|
+
welcomePopupDelay={2000}
|
|
147
|
+
inputPlaceholder="Type your message..."
|
|
148
|
+
emptyStateMessage="Hi! How can I help you today?"
|
|
149
|
+
debug={false}
|
|
150
|
+
/>
|
|
151
|
+
);
|
|
152
|
+
}
|
|
212
153
|
```
|
|
213
154
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
```vue
|
|
217
|
-
<script setup>
|
|
218
|
-
import { BlockSparkChatWidgetVue } from '@blockspark/chat-widget/vue';
|
|
219
|
-
import '@blockspark/chat-widget/dist/styles.css';
|
|
220
|
-
|
|
221
|
-
import serviceAccountKey from './path/to/service-account-key.json';
|
|
222
|
-
</script>
|
|
155
|
+
### Using Environment Variables
|
|
223
156
|
|
|
224
|
-
|
|
225
|
-
<BlockSparkChatWidgetVue
|
|
226
|
-
dfProjectId="your-project-id"
|
|
227
|
-
dfLocation="us-central1"
|
|
228
|
-
dfAgentId="your-agent-id"
|
|
229
|
-
:serviceAccountKey="serviceAccountKey"
|
|
230
|
-
languageCode="en"
|
|
231
|
-
title="💬 BlockSpark AI Assistant"
|
|
232
|
-
subtitle="We're here to help"
|
|
233
|
-
welcomeTitle="👋 Welcome to Blockspark"
|
|
234
|
-
welcomeMessage="My name is BlockSpark AI Assistant and I'll guide you."
|
|
235
|
-
welcomeCta="💬 Click here to start chatting!"
|
|
236
|
-
:showWelcomePopup="true"
|
|
237
|
-
:welcomePopupDelay="1500"
|
|
238
|
-
fallbackWelcomeMessage="Hello! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
239
|
-
inputPlaceholder="Type your message..."
|
|
240
|
-
emptyStateMessage="Hi! I'm BlockSpark AI Assistant. How can I help you today?"
|
|
241
|
-
:debug="false"
|
|
242
|
-
backendBaseUrl="http://localhost:8012"
|
|
243
|
-
backendWsUrl="ws://localhost:8012"
|
|
244
|
-
/>
|
|
245
|
-
</template>
|
|
246
|
-
```
|
|
157
|
+
You can configure the backend API URLs for Human Support Mode using environment variables. Create a `.env` file in the project root:
|
|
247
158
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
Replace `1.0.1` with the version you want (or use `latest` for the latest release).
|
|
253
|
-
|
|
254
|
-
**Using unpkg:**
|
|
255
|
-
|
|
256
|
-
```html
|
|
257
|
-
<!DOCTYPE html>
|
|
258
|
-
<html lang="en">
|
|
259
|
-
<head>
|
|
260
|
-
<meta charset="UTF-8" />
|
|
261
|
-
<title>BlockSpark Chat Widget</title>
|
|
262
|
-
<!-- 1. React (required by the widget) -->
|
|
263
|
-
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
|
264
|
-
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
|
265
|
-
<!-- 2. Widget CSS -->
|
|
266
|
-
<link rel="stylesheet" href="https://unpkg.com/@blockspark/chat-widget@1.0.1/dist/styles.css" />
|
|
267
|
-
</head>
|
|
268
|
-
<body>
|
|
269
|
-
<div id="chat-root"></div>
|
|
270
|
-
|
|
271
|
-
<!-- 3. Widget script (UMD: exposes BlockSparkChatWidget) -->
|
|
272
|
-
<script src="https://unpkg.com/@blockspark/chat-widget@1.0.1/dist/index.js"></script>
|
|
273
|
-
|
|
274
|
-
<script>
|
|
275
|
-
(function () {
|
|
276
|
-
var container = document.getElementById('chat-root');
|
|
277
|
-
var React = window.React;
|
|
278
|
-
var ReactDOM = window.ReactDOM;
|
|
279
|
-
var ChatWidget = window.BlockSparkChatWidget;
|
|
280
|
-
|
|
281
|
-
var config = {
|
|
282
|
-
dfProjectId: 'your-project-id',
|
|
283
|
-
dfLocation: 'us-central1',
|
|
284
|
-
dfAgentId: 'your-agent-id',
|
|
285
|
-
serviceAccountKey: { /* your service account key object */ },
|
|
286
|
-
// accessToken: 'your-token', // use instead of serviceAccountKey if you have a token
|
|
287
|
-
languageCode: 'en',
|
|
288
|
-
title: '💬 BlockSpark AI Assistant',
|
|
289
|
-
subtitle: "We're here to help",
|
|
290
|
-
welcomeTitle: '👋 Welcome to Blockspark',
|
|
291
|
-
welcomeMessage: "My name is BlockSpark AI Assistant and I'll guide you.",
|
|
292
|
-
welcomeCta: '💬 Click here to start chatting!',
|
|
293
|
-
showWelcomePopup: true,
|
|
294
|
-
welcomePopupDelay: 1500,
|
|
295
|
-
fallbackWelcomeMessage: "Hello! I'm BlockSpark AI Assistant. How can I help you today?",
|
|
296
|
-
inputPlaceholder: 'Type your message...',
|
|
297
|
-
emptyStateMessage: "Hi! I'm BlockSpark AI Assistant. How can I help you today?",
|
|
298
|
-
debug: false,
|
|
299
|
-
backendBaseUrl: 'http://localhost:8012',
|
|
300
|
-
backendWsUrl: 'ws://localhost:8012'
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
if (ReactDOM.createRoot) {
|
|
304
|
-
ReactDOM.createRoot(container).render(React.createElement(ChatWidget, config));
|
|
305
|
-
} else {
|
|
306
|
-
ReactDOM.render(React.createElement(ChatWidget, config), container);
|
|
307
|
-
}
|
|
308
|
-
})();
|
|
309
|
-
</script>
|
|
310
|
-
</body>
|
|
311
|
-
</html>
|
|
159
|
+
```bash
|
|
160
|
+
# .env file
|
|
161
|
+
REACT_APP_BACKEND_BASE_URL=http://localhost:8012
|
|
162
|
+
REACT_APP_BACKEND_WS_URL=ws://localhost:8012
|
|
312
163
|
```
|
|
313
164
|
|
|
314
|
-
|
|
165
|
+
Or pass them as props:
|
|
315
166
|
|
|
316
|
-
|
|
167
|
+
```tsx
|
|
168
|
+
<ChatWidget
|
|
169
|
+
dfProjectId="your-project-id"
|
|
170
|
+
dfAgentId="your-agent-id"
|
|
171
|
+
serviceAccountKey={serviceAccountKey}
|
|
172
|
+
backendBaseUrl="http://your-backend-url:8012"
|
|
173
|
+
backendWsUrl="ws://your-backend-url:8012"
|
|
174
|
+
/>
|
|
175
|
+
```
|
|
317
176
|
|
|
318
|
-
|
|
319
|
-
- JS: `https://cdn.jsdelivr.net/npm/@blockspark/chat-widget@1.0.1/dist/index.js`
|
|
177
|
+
**Note**: Props take precedence over environment variables.
|
|
320
178
|
|
|
321
|
-
|
|
179
|
+
### Human Support Mode
|
|
322
180
|
|
|
323
|
-
|
|
324
|
-
- Pin the version in the URL (e.g. `@1.0.1`) instead of `@latest` for stable behavior.
|
|
181
|
+
The widget supports automatic handoff from bot to human agents. When Dialogflow returns `{"handoff": true}`, the widget will:
|
|
325
182
|
|
|
326
|
-
|
|
183
|
+
1. Switch from Bot Mode to Human Support Mode
|
|
184
|
+
2. Create a support chat session
|
|
185
|
+
3. Connect via WebSocket for real-time messaging
|
|
186
|
+
4. Load message history
|
|
187
|
+
5. Route messages to the backend API instead of Dialogflow
|
|
327
188
|
|
|
328
|
-
|
|
189
|
+
The widget displays mode indicators and connection status in the chat header.
|
|
329
190
|
|
|
330
|
-
|
|
191
|
+
### Import Types (TypeScript)
|
|
331
192
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
4. Load message history
|
|
336
|
-
5. Route messages to the backend API instead of Dialogflow
|
|
337
|
-
|
|
338
|
-
The widget shows mode and connection status in the chat header.
|
|
193
|
+
```tsx
|
|
194
|
+
import ChatWidget, { ChatWidgetProps, DialogflowConfig } from '@blockspark/chat-widget';
|
|
195
|
+
```
|
|
339
196
|
|
|
340
197
|
## Props
|
|
341
198
|
|
|
342
|
-
All props use **camelCase** in every framework (React, Next.js, Vue, CDN).
|
|
343
|
-
|
|
344
199
|
| Prop | Type | Required | Default | Description |
|
|
345
200
|
|------|------|----------|---------|-------------|
|
|
346
201
|
| `dfProjectId` | `string` | Yes | - | Dialogflow project ID |
|
|
@@ -360,57 +215,62 @@ All props use **camelCase** in every framework (React, Next.js, Vue, CDN).
|
|
|
360
215
|
| `inputPlaceholder` | `string` | No | `"Type your message..."` | Input field placeholder |
|
|
361
216
|
| `emptyStateMessage` | `string` | No | `"Hi! I'm BlockSpark..."` | Empty state message |
|
|
362
217
|
| `debug` | `boolean` | No | `false` | Enable debug logging |
|
|
363
|
-
| `backendBaseUrl` | `string` | No | env or `"http://localhost:8012"` | Backend REST API base URL for Human Support Mode |
|
|
364
|
-
| `backendWsUrl` | `string` | No | env or `"ws://localhost:8012"` | Backend WebSocket URL for Human Support Mode |
|
|
218
|
+
| `backendBaseUrl` | `string` | No | `process.env.REACT_APP_BACKEND_BASE_URL` or `"http://localhost:8012"` | Backend REST API base URL for Human Support Mode |
|
|
219
|
+
| `backendWsUrl` | `string` | No | `process.env.REACT_APP_BACKEND_WS_URL` or `"ws://localhost:8012"` | Backend WebSocket URL for Human Support Mode |
|
|
365
220
|
|
|
366
221
|
\* Either `serviceAccountKey` or `accessToken` must be provided.
|
|
367
222
|
|
|
368
|
-
## TypeScript
|
|
369
|
-
|
|
370
|
-
```tsx
|
|
371
|
-
import ChatWidget, { ChatWidgetProps, DialogflowConfig } from '@blockspark/chat-widget';
|
|
372
|
-
```
|
|
373
|
-
|
|
374
223
|
## How It Works
|
|
375
224
|
|
|
376
|
-
The widget
|
|
225
|
+
The widget connects **directly** to Dialogflow CX using the REST API - no backend required!
|
|
377
226
|
|
|
378
|
-
1. **Authentication
|
|
379
|
-
2. **
|
|
380
|
-
3. **
|
|
381
|
-
4. **Rich
|
|
227
|
+
1. **Authentication**: Uses Google Cloud service account key to generate OAuth2 access tokens
|
|
228
|
+
2. **Session Management**: Creates and manages Dialogflow sessions automatically
|
|
229
|
+
3. **Message Handling**: Sends messages directly to Dialogflow and displays responses
|
|
230
|
+
4. **Rich Content**: Supports Dialogflow rich content (chips, cards, etc.)
|
|
382
231
|
|
|
383
232
|
## Requirements
|
|
384
233
|
|
|
385
|
-
-
|
|
386
|
-
-
|
|
387
|
-
-
|
|
388
|
-
-
|
|
234
|
+
- React 16.8.0 or higher
|
|
235
|
+
- React DOM 16.8.0 or higher
|
|
236
|
+
- Google Cloud service account with Dialogflow API enabled
|
|
237
|
+
- Dialogflow CX agent
|
|
389
238
|
|
|
390
239
|
## Getting Your Service Account Key
|
|
391
240
|
|
|
392
|
-
1.
|
|
393
|
-
2.
|
|
394
|
-
3.
|
|
395
|
-
4.
|
|
396
|
-
5.
|
|
241
|
+
1. Go to [Google Cloud Console](https://console.cloud.google.com/)
|
|
242
|
+
2. Select your project
|
|
243
|
+
3. Navigate to **IAM & Admin** > **Service Accounts**
|
|
244
|
+
4. Create a new service account or select an existing one
|
|
245
|
+
5. Create a JSON key and download it
|
|
246
|
+
6. Enable **Dialogflow API** for your project
|
|
247
|
+
7. Grant the service account **Dialogflow API User** role
|
|
397
248
|
|
|
398
|
-
## Security
|
|
249
|
+
## Security Warning ⚠️
|
|
399
250
|
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
-
|
|
251
|
+
**Important**: Service account keys contain sensitive credentials.
|
|
252
|
+
|
|
253
|
+
- **For Development**: You can import the key directly (as shown in examples)
|
|
254
|
+
- **For Production**:
|
|
255
|
+
- **DO NOT** expose service account keys in client-side code
|
|
256
|
+
- Use a backend proxy to handle authentication
|
|
257
|
+
- Or use OAuth2 flow to get access tokens securely
|
|
258
|
+
- Consider using restricted service account keys with minimal permissions
|
|
405
259
|
|
|
406
260
|
## Development
|
|
407
261
|
|
|
408
262
|
```bash
|
|
263
|
+
# Install dependencies
|
|
409
264
|
npm install
|
|
410
|
-
|
|
411
|
-
|
|
265
|
+
|
|
266
|
+
# Build for production
|
|
267
|
+
npm run build
|
|
268
|
+
|
|
269
|
+
# Watch mode for development
|
|
270
|
+
npm run dev
|
|
412
271
|
```
|
|
413
272
|
|
|
414
273
|
## License
|
|
415
274
|
|
|
416
275
|
MIT
|
|
276
|
+
export NPM_TOKEN=your_token_here
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/adapters/vue/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,OAAO,IAAI,UAAU,EAAE,MAAM,kBAAkB,CAAC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vue Composable for Chat Mode Management
|
|
3
|
+
* Equivalent to React's useChatMode hook
|
|
4
|
+
*/
|
|
5
|
+
import type { ChatResponse } from '../../services/dialogflowClient';
|
|
6
|
+
export type ChatMode = 'BOT' | 'HUMAN';
|
|
7
|
+
export interface UseChatModeReturn {
|
|
8
|
+
currentMode: ChatMode;
|
|
9
|
+
switchToHumanMode: () => void;
|
|
10
|
+
switchToBotMode: () => void;
|
|
11
|
+
isHandoffTriggered: (dialogflowResponse: ChatResponse) => boolean;
|
|
12
|
+
chatId: string | null;
|
|
13
|
+
sessionId: string | null;
|
|
14
|
+
setChatId: (id: string | null) => void;
|
|
15
|
+
setSessionId: (id: string | null) => void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Vue composable to manage chat mode (BOT or HUMAN)
|
|
19
|
+
*/
|
|
20
|
+
export declare function useChatMode(): UseChatModeReturn;
|
|
21
|
+
//# sourceMappingURL=useChatMode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useChatMode.d.ts","sourceRoot":"","sources":["../../../src/adapters/vue/useChatMode.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAEpE,MAAM,MAAM,QAAQ,GAAG,KAAK,GAAG,OAAO,CAAC;AAMvC,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,QAAQ,CAAC;IACtB,iBAAiB,EAAE,MAAM,IAAI,CAAC;IAC9B,eAAe,EAAE,MAAM,IAAI,CAAC;IAC5B,kBAAkB,EAAE,CAAC,kBAAkB,EAAE,YAAY,KAAK,OAAO,CAAC;IAClE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,SAAS,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;IACvC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAC;CAC3C;AAED;;GAEG;AACH,wBAAgB,WAAW,IAAI,iBAAiB,CAqF/C"}
|