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