ttp-agent-sdk 2.5.3 → 2.5.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.
@@ -1,20 +1,29 @@
1
- # Enhanced AgentWidget - Complete Customization Guide
1
+ # TTPChatWidget - Complete Customization Guide
2
2
 
3
- The `EnhancedAgentWidget` provides extensive customization options while maintaining sensible defaults. Users can customize icons, positioning, colors, animations, and much more.
3
+ The `TTPChatWidget` provides extensive customization options while maintaining sensible defaults. Users can customize icons, positioning, colors, animations, and much more.
4
4
 
5
5
  ## Quick Start
6
6
 
7
7
  ```javascript
8
- import { EnhancedAgentWidget } from 'ttp-agent-sdk';
8
+ import { TTPChatWidget } from 'ttp-agent-sdk';
9
9
 
10
- // Minimal configuration (uses all defaults)
11
- new EnhancedAgentWidget({
10
+ // Minimal configuration with signed URL (uses all defaults)
11
+ new TTPChatWidget({
12
12
  agentId: 'your_agent_id',
13
- getSessionUrl: async ({ agentId, variables }) => {
13
+ signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=eyJ...' // Direct signed URL
14
+ });
15
+ ```
16
+
17
+ Or use a function to fetch the signed URL:
18
+
19
+ ```javascript
20
+ new TTPChatWidget({
21
+ agentId: 'your_agent_id',
22
+ signedUrl: async () => {
14
23
  const response = await fetch('/api/get-session', {
15
24
  method: 'POST',
16
25
  headers: { 'Content-Type': 'application/json' },
17
- body: JSON.stringify({ agentId, variables })
26
+ body: JSON.stringify({ agentId: 'your_agent_id' })
18
27
  });
19
28
  const data = await response.json();
20
29
  return data.signedUrl;
@@ -29,10 +38,14 @@ new EnhancedAgentWidget({
29
38
  ```javascript
30
39
  {
31
40
  agentId: 'your_agent_id', // Required: Your agent ID
32
- getSessionUrl: async ({ agentId, variables }) => { ... } // Required: Function to get signed URL
41
+ signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=...' // Required: Signed URL (string or async function)
33
42
  }
34
43
  ```
35
44
 
45
+ **Signed URL Options:**
46
+ - **Direct string**: `signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=...'`
47
+ - **Function**: `signedUrl: async () => { const data = await fetch(...); return data.signedUrl; }`
48
+
36
49
  ### Icon/Image Configuration
37
50
 
38
51
  ```javascript
@@ -194,7 +207,7 @@ position: {
194
207
  ```javascript
