ttp-agent-sdk 2.18.0 → 2.20.0
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/dist/agent-widget.js +1 -1
- package/dist/agent-widget.js.map +1 -1
- package/dist/demos/test-widget.html +208 -109
- package/dist/examples/test-widget.html +208 -109
- package/examples/test-widget.html +208 -109
- package/package.json +1 -1
|
@@ -329,9 +329,9 @@
|
|
|
329
329
|
</div>
|
|
330
330
|
|
|
331
331
|
<div class="button-group">
|
|
332
|
-
<button class="btn btn-primary"
|
|
333
|
-
<button class="btn btn-secondary"
|
|
334
|
-
<button class="btn btn-secondary"
|
|
332
|
+
<button class="btn btn-primary" id="initBtn">Initialize Widget</button>
|
|
333
|
+
<button class="btn btn-secondary" id="destroyBtn">Destroy Widget</button>
|
|
334
|
+
<button class="btn btn-secondary" id="resetBtn">Reset Config</button>
|
|
335
335
|
</div>
|
|
336
336
|
|
|
337
337
|
<div id="status" class="status" style="display: none;">
|
|
@@ -357,129 +357,228 @@
|
|
|
357
357
|
</div>
|
|
358
358
|
</div>
|
|
359
359
|
|
|
360
|
-
<!-- Load SDK -->
|
|
361
|
-
<script
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (!window.TTPChatWidget) {
|
|
371
|
-
alert('TTPChatWidget is not available. Check browser console for errors.');
|
|
372
|
-
console.error('TTPChatWidget is undefined');
|
|
360
|
+
<!-- Load SDK as UMD library (script tag) -->
|
|
361
|
+
<script src="../agent-widget.js" onload="console.log('✅ SDK script loaded, TTPAgentSDK:', typeof window.TTPAgentSDK)" onerror="console.error('❌ Failed to load SDK script')"></script>
|
|
362
|
+
<script>
|
|
363
|
+
console.log('🔵 Waiting for SDK to load...');
|
|
364
|
+
|
|
365
|
+
// Wait for TTPAgentSDK to be available (UMD library loads as global)
|
|
366
|
+
function initSDK() {
|
|
367
|
+
if (typeof window.TTPAgentSDK === 'undefined') {
|
|
368
|
+
console.log('⏳ TTPAgentSDK not ready yet, waiting...');
|
|
369
|
+
setTimeout(initSDK, 100);
|
|
373
370
|
return;
|
|
374
371
|
}
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
const
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
372
|
+
|
|
373
|
+
console.log('✅ TTPAgentSDK loaded:', window.TTPAgentSDK);
|
|
374
|
+
console.log('✅ TTPAgentSDK keys:', Object.keys(window.TTPAgentSDK || {}));
|
|
375
|
+
|
|
376
|
+
const TTPChatWidget = window.TTPAgentSDK?.TTPChatWidget;
|
|
377
|
+
console.log('✅ TTPChatWidget:', TTPChatWidget);
|
|
378
|
+
console.log('✅ TTPChatWidget type:', typeof TTPChatWidget);
|
|
379
|
+
|
|
380
|
+
if (!TTPChatWidget) {
|
|
381
|
+
console.error('❌ TTPChatWidget is undefined');
|
|
382
|
+
console.error('Available in TTPAgentSDK:', Object.keys(window.TTPAgentSDK || {}));
|
|
383
|
+
alert('TTPChatWidget is not available. Check console for errors.');
|
|
386
384
|
return;
|
|
387
385
|
}
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
386
|
+
|
|
387
|
+
window.TTPChatWidget = TTPChatWidget;
|
|
388
|
+
window.widgetInstance = null;
|
|
389
|
+
|
|
390
|
+
// Define functions after module loads
|
|
391
|
+
window.initializeWidget = function() {
|
|
392
|
+
console.log('🔵 ===== initializeWidget CALLED =====');
|
|
393
|
+
console.log('🔵 TTPChatWidget available:', !!window.TTPChatWidget);
|
|
394
|
+
console.log('🔵 TTPChatWidget type:', typeof window.TTPChatWidget);
|
|
395
|
+
|
|
396
|
+
if (!window.TTPChatWidget) {
|
|
397
|
+
alert('TTPChatWidget is not available. Check browser console for errors.');
|
|
398
|
+
console.error('TTPChatWidget is undefined');
|
|
399
|
+
return;
|
|
400
|
+
}
|
|
401
|
+
const agentId = document.getElementById('agentId').value;
|
|
402
|
+
const appId = document.getElementById('appId').value;
|
|
403
|
+
const getSessionUrl = document.getElementById('getSessionUrl').value;
|
|
404
|
+
const websocketUrl = document.getElementById('websocketUrl').value;
|
|
405
|
+
const position = document.getElementById('position').value;
|
|
406
|
+
const language = document.getElementById('language').value;
|
|
407
|
+
const mode = document.getElementById('mode').value;
|
|
408
|
+
const primaryColor = document.getElementById('primaryColor').value;
|
|
409
|
+
|
|
410
|
+
if (!agentId || !appId) {
|
|
411
|
+
alert('Please provide Agent ID and App ID');
|
|
412
|
+
return;
|
|
408
413
|
}
|
|
409
414
|
|
|
410
|
-
if
|
|
411
|
-
|
|
415
|
+
// Destroy existing widget if any
|
|
416
|
+
if (window.widgetInstance) {
|
|
417
|
+
window.destroyWidget();
|
|
412
418
|
}
|
|
413
419
|
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
420
|
+
try {
|
|
421
|
+
const config = {
|
|
422
|
+
agentId: agentId,
|
|
423
|
+
appId: appId,
|
|
424
|
+
language: language,
|
|
425
|
+
primaryColor: primaryColor,
|
|
426
|
+
behavior: {
|
|
427
|
+
mode: mode
|
|
428
|
+
}
|
|
421
429
|
};
|
|
422
|
-
}
|
|
423
430
|
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
// Update status
|
|
430
|
-
document.getElementById('status').style.display = 'block';
|
|
431
|
-
document.getElementById('statusText').textContent = 'Widget initialized';
|
|
432
|
-
document.getElementById('widgetStatus').textContent = 'Yes';
|
|
433
|
-
|
|
434
|
-
console.log('✅ Widget initialized successfully');
|
|
435
|
-
} catch (error) {
|
|
436
|
-
console.error('❌ Error initializing widget:', error);
|
|
437
|
-
alert('Error initializing widget: ' + error.message);
|
|
438
|
-
document.getElementById('statusText').textContent = 'Error: ' + error.message;
|
|
439
|
-
}
|
|
440
|
-
};
|
|
431
|
+
// Add optional configs
|
|
432
|
+
if (getSessionUrl) {
|
|
433
|
+
config.getSessionUrl = getSessionUrl;
|
|
434
|
+
}
|
|
441
435
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
try {
|
|
445
|
-
// Widget doesn't have a destroy method, but we can remove it from DOM
|
|
446
|
-
const widgetButton = document.getElementById('text-chat-button');
|
|
447
|
-
const widgetPanel = document.getElementById('text-chat-panel');
|
|
448
|
-
|
|
449
|
-
if (widgetButton && widgetButton.parentNode) {
|
|
450
|
-
widgetButton.parentNode.removeChild(widgetButton);
|
|
436
|
+
if (websocketUrl) {
|
|
437
|
+
config.websocketUrl = websocketUrl;
|
|
451
438
|
}
|
|
452
|
-
|
|
453
|
-
|
|
439
|
+
|
|
440
|
+
// Handle position
|
|
441
|
+
if (position) {
|
|
442
|
+
const [vertical, horizontal] = position.split('-');
|
|
443
|
+
config.position = {
|
|
444
|
+
vertical: vertical,
|
|
445
|
+
horizontal: horizontal,
|
|
446
|
+
offset: { x: 20, y: 20 }
|
|
447
|
+
};
|
|
454
448
|
}
|
|
455
449
|
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
console.log('
|
|
450
|
+
console.log('Initializing widget with config:', config);
|
|
451
|
+
console.log('TTPChatWidget constructor:', window.TTPChatWidget);
|
|
452
|
+
window.widgetInstance = new window.TTPChatWidget(config);
|
|
453
|
+
console.log('Widget instance created:', window.widgetInstance);
|
|
454
|
+
|
|
455
|
+
// Update status
|
|
456
|
+
document.getElementById('status').style.display = 'block';
|
|
457
|
+
document.getElementById('statusText').textContent = 'Widget initialized';
|
|
458
|
+
document.getElementById('widgetStatus').textContent = 'Yes';
|
|
459
|
+
|
|
460
|
+
console.log('✅ Widget initialized successfully');
|
|
460
461
|
} catch (error) {
|
|
461
|
-
console.error('❌ Error
|
|
462
|
+
console.error('❌ Error initializing widget:', error);
|
|
463
|
+
alert('Error initializing widget: ' + error.message);
|
|
464
|
+
document.getElementById('statusText').textContent = 'Error: ' + error.message;
|
|
465
|
+
}
|
|
466
|
+
};
|
|
467
|
+
|
|
468
|
+
window.destroyWidget = function() {
|
|
469
|
+
if (window.widgetInstance) {
|
|
470
|
+
try {
|
|
471
|
+
// Widget doesn't have a destroy method, but we can remove it from DOM
|
|
472
|
+
const widgetButton = document.getElementById('text-chat-button');
|
|
473
|
+
const widgetPanel = document.getElementById('text-chat-panel');
|
|
474
|
+
|
|
475
|
+
if (widgetButton && widgetButton.parentNode) {
|
|
476
|
+
widgetButton.parentNode.removeChild(widgetButton);
|
|
477
|
+
}
|
|
478
|
+
if (widgetPanel && widgetPanel.parentNode) {
|
|
479
|
+
widgetPanel.parentNode.removeChild(widgetPanel);
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
window.widgetInstance = null;
|
|
483
|
+
document.getElementById('statusText').textContent = 'Widget destroyed';
|
|
484
|
+
document.getElementById('widgetStatus').textContent = 'No';
|
|
485
|
+
console.log('✅ Widget destroyed');
|
|
486
|
+
} catch (error) {
|
|
487
|
+
console.error('❌ Error destroying widget:', error);
|
|
488
|
+
}
|
|
462
489
|
}
|
|
490
|
+
};
|
|
491
|
+
|
|
492
|
+
window.resetConfig = function() {
|
|
493
|
+
document.getElementById('agentId').value = 'agent_e5cf06457';
|
|
494
|
+
document.getElementById('appId').value = 'app_Bc01EqMQt2Euehl4qqZSi6l3FJP42Q9vJ0pC';
|
|
495
|
+
document.getElementById('getSessionUrl').value = '';
|
|
496
|
+
document.getElementById('websocketUrl').value = 'wss://speech.talktopc.com/ws/conv';
|
|
497
|
+
document.getElementById('position').value = 'bottom-right';
|
|
498
|
+
document.getElementById('language').value = 'en';
|
|
499
|
+
document.getElementById('mode').value = 'unified';
|
|
500
|
+
document.getElementById('primaryColor').value = '#7C3AED';
|
|
501
|
+
};
|
|
502
|
+
|
|
503
|
+
// Attach event listeners to buttons after module loads
|
|
504
|
+
function attachButtonListeners() {
|
|
505
|
+
const buttons = document.querySelectorAll('.button-group button');
|
|
506
|
+
console.log('🔵 Setting up button listeners, found buttons:', buttons.length);
|
|
507
|
+
|
|
508
|
+
if (buttons.length === 0) {
|
|
509
|
+
console.warn('⚠️ No buttons found, retrying in 100ms...');
|
|
510
|
+
setTimeout(attachButtonListeners, 100);
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
buttons.forEach(btn => {
|
|
515
|
+
const btnText = btn.textContent.trim();
|
|
516
|
+
console.log('🔵 Processing button:', btnText);
|
|
517
|
+
|
|
518
|
+
// Remove existing onclick to avoid conflicts
|
|
519
|
+
const onclickAttr = btn.getAttribute('onclick');
|
|
520
|
+
if (onclickAttr) {
|
|
521
|
+
btn.removeAttribute('onclick');
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
// Remove any existing listeners by cloning
|
|
525
|
+
const newBtn = btn.cloneNode(true);
|
|
526
|
+
btn.parentNode.replaceChild(newBtn, btn);
|
|
527
|
+
|
|
528
|
+
// Attach new listener based on button text
|
|
529
|
+
if (btnText === 'Initialize Widget' || onclickAttr === 'initializeWidget()') {
|
|
530
|
+
newBtn.addEventListener('click', (e) => {
|
|
531
|
+
e.preventDefault();
|
|
532
|
+
e.stopPropagation();
|
|
533
|
+
console.log('🔵 Init button clicked!');
|
|
534
|
+
console.log('window.initializeWidget available:', typeof window.initializeWidget);
|
|
535
|
+
if (typeof window.initializeWidget === 'function') {
|
|
536
|
+
window.initializeWidget();
|
|
537
|
+
} else {
|
|
538
|
+
console.error('❌ initializeWidget is not a function:', typeof window.initializeWidget);
|
|
539
|
+
alert('Error: initializeWidget function not available. Check console for details.');
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
} else if (btnText === 'Destroy Widget' || onclickAttr === 'destroyWidget()') {
|
|
543
|
+
newBtn.addEventListener('click', (e) => {
|
|
544
|
+
e.preventDefault();
|
|
545
|
+
e.stopPropagation();
|
|
546
|
+
if (typeof window.destroyWidget === 'function') {
|
|
547
|
+
window.destroyWidget();
|
|
548
|
+
}
|
|
549
|
+
});
|
|
550
|
+
} else if (btnText === 'Reset Config' || onclickAttr === 'resetConfig()') {
|
|
551
|
+
newBtn.addEventListener('click', (e) => {
|
|
552
|
+
e.preventDefault();
|
|
553
|
+
e.stopPropagation();
|
|
554
|
+
if (typeof window.resetConfig === 'function') {
|
|
555
|
+
window.resetConfig();
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
});
|
|
560
|
+
|
|
561
|
+
console.log('✅ Button event listeners attached successfully');
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
// Try to attach immediately (if DOM is ready) or wait for DOMContentLoaded
|
|
565
|
+
if (document.readyState === 'loading') {
|
|
566
|
+
window.addEventListener('DOMContentLoaded', attachButtonListeners);
|
|
567
|
+
} else {
|
|
568
|
+
// DOM is already loaded
|
|
569
|
+
setTimeout(attachButtonListeners, 100);
|
|
463
570
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
};
|
|
476
|
-
|
|
477
|
-
// Auto-initialize on load (optional)
|
|
478
|
-
// window.addEventListener('DOMContentLoaded', () => {
|
|
479
|
-
// setTimeout(() => {
|
|
480
|
-
// window.initializeWidget();
|
|
481
|
-
// }, 1000);
|
|
482
|
-
// });
|
|
571
|
+
|
|
572
|
+
// Also expose functions globally for direct access
|
|
573
|
+
console.log('✅ Functions exposed to window:', {
|
|
574
|
+
initializeWidget: typeof window.initializeWidget,
|
|
575
|
+
destroyWidget: typeof window.destroyWidget,
|
|
576
|
+
resetConfig: typeof window.resetConfig
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Start initialization
|
|
581
|
+
initSDK();
|
|
483
582
|
</script>
|
|
484
583
|
</body>
|
|
485
584
|
</html>
|