@blockspark/chat-widget 1.0.8 → 1.0.9
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 +117 -123
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# BlockSpark Chat Widget
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A universal JavaScript chat widget library that connects directly with Dialogflow CX - no backend API required!
|
|
4
|
+
|
|
5
|
+
**Supports:** React, Next.js, Vue.js, Nuxt 3, Vite, and Vanilla JavaScript
|
|
4
6
|
|
|
5
7
|
## Installation
|
|
6
8
|
|
|
@@ -40,89 +42,71 @@ npm install @blockspark/chat-widget
|
|
|
40
42
|
|
|
41
43
|
## Usage
|
|
42
44
|
|
|
43
|
-
### Vue.js
|
|
44
|
-
|
|
45
|
-
```bash
|
|
46
|
-
# Install
|
|
47
|
-
npm install @blockspark/chat-widget
|
|
48
|
-
```
|
|
45
|
+
### Vue.js 3
|
|
49
46
|
|
|
50
47
|
```vue
|
|
51
48
|
<template>
|
|
52
49
|
<ChatWidget
|
|
53
|
-
|
|
54
|
-
|
|
50
|
+
df-project-id="your-project-id"
|
|
51
|
+
df-agent-id="your-agent-id"
|
|
55
52
|
:service-account-key="serviceAccountKey"
|
|
53
|
+
backendBaseUrl="https://chartconnect.blockspark.in"
|
|
54
|
+
backendWsUrl="wss://chartconnect.blockspark.in"
|
|
56
55
|
/>
|
|
57
56
|
</template>
|
|
58
57
|
|
|
59
58
|
<script setup>
|
|
60
59
|
import ChatWidget from '@blockspark/chat-widget/vue';
|
|
61
|
-
|
|
62
|
-
import
|
|
60
|
+
// ⚠️ REQUIRED: Import CSS separately
|
|
61
|
+
import '@blockspark/chat-widget/styles';
|
|
62
|
+
import serviceAccountKey from './credentials/dialogflow.json';
|
|
63
63
|
</script>
|
|
64
64
|
```
|
|
65
65
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
### React/Next.js Usage
|
|
66
|
+
**CSS Import Options:**
|
|
67
|
+
- `import '@blockspark/chat-widget/styles'` (recommended)
|
|
68
|
+
- `import '@blockspark/chat-widget/dist/styles.css'` (alternative)
|
|
71
69
|
|
|
72
|
-
###
|
|
70
|
+
### Nuxt 3 / Vue.js 3 (Important: Use ClientOnly!)
|
|
73
71
|
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
72
|
+
```vue
|
|
73
|
+
<template>
|
|
74
|
+
<ClientOnly>
|
|
75
|
+
<ChatWidget
|
|
76
|
+
df-project-id="your-project-id"
|
|
77
|
+
df-agent-id="your-agent-id"
|
|
78
|
+
:service-account-key="serviceAccountKey"
|
|
79
|
+
/>
|
|
80
|
+
</ClientOnly>
|
|
81
|
+
</template>
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
dfLocation="us-central1"
|
|
87
|
-
dfAgentId="your-agent-id"
|
|
88
|
-
serviceAccountKey={serviceAccountKey}
|
|
89
|
-
languageCode="en"
|
|
90
|
-
/>
|
|
91
|
-
</div>
|
|
92
|
-
);
|
|
93
|
-
}
|
|
83
|
+
<script setup>
|
|
84
|
+
import ChatWidget from '@blockspark/chat-widget/nuxt';
|
|
85
|
+
import '@blockspark/chat-widget/styles';
|
|
86
|
+
import serviceAccountKey from './credentials/dialogflow.json';
|
|
87
|
+
</script>
|
|
94
88
|
```
|
|
95
89
|
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
90
|
+
**In `nuxt.config.ts`:**
|
|
91
|
+
```typescript
|
|
92
|
+
export default defineNuxtConfig({
|
|
93
|
+
css: ['@blockspark/chat-widget/dist/styles.css'],
|
|
94
|
+
|
|
95
|
+
vite: {
|
|
96
|
+
optimizeDeps: {
|
|
97
|
+
exclude: ['@blockspark/chat-widget'],
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
});
|
|
101
|
+
```
|
|
99
102
|
|
|
100
|
-
|
|
101
|
-
import ChatWidget from '@blockspark/chat-widget';
|
|
102
|
-
import '@blockspark/chat-widget/dist/styles.css';
|
|
103
|
+
**⚠️ CRITICAL for Nuxt:** The component MUST be wrapped in `<ClientOnly>` because it uses browser-only APIs (`localStorage`, `window`, `WebSocket`) that don't exist during SSR.
|
|
103
104
|
|
|
104
|
-
|
|
105
|
-
|
|
105
|
+
**CSS Import Options:**
|
|
106
|
+
- `import '@blockspark/chat-widget/styles'` (recommended - shorter path)
|
|
107
|
+
- `import '@blockspark/chat-widget/dist/styles.css'` (alternative)
|
|
106
108
|
|
|
107
|
-
|
|
108
|
-
useEffect(() => {
|
|
109
|
-
// Your token fetching logic here
|
|
110
|
-
fetchAccessToken().then(setAccessToken);
|
|
111
|
-
}, []);
|
|
112
|
-
|
|
113
|
-
return (
|
|
114
|
-
<ChatWidget
|
|
115
|
-
dfProjectId="your-project-id"
|
|
116
|
-
dfLocation="us-central1"
|
|
117
|
-
dfAgentId="your-agent-id"
|
|
118
|
-
accessToken={accessToken}
|
|
119
|
-
languageCode="en"
|
|
120
|
-
/>
|
|
121
|
-
);
|
|
122
|
-
}
|
|
123
|
-
```
|
|
124
|
-
|
|
125
|
-
### With Custom Configuration
|
|
109
|
+
### React/Next.js
|
|
126
110
|
|
|
127
111
|
```tsx
|
|
128
112
|
import ChatWidget from '@blockspark/chat-widget';
|
|
@@ -137,63 +121,11 @@ function App() {
|
|
|
137
121
|
dfAgentId="your-agent-id"
|
|
138
122
|
serviceAccountKey={serviceAccountKey}
|
|
139
123
|
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
124
|
/>
|
|
151
125
|
);
|
|
152
126
|
}
|
|
153
127
|
```
|
|
154
128
|
|
|
155
|
-
### Using Environment Variables
|
|
156
|
-
|
|
157
|
-
You can configure the backend API URLs for Human Support Mode using environment variables. Create a `.env` file in the project root:
|
|
158
|
-
|
|
159
|
-
```bash
|
|
160
|
-
# .env file
|
|
161
|
-
REACT_APP_BACKEND_BASE_URL=http://localhost:8012
|
|
162
|
-
REACT_APP_BACKEND_WS_URL=ws://localhost:8012
|
|
163
|
-
```
|
|
164
|
-
|
|
165
|
-
Or pass them as props:
|
|
166
|
-
|
|
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
|
-
```
|
|
176
|
-
|
|
177
|
-
**Note**: Props take precedence over environment variables.
|
|
178
|
-
|
|
179
|
-
### Human Support Mode
|
|
180
|
-
|
|
181
|
-
The widget supports automatic handoff from bot to human agents. When Dialogflow returns `{"handoff": true}`, the widget will:
|
|
182
|
-
|
|
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
|
|
188
|
-
|
|
189
|
-
The widget displays mode indicators and connection status in the chat header.
|
|
190
|
-
|
|
191
|
-
### Import Types (TypeScript)
|
|
192
|
-
|
|
193
|
-
```tsx
|
|
194
|
-
import ChatWidget, { ChatWidgetProps, DialogflowConfig } from '@blockspark/chat-widget';
|
|
195
|
-
```
|
|
196
|
-
|
|
197
129
|
## Props
|
|
198
130
|
|
|
199
131
|
| Prop | Type | Required | Default | Description |
|
|
@@ -215,11 +147,22 @@ import ChatWidget, { ChatWidgetProps, DialogflowConfig } from '@blockspark/chat-
|
|
|
215
147
|
| `inputPlaceholder` | `string` | No | `"Type your message..."` | Input field placeholder |
|
|
216
148
|
| `emptyStateMessage` | `string` | No | `"Hi! I'm BlockSpark..."` | Empty state message |
|
|
217
149
|
| `debug` | `boolean` | No | `false` | Enable debug logging |
|
|
218
|
-
| `backendBaseUrl` | `string` | No | `
|
|
219
|
-
| `backendWsUrl` | `string` | No | `
|
|
150
|
+
| `backendBaseUrl` | `string` | No | `"http://localhost:8012"` | Backend REST API base URL for Human Support Mode |
|
|
151
|
+
| `backendWsUrl` | `string` | No | `"ws://localhost:8012"` | Backend WebSocket URL for Human Support Mode |
|
|
220
152
|
|
|
221
153
|
\* Either `serviceAccountKey` or `accessToken` must be provided.
|
|
222
154
|
|
|
155
|
+
## Features
|
|
156
|
+
|
|
157
|
+
- ✅ **Direct Dialogflow CX Integration** - No backend required
|
|
158
|
+
- ✅ **Human Handoff Support** - Automatic transition from bot to human agents
|
|
159
|
+
- ✅ **Rich Content** - Supports Dialogflow chips, cards, and more
|
|
160
|
+
- ✅ **Real-time Messaging** - WebSocket support for human agents
|
|
161
|
+
- ✅ **SSR Compatible** - Works with Next.js and Nuxt 3 (with ClientOnly wrapper)
|
|
162
|
+
- ✅ **Framework Agnostic** - Same UI across React and Vue
|
|
163
|
+
- ✅ **TypeScript Support** - Full type definitions included
|
|
164
|
+
- ✅ **Tree-shakeable** - Only import what you need
|
|
165
|
+
|
|
223
166
|
## How It Works
|
|
224
167
|
|
|
225
168
|
The widget connects **directly** to Dialogflow CX using the REST API - no backend required!
|
|
@@ -228,13 +171,18 @@ The widget connects **directly** to Dialogflow CX using the REST API - no backen
|
|
|
228
171
|
2. **Session Management**: Creates and manages Dialogflow sessions automatically
|
|
229
172
|
3. **Message Handling**: Sends messages directly to Dialogflow and displays responses
|
|
230
173
|
4. **Rich Content**: Supports Dialogflow rich content (chips, cards, etc.)
|
|
174
|
+
5. **Human Handoff**: Automatically switches to human support mode when Dialogflow returns handoff signal
|
|
231
175
|
|
|
232
176
|
## Requirements
|
|
233
177
|
|
|
234
|
-
|
|
235
|
-
- React
|
|
236
|
-
-
|
|
237
|
-
|
|
178
|
+
### For React/Next.js
|
|
179
|
+
- React 16.8.0 or higher (peer dependency)
|
|
180
|
+
- React DOM 16.8.0 or higher (peer dependency)
|
|
181
|
+
|
|
182
|
+
### For Vue.js/Nuxt
|
|
183
|
+
- Vue 3.0.0 or higher (peer dependency)
|
|
184
|
+
|
|
185
|
+
**Note:** Peer dependencies are optional - install only what you need for your framework.
|
|
238
186
|
|
|
239
187
|
## Getting Your Service Account Key
|
|
240
188
|
|
|
@@ -270,7 +218,53 @@ npm run build
|
|
|
270
218
|
npm run dev
|
|
271
219
|
```
|
|
272
220
|
|
|
221
|
+
## Troubleshooting
|
|
222
|
+
|
|
223
|
+
### Vue.js/Nuxt Issues
|
|
224
|
+
|
|
225
|
+
**Widget not displaying?**
|
|
226
|
+
- ✅ Make sure you imported the CSS: `import '@blockspark/chat-widget/styles'`
|
|
227
|
+
- ✅ For Nuxt: Wrap in `<ClientOnly>` component
|
|
228
|
+
- ✅ For Nuxt: Add CSS to `nuxt.config.ts` and exclude from optimization
|
|
229
|
+
|
|
230
|
+
**Vue warnings about attributes?**
|
|
231
|
+
- ✅ This is fixed in the latest version
|
|
232
|
+
- ✅ Ensure you're using the latest package version
|
|
233
|
+
|
|
234
|
+
**Nuxt vite-node errors?**
|
|
235
|
+
- ✅ Wrap component in `<ClientOnly>`
|
|
236
|
+
- ✅ Add to `nuxt.config.ts`:
|
|
237
|
+
```ts
|
|
238
|
+
vite: {
|
|
239
|
+
optimizeDeps: {
|
|
240
|
+
exclude: ['@blockspark/chat-widget'],
|
|
241
|
+
},
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
- ✅ Clear cache: `rm -rf .nuxt node_modules/.vite`
|
|
245
|
+
|
|
246
|
+
**504 Outdated Optimize Dep error?**
|
|
247
|
+
- ✅ Clear Vite cache: `rm -rf node_modules/.vite && npm run dev`
|
|
248
|
+
- ✅ Or add to `vite.config.ts`:
|
|
249
|
+
```ts
|
|
250
|
+
optimizeDeps: {
|
|
251
|
+
exclude: ['@blockspark/chat-widget'],
|
|
252
|
+
}
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### General Issues
|
|
256
|
+
|
|
257
|
+
**Chat not opening?**
|
|
258
|
+
- ✅ Check CSS is imported
|
|
259
|
+
- ✅ Verify Dialogflow config is provided
|
|
260
|
+
- ✅ Enable debug mode: `:debug="true"` or `debug={true}` to see console logs
|
|
261
|
+
|
|
262
|
+
**Dialogflow errors?**
|
|
263
|
+
- ✅ Verify service account key is valid
|
|
264
|
+
- ✅ Check Dialogflow API is enabled
|
|
265
|
+
- ✅ Ensure service account has Dialogflow API User role
|
|
266
|
+
- ✅ Verify project ID, location, and agent ID are correct
|
|
267
|
+
|
|
273
268
|
## License
|
|
274
269
|
|
|
275
|
-
MIT
|
|
276
|
-
export NPM_TOKEN=your_token_here
|
|
270
|
+
MIT
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockspark/chat-widget",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.9",
|
|
4
4
|
"description": "BlockSpark AI Chat Widget - Universal JavaScript library supporting React, Next.js, Vue, Nuxt, and Vite",
|
|
5
5
|
"main": "./dist/index.cjs.js",
|
|
6
6
|
"module": "./dist/index.esm.js",
|