195
208
  {
196
209
  customStyles: `
197
- #enhanced-agent-widget {
210
+ #text-chat-panel {
198
211
  /* Your custom CSS here */
199
212
  }
200
213
  `
@@ -204,20 +217,20 @@ position: {
204
217
  ## Complete Example
205
218
 
206
219
  ```javascript
207
- import { EnhancedAgentWidget } from 'ttp-agent-sdk';
220
+ import { TTPChatWidget } from 'ttp-agent-sdk';
221
+
222
+ // Get signed URL from backend
223
+ const response = await fetch('/api/get-session', {
224
+ method: 'POST',
225
+ headers: { 'Content-Type': 'application/json' },
226
+ body: JSON.stringify({ agentId: 'my_agent_123' })
227
+ });
228
+ const data = await response.json();
208
229
 
209
- const widget = new EnhancedAgentWidget({
230
+ const widget = new TTPChatWidget({
210
231
  // Required
211
232
  agentId: 'my_agent_123',
212
- getSessionUrl: async ({ agentId, variables }) => {
213
- const response = await fetch('/api/get-session', {
214
- method: 'POST',
215
- headers: { 'Content-Type': 'application/json' },
216
- body: JSON.stringify({ agentId, variables })
217
- });
218
- const data = await response.json();
219
- return data.signedUrl;
220
- },
233
+ signedUrl: data.signedUrl, // Use signed URL directly
221
234
 
222
235
  // Custom icon (company logo)
223
236
  icon: {
@@ -302,22 +315,23 @@ widget.updateConfig({
302
315
  widget.destroy();
303
316
  ```
304
317
 
305
- ## Migration from Original AgentWidget
318
+ ## Widget Modes
306
319
 
307
- The enhanced widget is fully backward compatible. Simply replace:
320
+ The `TTPChatWidget` supports three modes:
308
321
 
309
- ```javascript
310
- // Old
311
- import { AgentWidget } from 'ttp-agent-sdk';
312
- new AgentWidget({ ... });
322
+ - `'unified'` (default) - Shows landing screen with both voice and text options
323
+ - `'voice-only'` - Only voice interface, no text chat
324
+ - `'text-only'` - Only text chat interface, no voice
313
325
 
314
- // New
315
- import { EnhancedAgentWidget } from 'ttp-agent-sdk';
316
- new EnhancedAgentWidget({ ... });
326
+ ```javascript
327
+ new TTPChatWidget({
328
+ agentId: 'your_agent_id',
329
+ behavior: {
330
+ mode: 'unified' // or 'voice-only' or 'text-only'
331
+ }
332
+ });
317
333
  ```
318
334
 
319
- All existing configurations will work with sensible defaults applied.
320
-
321
335
  ## Browser Support
322
336
 
323
337
  - Chrome 66+
@@ -30,11 +30,11 @@ npm install ttp-agent-sdk
30
30
  // Initialize the voice widget
31
31
  TTPAgentSDK.AgentWidget.init({
32
32
  agentId: 'your_agent_id',
33
- getSessionUrl: async ({ agentId, variables }) => {
33
+ signedUrl: async () => {
34
34
  const response = await fetch('/api/get-session', {
35
35
  method: 'POST',
36
36
  headers: { 'Content-Type': 'application/json' },
37
- body: JSON.stringify({ agentId, variables })
37
+ body: JSON.stringify({ agentId: 'your_agent_id' })
38
38
  });
39
39
  const data = await response.json();
40
40
  return data.signedUrl;
@@ -143,7 +143,7 @@ const voiceSDK = new VoiceSDK({
143
143
  ```javascript
144
144
  TTPAgentSDK.AgentWidget.init({
145
145
  agentId: 'your_agent_id', // Required
146
- getSessionUrl: 'https://...', // Required - URL or function
146
+ signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=...', // Required - Signed URL (string or async function)
147
147
  variables: { // Optional - dynamic variables
148
148
  userName: 'John Doe',
149
149
  page: 'homepage'
package/README.md CHANGED
@@ -65,20 +65,36 @@ await voiceSDK.connect();
65
65
  ```html
66
66
  <script src="https://unpkg.com/ttp-agent-sdk/dist/agent-widget.js"></script>
67
67
  <script>
68
- TTPAgentSDK.AgentWidget.init({
68
+ // Get signed URL from your backend first
69
+ const response = await fetch('/api/get-session', {
70
+ method: 'POST',
71
+ headers: { 'Content-Type': 'application/json' },
72
+ body: JSON.stringify({ agentId: 'your_agent_id' })
73
+ });
74
+ const data = await response.json();
75
+
76
+ // Use the signed URL directly
77
+ new TTPAgentSDK.TTPChatWidget({
78
+ agentId: 'your_agent_id',
79
+ signedUrl: data.signedUrl
80
+ });
81
+ </script>
82
+ ```
83
+
84
+ Or use a function to fetch the signed URL:
85
+
86
+ ```html
87
+ <script>
88
+ new TTPAgentSDK.TTPChatWidget({
69
89
  agentId: 'your_agent_id',
70
- getSessionUrl: async ({ agentId, variables }) => {
90
+ signedUrl: async () => {
71
91
  const response = await fetch('/api/get-session', {
72
92
  method: 'POST',
73
93
  headers: { 'Content-Type': 'application/json' },
74
- body: JSON.stringify({ agentId, variables })
94
+ body: JSON.stringify({ agentId: 'your_agent_id' })
75
95
  });
76
96
  const data = await response.json();
77
97
  return data.signedUrl;
78
- },
79
- variables: {
80
- userName: 'John Doe',
81
- page: 'homepage'
82
98
  }
83
99
  });
84
100
  </script>
@@ -28,7 +28,7 @@ User's Frontend → User's Backend → TTP UI Backend → TTP Conversation Backe
28
28
  ### ❌ **Direct Agent ID (Insecure)**
29
29
  ```javascript
30
30
  // DON'T DO THIS IN PRODUCTION
31
- new EnhancedAgentWidget({
31
+ new TTPChatWidget({
32
32
  agentId: 'agent_12345', // ❌ Visible in network traffic
33
33
  websocketUrl: 'wss://speech.talktopc.com/ws/conv'
34
34
  });
@@ -42,15 +42,23 @@ new EnhancedAgentWidget({
42
42
 
43
43
  ### ✅ **Signed Link (Secure)**
44
44
  ```javascript
45
- // PRODUCTION-READY APPROACH
46
- new EnhancedAgentWidget({
47
- agentId: 'agent_12345',
48
- getSessionUrl: async ({ agentId, variables }) => {
45
+ // PRODUCTION-READY APPROACH - Option 1: Direct signed URL
46
+ new TTPChatWidget({
47
+ agentId: 'agent_12345', // Still needed for widget initialization
48
+ signedUrl: 'wss://speech.talktopc.com/ws/conv?signed_token=eyJ...' // Direct signed URL
49
+ });
50
+ ```
51
+
52
+ ```javascript
53
+ // PRODUCTION-READY APPROACH - Option 2: Get signed URL from backend
54
+ new TTPChatWidget({
55
+ agentId: 'your_agent_id',
56
+ signedUrl: async () => {
49
57
  // User's Frontend calls User's Backend
50
58
  const response = await fetch('/api/get-voice-session', {
51
59
  method: 'POST',
52
60
  headers: { 'Content-Type': 'application/json' },
53
- body: JSON.stringify({ agentId, variables })
61
+ body: JSON.stringify({ agentId: 'your_agent_id' })
54
62
  });
55
63
  const data = await response.json();
56
64
  return data.signedUrl; // ✅ Secure, time-limited URL from TTP
@@ -120,73 +128,96 @@ app.post('/api/get-voice-session', async (req, res) => {
120
128
 
121
129
  ### Step 2: User's Frontend Integration
122
130
 
131
+ **Option 1: Direct Signed URL (Simplest)**
132
+
123
133
  ```javascript
124
- import { EnhancedAgentWidget } from 'ttp-agent-sdk';
134
+ import { TTPChatWidget } from 'ttp-agent-sdk';
135
+
136
+ // Get signed URL from your backend first
137
+ const response = await fetch('/api/get-voice-session', {
138
+ method: 'POST',
139
+ headers: {
140
+ 'Content-Type': 'application/json',
141
+ 'Authorization': `Bearer ${getAuthToken()}`
142
+ },
143
+ body: JSON.stringify({
144
+ agentId: 'your_agent_id',
145
+ variables: {
146
+ page: 'homepage',
147
+ userType: 'customer'
148
+ }
149
+ })
150
+ });
151
+
152
+ const data = await response.json();
125
153
 
126
- new EnhancedAgentWidget({
154
+ // Use the signed URL directly
155
+ new TTPChatWidget({
156
+ agentId: 'your_agent_id', // Still needed for widget initialization
157
+ signedUrl: data.signedUrl // ✅ Direct signed URL
158
+ });
159
+ ```
160
+
161
+ **Option 2: Function that Returns Signed URL**
162
+
163
+ ```javascript
164
+ import { TTPChatWidget } from 'ttp-agent-sdk';
165
+
166
+ new TTPChatWidget({
127
167
  agentId: 'your_agent_id',
128
168
 
129
- // User's Frontend calls User's Backend
130
- getSessionUrl: async ({ agentId, variables }) => {
131
- try {
132
- const response = await fetch('/api/get-voice-session', {
133
- method: 'POST',
134
- headers: {
135
- 'Content-Type': 'application/json',
136
- 'Authorization': `Bearer ${getAuthToken()}` // User's auth token
137
- },
138
- body: JSON.stringify({
139
- agentId,
140
- variables: {
141
- ...variables,
142
- page: 'homepage',
143
- userType: 'customer'
144
- }
145
- })
146
- });
147
-
148
- if (!response.ok) {
149
- throw new Error(`Your backend responded with ${response.status}`);
150
- }
151
-
152
- const data = await response.json();
153
- return data.signedUrl; // This connects directly to TTP Conversation Backend
154
-
155
- } catch (error) {
156
- console.error('Failed to get signed URL from your backend:', error);
157
- throw error;
169
+ // Function that fetches and returns signed URL
170
+ signedUrl: async () => {
171
+ const response = await fetch('/api/get-voice-session', {
172
+ method: 'POST',
173
+ headers: {
174
+ 'Content-Type': 'application/json',
175
+ 'Authorization': `Bearer ${getAuthToken()}`
176
+ },
177
+ body: JSON.stringify({
178
+ agentId: 'your_agent_id',
179
+ variables: {
180
+ page: 'homepage',
181
+ userType: 'customer'
182
+ }
183
+ })
184
+ });
185
+
186
+ if (!response.ok) {
187
+ throw new Error(`Your backend responded with ${response.status}`);
158
188
  }
159
- },
160
-
161
- variables: {
162
- page: 'homepage',
163
- userType: 'customer',
164
- language: 'en'
189
+
190
+ const data = await response.json();
191
+ return data.signedUrl; // This connects directly to TTP Conversation Backend
165
192
  }
166
193
  });
167
194
  ```
168
195
 
169
196
  ## 🔧 Your Current Implementation
170
197
 
171
- Based on your setup, you're already using this pattern:
198
+ Based on your setup, you can use signed URLs like this:
172
199
 
173
200
  ```javascript
174
- // Your current LandingPageWidget.jsx
175
- getSessionUrl: async ({ agentId, variables }) => {
176
- const response = await fetch(buildApiUrl('/api/landing/signed-url'), {
177
- method: 'POST',
178
- headers: { 'Content-Type': 'application/json' },
179
- body: JSON.stringify({
180
- agentId: agentId,
181
- variables: variables,
201
+ // Get signed URL from your backend
202
+ const response = await fetch(buildApiUrl('/api/landing/signed-url'), {
203
+ method: 'POST',
204
+ headers: { 'Content-Type': 'application/json' },
205
+ body: JSON.stringify({
206
+ agentId: 'your_agent_id',
207
+ variables: {
182
208
  page: 'landing',
183
209
  userType: 'visitor'
184
- })
185
- });
186
-
187
- const data = await response.json();
188
- return data.signedUrl; // This connects to conversation backend
189
- }
210
+ }
211
+ })
212
+ });
213
+
214
+ const data = await response.json();
215
+
216
+ // Use the signed URL directly
217
+ new TTPChatWidget({
218
+ agentId: 'your_agent_id',
219
+ signedUrl: data.signedUrl // ✅ Direct signed URL
220
+ });
190
221
  ```
191
222
 
192
223
  ## 🎯 Key Points
@@ -173,12 +173,15 @@ For production, use **signed links** instead of exposing agent IDs. Here's how:
173
173
  appId: 'app_bQHDFqydfNPl75MZNijXc4dUyHGqnHeX9e5l',
174
174
  behavior: { mode: 'unified' },
175
175
 
176
- // Use your backend to generate signed URLs
177
- getSessionUrl: async ({ agentId, appId, variables }) => {
176
+ // Use signed URL from your backend
177
+ signedUrl: async () => {
178
178
  const response = await fetch('https://your-backend.com/api/get-session', {
179
179
  method: 'POST',
180
180
  headers: { 'Content-Type': 'application/json' },
181
- body: JSON.stringify({ agentId, appId, variables })
181
+ body: JSON.stringify({
182
+ agentId: 'agent_f676e962a',
183
+ appId: 'app_bQHDFqydfNPl75MZNijXc4dUyHGqnHeX9e5l'
184
+ })
182
185
  });
183
186
  const data = await response.json();
184
187
  return data.signedUrl;