guideai-app 0.2.4 → 0.2.6
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/GuideAI.js +1 -1
- package/GuideAI.js.map +1 -1
- package/README.md +39 -1
- package/dist/GuideAI.js +1 -1
- package/dist/GuideAI.js.map +1 -1
- package/dist/components/TextInput.d.ts +8 -0
- package/dist/components/TranscriptBox.d.ts +17 -0
- package/dist/index.d.ts +2 -0
- package/dist/metric/event-listner.d.ts +113 -0
- package/dist/metric/index.d.ts +4 -0
- package/dist/metric/metadata-tracker.d.ts +33 -0
- package/dist/styles/GuideAI.styles.d.ts +1 -1
- package/dist/types/GuideAI.types.d.ts +18 -0
- package/dist/types/metadata.types.d.ts +46 -0
- package/dist/utils/api.d.ts +4 -0
- package/dist/utils/constants.d.ts +1 -1
- package/dist/utils/messageStorage.d.ts +1 -1
- package/metadata-tracking-example.md +324 -0
- package/package.json +1 -1
- package/text-input-usage.md +321 -0
- package/transcript-toggle-usage.md +267 -0
- package/dist/GuideAI.js.LICENSE.txt +0 -16
- package/dist/components/Styles.d.ts +0 -3
- package/dist/components/Styles.js +0 -6
- package/dist/components/Styles.js.map +0 -1
- package/dist/hooks/useConversation.d.ts +0 -11
- package/dist/hooks/useConversation.js +0 -286
- package/dist/hooks/useConversation.js.map +0 -1
- package/dist/hooks/useRecording.d.ts +0 -12
- package/dist/hooks/useRecording.js +0 -362
- package/dist/hooks/useRecording.js.map +0 -1
- package/dist/index.esm.js +0 -1
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +0 -1
- package/dist/messageStorageUtils.d.ts +0 -26
- package/dist/types/index.d.ts +0 -20
- package/dist/types/index.js +0 -2
- package/dist/types/index.js.map +0 -1
- package/dist/types/workflow.d.ts +0 -24
- package/dist/types.d.ts +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/dist/utils/api-services.d.ts +0 -5
- package/dist/utils/api-services.js +0 -203
- package/dist/utils/api-services.js.map +0 -1
- package/dist/utils/dom-interaction.d.ts +0 -2
- package/dist/utils/dom-interaction.js +0 -195
- package/dist/utils/dom-interaction.js.map +0 -1
- package/dist/utils/dom.d.ts +0 -1
- package/dist/utils/messageStorageUtils.d.ts +0 -26
- package/dist/utils/react-hooks.d.ts +0 -9
- package/dist/utils/react-hooks.js +0 -19
- package/dist/utils/react-hooks.js.map +0 -1
- package/dist/utils/storage.d.ts +0 -14
- package/dist/utils/storage.js +0 -27
- package/dist/utils/storage.js.map +0 -1
- package/dist/utils/webrtc.d.ts +0 -3
- package/dist/utils/webrtc.js +0 -135
- package/dist/utils/webrtc.js.map +0 -1
- package/dist/utils/workflowUtils.d.ts +0 -17
- package/dist/utils/workflowValidator.d.ts +0 -17
- package/dist/workflows/certificateWorkflow.d.ts +0 -7
- package/dist/workflows/index.d.ts +0 -6
- package/todo.md +0 -2
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
# User Metadata Tracking - Implementation Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The GuideAI package now includes comprehensive user metadata tracking capabilities designed for integration with Overproof. This system tracks the following metadata:
|
|
6
|
+
|
|
7
|
+
- **User's First Visit** - Timestamp of the first time the user interacted with GuideAI
|
|
8
|
+
- **User's Last Visit** - Timestamp of the most recent user interaction
|
|
9
|
+
- **User Logins** - Count and timestamp of login events
|
|
10
|
+
- **User Type** - Classification of the user (agent, admin, manager, customer, guest, etc.)
|
|
11
|
+
- **Customer Type** - Type of customer (individual, business, enterprise, etc.)
|
|
12
|
+
- **Customer License** - License identifier for the customer
|
|
13
|
+
|
|
14
|
+
## Basic Usage
|
|
15
|
+
|
|
16
|
+
### 1. Basic Integration
|
|
17
|
+
|
|
18
|
+
```typescript
|
|
19
|
+
import { GuideAI } from 'guide-ai-package';
|
|
20
|
+
|
|
21
|
+
function App() {
|
|
22
|
+
return (
|
|
23
|
+
<GuideAI
|
|
24
|
+
organizationKey="your-org-key"
|
|
25
|
+
metadata={{
|
|
26
|
+
config: {
|
|
27
|
+
trackVisits: true,
|
|
28
|
+
trackLogins: true,
|
|
29
|
+
syncInterval: 30000, // Sync every 30 seconds
|
|
30
|
+
storage: 'localStorage'
|
|
31
|
+
},
|
|
32
|
+
initialUserData: {
|
|
33
|
+
userType: 'agent',
|
|
34
|
+
customerType: 'business',
|
|
35
|
+
customerLicense: 'OVERPRF-12345'
|
|
36
|
+
},
|
|
37
|
+
onMetadataUpdate: (metadata) => {
|
|
38
|
+
console.log('Metadata updated:', metadata);
|
|
39
|
+
// Send to your analytics system
|
|
40
|
+
}
|
|
41
|
+
}}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Tracking User Login Events
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { useRef } from 'react';
|
|
51
|
+
|
|
52
|
+
function LoginComponent() {
|
|
53
|
+
const guideAIRef = useRef();
|
|
54
|
+
|
|
55
|
+
const handleLogin = async (userInfo) => {
|
|
56
|
+
// Your login logic here
|
|
57
|
+
const loginResult = await performLogin(userInfo);
|
|
58
|
+
|
|
59
|
+
if (loginResult.success) {
|
|
60
|
+
// Track the login with GuideAI
|
|
61
|
+
guideAIRef.current?.trackLogin({
|
|
62
|
+
userId: loginResult.userId,
|
|
63
|
+
userType: loginResult.userType,
|
|
64
|
+
customerType: loginResult.customerType,
|
|
65
|
+
customerLicense: loginResult.license
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
return (
|
|
71
|
+
<div>
|
|
72
|
+
<GuideAI
|
|
73
|
+
ref={guideAIRef}
|
|
74
|
+
organizationKey="your-org-key"
|
|
75
|
+
metadata={{
|
|
76
|
+
config: { trackLogins: true }
|
|
77
|
+
}}
|
|
78
|
+
/>
|
|
79
|
+
<button onClick={handleLogin}>Login</button>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
### 3. Updating User Information
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
function UserProfileComponent() {
|
|
89
|
+
const guideAIRef = useRef();
|
|
90
|
+
|
|
91
|
+
const updateUserProfile = (newUserData) => {
|
|
92
|
+
// Update user profile in your system
|
|
93
|
+
saveUserProfile(newUserData);
|
|
94
|
+
|
|
95
|
+
// Update GuideAI metadata
|
|
96
|
+
guideAIRef.current?.updateUserInfo({
|
|
97
|
+
userType: newUserData.role,
|
|
98
|
+
customerType: newUserData.accountType,
|
|
99
|
+
customerLicense: newUserData.license,
|
|
100
|
+
customFields: {
|
|
101
|
+
department: newUserData.department,
|
|
102
|
+
region: newUserData.region
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<GuideAI
|
|
109
|
+
ref={guideAIRef}
|
|
110
|
+
organizationKey="your-org-key"
|
|
111
|
+
metadata={{
|
|
112
|
+
config: {
|
|
113
|
+
customFields: ['department', 'region'],
|
|
114
|
+
collectBrowserInfo: true
|
|
115
|
+
}
|
|
116
|
+
}}
|
|
117
|
+
/>
|
|
118
|
+
);
|
|
119
|
+
}
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
## Configuration Options
|
|
123
|
+
|
|
124
|
+
### MetadataConfig
|
|
125
|
+
|
|
126
|
+
```typescript
|
|
127
|
+
interface MetadataConfig {
|
|
128
|
+
// Whether to automatically track visits (default: true)
|
|
129
|
+
trackVisits?: boolean;
|
|
130
|
+
|
|
131
|
+
// Whether to automatically track logins (default: true)
|
|
132
|
+
trackLogins?: boolean;
|
|
133
|
+
|
|
134
|
+
// How often to sync metadata to backend in milliseconds (default: 30000)
|
|
135
|
+
syncInterval?: number;
|
|
136
|
+
|
|
137
|
+
// Storage strategy (default: 'localStorage')
|
|
138
|
+
storage?: 'localStorage' | 'sessionStorage' | 'memory';
|
|
139
|
+
|
|
140
|
+
// Custom metadata fields to collect
|
|
141
|
+
customFields?: string[];
|
|
142
|
+
|
|
143
|
+
// Whether to collect browser information (default: true)
|
|
144
|
+
collectBrowserInfo?: boolean;
|
|
145
|
+
|
|
146
|
+
// Whether to collect user agent (default: true)
|
|
147
|
+
collectUserAgent?: boolean;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### UserMetadata Structure
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
interface UserMetadata {
|
|
155
|
+
// Core identification
|
|
156
|
+
userId?: string;
|
|
157
|
+
userType?: 'agent' | 'admin' | 'manager' | 'customer' | 'guest' | string;
|
|
158
|
+
|
|
159
|
+
// Customer-specific metadata
|
|
160
|
+
customerType?: 'individual' | 'business' | 'enterprise' | string;
|
|
161
|
+
customerLicense?: string;
|
|
162
|
+
|
|
163
|
+
// Visit tracking (automatically managed)
|
|
164
|
+
firstVisit?: number; // timestamp
|
|
165
|
+
lastVisit?: number; // timestamp
|
|
166
|
+
visitCount?: number;
|
|
167
|
+
|
|
168
|
+
// Login tracking (requires manual tracking)
|
|
169
|
+
loginCount?: number;
|
|
170
|
+
lastLogin?: number; // timestamp
|
|
171
|
+
|
|
172
|
+
// Session metadata (automatically managed)
|
|
173
|
+
organizationKey: string;
|
|
174
|
+
sessionId?: string;
|
|
175
|
+
|
|
176
|
+
// Browser information (automatically collected if enabled)
|
|
177
|
+
userAgent?: string;
|
|
178
|
+
browserInfo?: {
|
|
179
|
+
name?: string;
|
|
180
|
+
version?: string;
|
|
181
|
+
platform?: string;
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
// Custom fields for Overproof-specific needs
|
|
185
|
+
customFields?: Record<string, string | number | boolean>;
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
## API Integration
|
|
190
|
+
|
|
191
|
+
The system automatically sends metadata updates to these endpoints:
|
|
192
|
+
|
|
193
|
+
### POST `/user-metadata`
|
|
194
|
+
Sends complete user metadata object when initially collected.
|
|
195
|
+
|
|
196
|
+
### POST `/metadata-updates`
|
|
197
|
+
Sends batched metadata updates periodically.
|
|
198
|
+
|
|
199
|
+
### PATCH `/users/{userId}/metadata`
|
|
200
|
+
Updates specific user metadata when userId is available.
|
|
201
|
+
|
|
202
|
+
## Backend Implementation
|
|
203
|
+
|
|
204
|
+
You'll need to implement these endpoints in your backend:
|
|
205
|
+
|
|
206
|
+
```typescript
|
|
207
|
+
// Example Express.js implementation
|
|
208
|
+
app.post('/api/user-metadata', (req, res) => {
|
|
209
|
+
const { organizationKey, metadata, timestamp } = req.body;
|
|
210
|
+
|
|
211
|
+
// Store metadata in your database
|
|
212
|
+
await UserMetadata.upsert({
|
|
213
|
+
organizationKey,
|
|
214
|
+
userId: metadata.userId || 'anonymous',
|
|
215
|
+
...metadata,
|
|
216
|
+
lastUpdated: new Date(timestamp)
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
res.json({ success: true });
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
app.post('/api/metadata-updates', (req, res) => {
|
|
223
|
+
const { organizationKey, updates, batchTimestamp } = req.body;
|
|
224
|
+
|
|
225
|
+
// Process batch updates
|
|
226
|
+
for (const update of updates) {
|
|
227
|
+
await processMetadataUpdate(organizationKey, update);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
res.json({ success: true });
|
|
231
|
+
});
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
## Privacy Considerations
|
|
235
|
+
|
|
236
|
+
- **User Agent Collection**: Can be disabled via `collectUserAgent: false`
|
|
237
|
+
- **Browser Info Collection**: Can be disabled via `collectBrowserInfo: false`
|
|
238
|
+
- **Custom Fields**: Only fields specified in `customFields` array are collected
|
|
239
|
+
- **Storage**: Can be set to `'memory'` for session-only storage without persistence
|
|
240
|
+
|
|
241
|
+
## Testing
|
|
242
|
+
|
|
243
|
+
```typescript
|
|
244
|
+
// Get current metadata
|
|
245
|
+
const metadata = guideAIRef.current?.getMetadata();
|
|
246
|
+
console.log('Current metadata:', metadata);
|
|
247
|
+
|
|
248
|
+
// Force sync metadata now
|
|
249
|
+
await guideAIRef.current?.syncMetadata();
|
|
250
|
+
|
|
251
|
+
// Track custom events
|
|
252
|
+
guideAIRef.current?.trackCustomEvent('document_viewed', {
|
|
253
|
+
documentType: 'policy',
|
|
254
|
+
documentId: 'POL-12345'
|
|
255
|
+
});
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
## Overproof Integration Example
|
|
259
|
+
|
|
260
|
+
```typescript
|
|
261
|
+
function OverproofApp() {
|
|
262
|
+
const guideAIRef = useRef();
|
|
263
|
+
|
|
264
|
+
// Track when user logs into Overproof
|
|
265
|
+
const handleOverproofLogin = (user) => {
|
|
266
|
+
guideAIRef.current?.trackLogin({
|
|
267
|
+
userId: user.id,
|
|
268
|
+
userType: user.role, // 'agent', 'admin', etc.
|
|
269
|
+
customerType: user.accountType,
|
|
270
|
+
customerLicense: user.licenseNumber,
|
|
271
|
+
customFields: {
|
|
272
|
+
agencyId: user.agencyId,
|
|
273
|
+
territory: user.territory,
|
|
274
|
+
permissions: user.permissions.join(',')
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
};
|
|
278
|
+
|
|
279
|
+
// Track when user profile is updated
|
|
280
|
+
const handleProfileUpdate = (updatedProfile) => {
|
|
281
|
+
guideAIRef.current?.updateUserInfo({
|
|
282
|
+
userType: updatedProfile.role,
|
|
283
|
+
customerLicense: updatedProfile.licenseNumber,
|
|
284
|
+
customFields: {
|
|
285
|
+
agencyId: updatedProfile.agencyId,
|
|
286
|
+
territory: updatedProfile.territory
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
return (
|
|
292
|
+
<GuideAI
|
|
293
|
+
ref={guideAIRef}
|
|
294
|
+
organizationKey="overproof-org-key"
|
|
295
|
+
metadata={{
|
|
296
|
+
config: {
|
|
297
|
+
trackVisits: true,
|
|
298
|
+
trackLogins: true,
|
|
299
|
+
syncInterval: 15000, // More frequent syncing for Overproof
|
|
300
|
+
customFields: ['agencyId', 'territory', 'permissions'],
|
|
301
|
+
collectBrowserInfo: true
|
|
302
|
+
},
|
|
303
|
+
onMetadataUpdate: (metadata) => {
|
|
304
|
+
// Send to Overproof analytics
|
|
305
|
+
window.OverproofAnalytics?.track('guideai_metadata_update', metadata);
|
|
306
|
+
}
|
|
307
|
+
}}
|
|
308
|
+
/>
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
```
|
|
312
|
+
|
|
313
|
+
## Storage and Data Persistence
|
|
314
|
+
|
|
315
|
+
- **localStorage**: Persists across browser sessions (default)
|
|
316
|
+
- **sessionStorage**: Persists only for current session
|
|
317
|
+
- **memory**: No persistence, data lost on page refresh
|
|
318
|
+
|
|
319
|
+
Metadata is automatically:
|
|
320
|
+
- Saved locally based on storage configuration
|
|
321
|
+
- Synced to backend at configured intervals
|
|
322
|
+
- Restored when user returns (if using persistent storage)
|
|
323
|
+
|
|
324
|
+
This implementation provides a robust foundation for tracking user metadata in the Overproof environment while maintaining flexibility for other use cases.
|
package/package.json
CHANGED
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
# Text Input Feature - Usage Guide
|
|
2
|
+
|
|
3
|
+
## Overview
|
|
4
|
+
|
|
5
|
+
The GuideAI package now supports text input as an alternative to voice input, allowing users to type messages instead of speaking. This feature provides better accessibility and accommodates different user preferences.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
✅ **Text Input Box**: Clean, modern text area for typing messages
|
|
10
|
+
✅ **Input Mode Toggle**: Switch between voice and text input modes
|
|
11
|
+
✅ **Keyboard Shortcuts**: Send messages with Enter key
|
|
12
|
+
✅ **Configurable Interface**: Customize placeholder text and default mode
|
|
13
|
+
✅ **Programmatic Control**: Global API methods to control input mode
|
|
14
|
+
✅ **Seamless Integration**: Works with existing conversation and transcript features
|
|
15
|
+
|
|
16
|
+
## Configuration Options
|
|
17
|
+
|
|
18
|
+
### Basic Configuration
|
|
19
|
+
|
|
20
|
+
```typescript
|
|
21
|
+
<GuideAI
|
|
22
|
+
organizationKey="your-org-key"
|
|
23
|
+
input={{
|
|
24
|
+
enableTextInput: true, // Enable text input option
|
|
25
|
+
showInputToggle: true, // Show voice/text toggle button
|
|
26
|
+
defaultMode: 'voice', // Start with voice (default)
|
|
27
|
+
placeholder: "Type here..." // Custom placeholder text
|
|
28
|
+
}}
|
|
29
|
+
/>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
### Configuration Interface
|
|
33
|
+
|
|
34
|
+
```typescript
|
|
35
|
+
interface InputConfig {
|
|
36
|
+
// Whether to enable text input functionality
|
|
37
|
+
enableTextInput?: boolean; // default: false
|
|
38
|
+
|
|
39
|
+
// Whether to show the voice/text toggle button
|
|
40
|
+
showInputToggle?: boolean; // default: true
|
|
41
|
+
|
|
42
|
+
// Default input mode when conversation starts
|
|
43
|
+
defaultMode?: 'voice' | 'text'; // default: 'voice'
|
|
44
|
+
|
|
45
|
+
// Placeholder text for the text input field
|
|
46
|
+
placeholder?: string; // default: "Type your message..."
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Usage Examples
|
|
51
|
+
|
|
52
|
+
### 1. Enable Text Input with Default Settings
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
<GuideAI
|
|
56
|
+
organizationKey="your-org-key"
|
|
57
|
+
input={{
|
|
58
|
+
enableTextInput: true
|
|
59
|
+
}}
|
|
60
|
+
/>
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 2. Start with Text Input Mode
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
<GuideAI
|
|
67
|
+
organizationKey="your-org-key"
|
|
68
|
+
input={{
|
|
69
|
+
enableTextInput: true,
|
|
70
|
+
defaultMode: 'text',
|
|
71
|
+
placeholder: "What can I help you with?"
|
|
72
|
+
}}
|
|
73
|
+
/>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### 3. Text-Only Mode (No Voice)
|
|
77
|
+
|
|
78
|
+
```typescript
|
|
79
|
+
<GuideAI
|
|
80
|
+
organizationKey="your-org-key"
|
|
81
|
+
input={{
|
|
82
|
+
enableTextInput: true,
|
|
83
|
+
showInputToggle: false, // Hide toggle button
|
|
84
|
+
defaultMode: 'text'
|
|
85
|
+
}}
|
|
86
|
+
/>
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### 4. Custom Placeholder and Configuration
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
<GuideAI
|
|
93
|
+
organizationKey="your-org-key"
|
|
94
|
+
input={{
|
|
95
|
+
enableTextInput: true,
|
|
96
|
+
showInputToggle: true,
|
|
97
|
+
defaultMode: 'voice',
|
|
98
|
+
placeholder: "Ask me anything about your insurance policy..."
|
|
99
|
+
}}
|
|
100
|
+
/>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
## User Interface
|
|
104
|
+
|
|
105
|
+
### Unified Input Interface
|
|
106
|
+
|
|
107
|
+
- **Display**: Single microphone button
|
|
108
|
+
- **Action**: Click mic to start conversation and show transcript
|
|
109
|
+
- **Text Input**: Available in the transcript box when enabled
|
|
110
|
+
- **Voice & Text**: Both options available simultaneously once conversation starts
|
|
111
|
+
|
|
112
|
+
### Text Input Box
|
|
113
|
+
|
|
114
|
+
- **Position**: Integrated at the bottom of the transcript box
|
|
115
|
+
- **Design**: Matches transcript styling with dark theme and glass effect
|
|
116
|
+
- **Components**:
|
|
117
|
+
- Compact textarea (2 rows by default)
|
|
118
|
+
- Send button with 📤 icon
|
|
119
|
+
- Seamlessly integrated with transcript design
|
|
120
|
+
|
|
121
|
+
## User Interactions
|
|
122
|
+
|
|
123
|
+
### User Flow
|
|
124
|
+
|
|
125
|
+
1. **Click Microphone**: Click the mic button to start conversation
|
|
126
|
+
2. **Transcript Appears**: Conversation transcript box opens automatically
|
|
127
|
+
3. **Choose Input Method**:
|
|
128
|
+
- **Voice**: Speak directly (microphone is active)
|
|
129
|
+
- **Text**: Type in the text input area at bottom of transcript
|
|
130
|
+
4. **Seamless Switching**: Use voice and text interchangeably in same conversation
|
|
131
|
+
|
|
132
|
+
### Sending Text Messages
|
|
133
|
+
|
|
134
|
+
1. **Enter Key**: Press Enter to send (Shift+Enter for new line)
|
|
135
|
+
2. **Send Button**: Click the 📤 button
|
|
136
|
+
3. **Programmatically**: Use `window.GuideAI.input.sendText()`
|
|
137
|
+
|
|
138
|
+
### Visual Feedback
|
|
139
|
+
|
|
140
|
+
- **Active Text Mode**: Text input appears at bottom of transcript with fade-in animation
|
|
141
|
+
- **Button States**: Send button disabled when input is empty
|
|
142
|
+
- **Focus States**: Enhanced border and background when textarea is focused
|
|
143
|
+
- **Integrated Design**: Text input seamlessly blends with transcript box styling
|
|
144
|
+
|
|
145
|
+
## Programmatic Control
|
|
146
|
+
|
|
147
|
+
### Global API Methods
|
|
148
|
+
|
|
149
|
+
Access input controls via `window.GuideAI.input`:
|
|
150
|
+
|
|
151
|
+
```typescript
|
|
152
|
+
// Toggle between voice and text input
|
|
153
|
+
window.GuideAI.input.toggleMode();
|
|
154
|
+
|
|
155
|
+
// Set specific input mode
|
|
156
|
+
window.GuideAI.input.setMode('text');
|
|
157
|
+
window.GuideAI.input.setMode('voice');
|
|
158
|
+
|
|
159
|
+
// Get current input mode
|
|
160
|
+
const currentMode = window.GuideAI.input.getMode();
|
|
161
|
+
console.log('Current mode:', currentMode); // 'voice' or 'text'
|
|
162
|
+
|
|
163
|
+
// Send text message programmatically
|
|
164
|
+
window.GuideAI.input.sendText("Hello, can you help me?");
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
### Integration Examples
|
|
168
|
+
|
|
169
|
+
#### Custom Toggle Interface
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
function MyCustomControls() {
|
|
173
|
+
const [inputMode, setInputMode] = useState('voice');
|
|
174
|
+
|
|
175
|
+
const handleModeToggle = () => {
|
|
176
|
+
window.GuideAI.input.toggleMode();
|
|
177
|
+
setInputMode(window.GuideAI.input.getMode());
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
return (
|
|
181
|
+
<div>
|
|
182
|
+
<button onClick={handleModeToggle}>
|
|
183
|
+
Current Mode: {inputMode}
|
|
184
|
+
</button>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
#### Auto-Switch to Text on Mobile
|
|
191
|
+
|
|
192
|
+
```typescript
|
|
193
|
+
useEffect(() => {
|
|
194
|
+
const isMobile = /Android|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
|
|
195
|
+
|
|
196
|
+
if (isMobile) {
|
|
197
|
+
// Switch to text mode on mobile devices
|
|
198
|
+
window.GuideAI.input.setMode('text');
|
|
199
|
+
}
|
|
200
|
+
}, []);
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
#### Keyboard Shortcuts
|
|
204
|
+
|
|
205
|
+
```typescript
|
|
206
|
+
useEffect(() => {
|
|
207
|
+
const handleKeyPress = (event) => {
|
|
208
|
+
// Switch input mode with Ctrl/Cmd + I
|
|
209
|
+
if ((event.ctrlKey || event.metaKey) && event.key === 'i') {
|
|
210
|
+
event.preventDefault();
|
|
211
|
+
window.GuideAI.input.toggleMode();
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
document.addEventListener('keydown', handleKeyPress);
|
|
216
|
+
return () => document.removeEventListener('keydown', handleKeyPress);
|
|
217
|
+
}, []);
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
## Technical Implementation
|
|
221
|
+
|
|
222
|
+
### Message Flow
|
|
223
|
+
|
|
224
|
+
1. **Text Input**: User types message and presses Enter or clicks Send
|
|
225
|
+
2. **Message Logging**: Text is logged to conversation history
|
|
226
|
+
3. **AI Communication**: Message sent to AI via WebRTC data channel
|
|
227
|
+
4. **Response Generation**: AI processes text and generates response
|
|
228
|
+
5. **Audio Response**: AI responds with voice (maintains voice output)
|
|
229
|
+
|
|
230
|
+
### Data Channel Protocol
|
|
231
|
+
|
|
232
|
+
Text messages use the same WebRTC protocol as voice:
|
|
233
|
+
|
|
234
|
+
```typescript
|
|
235
|
+
// Message structure sent to AI
|
|
236
|
+
{
|
|
237
|
+
type: "conversation.item.create",
|
|
238
|
+
item: {
|
|
239
|
+
type: "message",
|
|
240
|
+
role: "user",
|
|
241
|
+
content: [{
|
|
242
|
+
type: "input_text",
|
|
243
|
+
text: "User's typed message"
|
|
244
|
+
}]
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
## Styling and Customization
|
|
250
|
+
|
|
251
|
+
### CSS Classes
|
|
252
|
+
|
|
253
|
+
- `.guideai-icon-wrapper` - Main microphone button
|
|
254
|
+
- `.guideai-transcript-text-input` - Text input container integrated into transcript
|
|
255
|
+
- `.guideai-transcript-input-field` - Textarea element
|
|
256
|
+
- `.guideai-transcript-send-button` - Send button
|
|
257
|
+
- `.guideai-transcript-send-icon` - Send button icon
|
|
258
|
+
|
|
259
|
+
### Custom Styling Example
|
|
260
|
+
|
|
261
|
+
```css
|
|
262
|
+
/* Custom text input styling */
|
|
263
|
+
.guideai-transcript-input-field {
|
|
264
|
+
font-family: 'Your Custom Font', sans-serif;
|
|
265
|
+
border-radius: 12px;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.guideai-transcript-send-button {
|
|
269
|
+
background: linear-gradient(45deg, #ff6b6b, #ee5a52);
|
|
270
|
+
}
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
## Accessibility Features
|
|
274
|
+
|
|
275
|
+
- **Keyboard Navigation**: Full keyboard support
|
|
276
|
+
- **Screen Readers**: Proper ARIA labels and semantic HTML
|
|
277
|
+
- **Focus Management**: Clear focus indicators
|
|
278
|
+
- **Alternative Input**: Text alternative for voice-only interface
|
|
279
|
+
|
|
280
|
+
## Best Practices
|
|
281
|
+
|
|
282
|
+
### For Implementation
|
|
283
|
+
|
|
284
|
+
1. **Test Both Modes**: Ensure voice and text modes work seamlessly
|
|
285
|
+
2. **Mobile Optimization**: Consider defaulting to text on mobile
|
|
286
|
+
3. **Clear Instructions**: Provide users with clear mode indicators
|
|
287
|
+
4. **Error Handling**: Handle cases where WebRTC isn't available
|
|
288
|
+
|
|
289
|
+
### For User Experience
|
|
290
|
+
|
|
291
|
+
1. **Mode Persistence**: Consider remembering user's preferred mode
|
|
292
|
+
2. **Visual Feedback**: Ensure users know which mode is active
|
|
293
|
+
3. **Quick Switching**: Make it easy to switch between modes
|
|
294
|
+
4. **Responsive Design**: Ensure text input works on all screen sizes
|
|
295
|
+
|
|
296
|
+
## Troubleshooting
|
|
297
|
+
|
|
298
|
+
### Text Input Not Appearing
|
|
299
|
+
|
|
300
|
+
Check that:
|
|
301
|
+
1. `enableTextInput` is set to `true`
|
|
302
|
+
2. Conversation is active
|
|
303
|
+
3. Input mode is set to 'text'
|
|
304
|
+
4. CSS styles are loaded
|
|
305
|
+
|
|
306
|
+
### Toggle Button Not Showing
|
|
307
|
+
|
|
308
|
+
Ensure:
|
|
309
|
+
1. `showInputToggle` is not set to `false`
|
|
310
|
+
2. `enableTextInput` is `true`
|
|
311
|
+
3. Conversation is active
|
|
312
|
+
|
|
313
|
+
### Messages Not Sending
|
|
314
|
+
|
|
315
|
+
Verify:
|
|
316
|
+
1. WebRTC connection is established
|
|
317
|
+
2. Conversation is active
|
|
318
|
+
3. Input is not empty
|
|
319
|
+
4. No JavaScript errors in console
|
|
320
|
+
|
|
321
|
+
This text input feature provides a comprehensive alternative to voice input while maintaining the seamless conversation experience that GuideAI is known for.
|