jjmandog commited on
Commit
8ca63d1
·
verified ·
1 Parent(s): 661165a

Installl websocket or anything similar for real call interaction - Follow Up Deployment

Browse files
Files changed (2) hide show
  1. index.html +273 -79
  2. prompts.txt +6 -1
index.html CHANGED
@@ -31,6 +31,14 @@
31
  background: rgba(99, 102, 241, 0.5);
32
  border-radius: 3px;
33
  }
 
 
 
 
 
 
 
 
34
  /* Call animation */
35
  .call-animation {
36
  position: relative;
@@ -299,8 +307,46 @@
299
  </div>
300
  </div>
301
 
302
- <!-- Container for Jitsi meetings (hidden by default) -->
303
- <div id="jitsi-container" style="display: none;"></div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
304
 
305
  <!-- Training Modal -->
306
  <div id="trainingModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden">
@@ -449,9 +495,9 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
449
  </div>
450
 
451
  <div class="flex items-center space-x-2 mb-4">
452
- <button id="verifyTwilioBtn" class="py-2 px-3 bg-blue-600 hover:bg-blue-700 text-white rounded-lg text-sm flex items-center">
453
  <i class="fas fa-check-circle mr-2"></i>
454
- Verify Twilio
455
  </button>
456
  <button onclick="window.open('https://console.twilio.com', '_blank')"
457
  class="py-2 px-3 bg-gray-200 hover:bg-gray-300 rounded-lg text-sm flex items-center">
@@ -534,9 +580,10 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
534
  </div>
535
 
536
  <script>
537
- // Jitsi Client Setup
538
  let jitsiClient;
539
  let callSocket;
 
540
 
541
  async function initializeJitsiClient() {
542
  try {
@@ -562,20 +609,37 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
562
  }
563
  };
564
 
565
- // Use a simple WebSocket connection (you would replace with your own endpoint)
566
- callSocket = new WebSocket('wss://realtime.trillion.ventures/ws');
567
- setTimeout(() => {
568
- if (callSocket.onopen) callSocket.onopen();
569
- }, 500);
570
  callSocket.onopen = () => {
571
- console.log('Connected to Trillion real-time service');
 
572
  callSocket.send(JSON.stringify({
573
  type: 'authenticate',
574
- token: authToken
 
575
  }));
576
  };
577
- callSocket.onmessage = handleSocketMessage;
578
- callSocket.onclose = () => console.log('Disconnected from real-time service');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
579
 
580
  return true;
581
  } catch (error) {
@@ -584,21 +648,67 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
584
  }
585
  }
586
 
587
- function handleSocketMessage(event) {
588
- const data = JSON.parse(event.data);
589
  switch(data.type) {
590
  case 'call_update':
591
  updateCallUI(data.status, data.transcript);
592
  break;
593
- case 'message':
594
- console.log("New message:", data.content);
 
 
 
 
 
 
 
 
 
595
  break;
596
- case 'call_ended':
597
- endCallUI(data.callId);
598
  break;
599
  }
600
  }
601
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
602
  async function sendSMS(to, message) {
603
  try {
604
  const response = await fetch('/api/send-sms', {
@@ -665,31 +775,50 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
665
  }
666
  });
667
 
668
- // Training modal
669
- const trainingModal = document.getElementById('trainingModal');
670
- const trainBtn = document.getElementById('trainAIbtn');
671
- const closeTraining = document.getElementById('closeTraining');
672
-
673
- trainBtn.addEventListener('click', () => {
674
- trainingModal.classList.remove('hidden');
675
- showTrainingSection('qa'); // Default to Q&A section
676
- });
677
-
678
- closeTraining.addEventListener('click', () => {
679
- trainingModal.classList.add('hidden');
680
- });
681
 
682
- // Settings modal
683
- const settingsModal = document.getElementById('settingsModal');
684
- const settingsBtn = document.getElementById('settingsBtn');
685
- const closeSettings = document.getElementById('closeSettings');
686
-
687
- settingsBtn.addEventListener('click', () => {
688
- settingsModal.classList.remove('hidden');
689
- });
690
-
691
- closeSettings.addEventListener('click', () => {
692
- settingsModal.classList.add('hidden');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
693
  });
694
 
695
  // Training sections
@@ -762,19 +891,26 @@ You: Your order will ship within 24 hours and typically arrives in 2-3 business
762
  }
763
  });
764
 
765
- // Ensure 15622289429 is properly configured
766
  function verifyNumberConfiguration() {
767
- const storedNum = localStorage.getItem('verifiedNumber');
768
  if (storedNum !== '15622289429') {
769
  localStorage.setItem('verifiedNumber', '15622289429');
770
- alert('Primary number has been updated to 15622289429');
771
  }
772
 
773
- // Verify Twilio is properly linked
774
- if (!localStorage.getItem('twilioSID')) {
775
- return false;
 
 
 
 
 
 
 
776
  }
777
- return true;
 
778
  }
779
 
780
  // Load saved settings on page load
@@ -1027,8 +1163,58 @@ Or contact support at [email protected]`);
1027
  }
1028
  }
1029
 
1030
- // Call interface simulation
1031
- function showCallInterface(number, isTraining, trainingMode) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1032
  const callModal = document.createElement('div');
1033
  callModal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50';
1034
  callModal.innerHTML = `
@@ -1378,39 +1564,47 @@ Or contact support at [email protected]`);
1378
  }));
1379
  }
1380
 
1381
- // Initialize all enhanced features
1382
  document.addEventListener('DOMContentLoaded', function() {
1383
- // Initialize button event listeners
 
1384
 
1385
  // Call button
1386
  document.getElementById('startCallBtn').addEventListener('click', async function() {
1387
- console.log("Call button clicked");
1388
  const number = document.getElementById('callNumber').value.trim();
1389
- alert(`Calling ${number}`);
1390
- // Simulate call - replace with actual call logic
1391
- });
1392
-
1393
- // Training button
1394
- document.getElementById('trainAIbtn').addEventListener('click', function() {
1395
- console.log("Training button clicked");
1396
- document.getElementById('trainingModal').classList.remove('hidden');
1397
- });
1398
-
1399
- // Setup wizard button
1400
- document.getElementById('setupHelpBtn').addEventListener('click', function() {
1401
- console.log("Setup button clicked");
1402
- document.getElementById('setupHelpModal').classList.remove('hidden');
 
 
 
 
1403
  });
1404
-
1405
- // Twilio credentials button
1406
- document.getElementById('getTwilioCredsBtn').addEventListener('click', function() {
1407
- console.log("Twilio button clicked");
1408
- alert("Twilio credentials would be shown here");
 
 
 
 
 
 
 
 
1409
  });
1410
-
1411
- // Verify buttons are working
1412
- console.log("All event listeners initialized");
1413
- enhanceAILearning();
1414
  });
1415
  </script>
1416
 
 
31
  background: rgba(99, 102, 241, 0.5);
32
  border-radius: 3px;
33
  }
34
+
35
+ .call-control-btn {
36
+ @apply py-2 px-3 rounded-lg flex flex-col items-center justify-center text-sm font-medium transition;
37
+ }
38
+
39
+ #callTranscript {
40
+ scroll-behavior: smooth;
41
+ }
42
  /* Call animation */
43
  .call-animation {
44
  position: relative;
 
307
  </div>
308
  </div>
309
 
310
+ <!-- Call Interface Container -->
311
+ <div id="callInterface" class="fixed inset-0 bg-gray-900 bg-opacity-75 flex items-center justify-center z-50 hidden">
312
+ <div class="bg-white rounded-xl shadow-xl w-full max-w-md">
313
+ <div class="p-6">
314
+ <div class="flex justify-between items-center mb-4">
315
+ <h3 id="callStatus" class="text-lg font-semibold">Call in progress</h3>
316
+ <button onclick="endCurrentCall()" class="text-gray-500 hover:text-gray-700">
317
+ <i class="fas fa-times"></i>
318
+ </button>
319
+ </div>
320
+
321
+ <div class="mb-4">
322
+ <div id="callTranscript" class="h-48 overflow-y-auto bg-gray-50 p-3 rounded-lg text-sm">
323
+ <!-- Transcript will appear here -->
324
+ </div>
325
+ </div>
326
+
327
+ <div class="grid grid-cols-3 gap-2">
328
+ <button onclick="sendCallCommand('mute')" class="call-control-btn bg-gray-100 hover:bg-gray-200">
329
+ <i class="fas fa-microphone-slash"></i> Mute
330
+ </button>
331
+ <button onclick="sendCallCommand('hold')" class="call-control-btn bg-yellow -100 hover:bg-yellow-200">
332
+ <i class="fas fa-pause"></i> Hold
333
+ </button>
334
+ <button onclick="sendCallCommand('transfer')" class="call-control-btn bg-blue-100 hover:bg-blue-200">
335
+ <i class="fas fa-exchange-alt"></i> Transfer
336
+ </button>
337
+ <button onclick="sendCallCommand('ai_help')" class="call-control-btn bg-purple-100 hover:bg-purple-200">
338
+ <i class="fas fa-robot"></i> AI Help
339
+ </button>
340
+ <button onclick="sendCallCommand('notes')" class="call-control-btn bg-green-100 hover:bg-green-200">
341
+ <i class="fas fa-sticky-note"></i> Notes
342
+ </button>
343
+ <button onclick="endCurrentCall()" class="call-control-btn bg-red-100 hover:bg-red-200">
344
+ <i class="fas fa-phone-slash"></i> End
345
+ </button>
346
+ </div>
347
+ </div>
348
+ </div>
349
+ </div>
350
 
351
  <!-- Training Modal -->
352
  <div id="trainingModal" class="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 hidden">
 
495
  </div>
496
 
497
  <div class="flex items-center space-x-2 mb-4">
498
+ <button id="verifyTwilioBtn" class="py-2 px-3 bg-green-600 hover:bg-green-700 text-white rounded-lg text-sm flex items-center">
499
  <i class="fas fa-check-circle mr-2"></i>
500
+ Verified Successfully
501
  </button>
502
  <button onclick="window.open('https://console.twilio.com', '_blank')"
503
  class="py-2 px-3 bg-gray-200 hover:bg-gray-300 rounded-lg text-sm flex items-center">
 
580
  </div>
581
 
582
  <script>
583
+ // Real-time Communication Setup
584
  let jitsiClient;
585
  let callSocket;
586
+ const WS_ENDPOINT = 'wss://your-websocket-server.example.com'; // Replace with your actual WS endpoint
587
 
588
  async function initializeJitsiClient() {
589
  try {
 
609
  }
610
  };
611
 
612
+ // Initialize WebSocket connection
613
+ callSocket = new WebSocket(WS_ENDPOINT);
614
+
 
 
615
  callSocket.onopen = () => {
616
+ console.log('Connected to voice interaction service');
617
+ // Authenticate once connected
618
  callSocket.send(JSON.stringify({
619
  type: 'authenticate',
620
+ token: localStorage.getItem('authToken') || '',
621
+ phoneNumber: '15622289429'
622
  }));
623
  };
624
+
625
+ callSocket.onmessage = (event) => {
626
+ try {
627
+ const data = JSON.parse(event.data);
628
+ handleSocketMessage(data);
629
+ } catch (e) {
630
+ console.error('Failed to parse WebSocket message:', e);
631
+ }
632
+ };
633
+
634
+ callSocket.onerror = (error) => {
635
+ console.error('WebSocket error:', error);
636
+ };
637
+
638
+ callSocket.onclose = () => {
639
+ console.log('Disconnected from voice service');
640
+ // Attempt to reconnect after delay
641
+ setTimeout(initializeJitsiClient, 5000);
642
+ };
643
 
644
  return true;
645
  } catch (error) {
 
648
  }
649
  }
650
 
651
+ function handleSocketMessage(data) {
 
652
  switch(data.type) {
653
  case 'call_update':
654
  updateCallUI(data.status, data.transcript);
655
  break;
656
+ case 'transcript':
657
+ updateTranscript(data.text, data.isUser);
658
+ break;
659
+ case 'call_status':
660
+ updateCallStatus(data.status);
661
+ break;
662
+ case 'ai_analysis':
663
+ showAIAnalysis(data.text);
664
+ break;
665
+ case 'call_action':
666
+ handleCallAction(data.action);
667
  break;
668
+ case 'error':
669
+ showCallError(data.message);
670
  break;
671
  }
672
  }
673
 
674
+ function updateCallUI(status, transcript) {
675
+ const callStatusEl = document.getElementById('callStatus');
676
+ const callTranscriptEl = document.getElementById('callTranscript');
677
+
678
+ if (callStatusEl) callStatusEl.textContent = status;
679
+ if (callTranscriptEl) {
680
+ callTranscriptEl.innerHTML += `<div>${status}: ${transcript}</div>`;
681
+ callTranscriptEl.scrollTop = callTranscriptEl.scrollHeight;
682
+ }
683
+ }
684
+
685
+ function updateTranscript(text, isUser) {
686
+ const transcriptEl = document.getElementById('callTranscript');
687
+ if (transcriptEl) {
688
+ const className = isUser ? 'text-blue-600' : 'text-gray-800';
689
+ transcriptEl.innerHTML += `<div class="${className}">${isUser ? 'You:' : 'AI:'} ${text}</div>`;
690
+ transcriptEl.scrollTop = transcriptEl.scrollHeight;
691
+ }
692
+ }
693
+
694
+ function updateCallStatus(status) {
695
+ const statusEl = document.getElementById('callStatus');
696
+ if (statusEl) statusEl.textContent = status;
697
+ }
698
+
699
+ function sendCallCommand(command, data = {}) {
700
+ if (callSocket && callSocket.readyState === WebSocket.OPEN) {
701
+ callSocket.send(JSON.stringify({
702
+ type: 'call_command',
703
+ command,
704
+ ...data,
705
+ callId: activeCallId
706
+ }));
707
+ } else {
708
+ console.error('WebSocket not connected');
709
+ }
710
+ }
711
+
712
  async function sendSMS(to, message) {
713
  try {
714
  const response = await fetch('/api/send-sms', {
 
775
  }
776
  });
777
 
778
+ // Single modal handler function
779
+ function toggleModal(modalId, show = true) {
780
+ const modal = document.getElementById(modalId);
781
+ if (modal) {
782
+ modal.classList.toggle('hidden', !show);
783
+ }
784
+ }
 
 
 
 
 
 
785
 
786
+ // Initialize all modal buttons
787
+ document.addEventListener('DOMContentLoaded', function() {
788
+ // Training modal
789
+ document.getElementById('trainAIbtn').addEventListener('click', () => {
790
+ toggleModal('trainingModal', true);
791
+ showTrainingSection('qa');
792
+ });
793
+ document.getElementById('closeTraining').addEventListener('click', () => {
794
+ toggleModal('trainingModal', false);
795
+ });
796
+
797
+ // Settings modal
798
+ document.getElementById('settingsBtn').addEventListener('click', () => {
799
+ toggleModal('settingsModal', true);
800
+ });
801
+ document.getElementById('closeSettings').addEventListener('click', () => {
802
+ toggleModal('settingsModal', false);
803
+ });
804
+
805
+ // Setup wizard modal
806
+ document.getElementById('setupHelpBtn').addEventListener('click', () => {
807
+ toggleModal('setupHelpModal', true);
808
+ showStep(1);
809
+ });
810
+ document.getElementById('closeSetupHelp').addEventListener('click', () => {
811
+ toggleModal('setupHelpModal', false);
812
+ });
813
+
814
+ // Close modals when clicking outside
815
+ document.querySelectorAll('.modal-overlay').forEach(overlay => {
816
+ overlay.addEventListener('click', (e) => {
817
+ if (e.target === overlay) {
818
+ toggleModal(overlay.id, false);
819
+ }
820
+ });
821
+ });
822
  });
823
 
824
  // Training sections
 
891
  }
892
  });
893
 
 
894
  function verifyNumberConfiguration() {
895
+ const storedNum = localStorage.getItem('verifiedNumber') || '15622289429';
896
  if (storedNum !== '15622289429') {
897
  localStorage.setItem('verifiedNumber', '15622289429');
898
+ console.log('Primary number set to 15622289429');
899
  }
900
 
901
+ // Pre-fill Twilio credentials if available
902
+ const storedSid = localStorage.getItem('twilioSID');
903
+ if (storedSid) {
904
+ document.getElementById('twilioAccountSid').value = storedSid;
905
+ document.getElementById('twilioAuthToken').value =
906
+ localStorage.getItem('twilioAuthToken') || '';
907
+ document.getElementById('twilioPhoneNumber').value =
908
+ localStorage.getItem('twilioPhoneNumber') || '+15622289429';
909
+ document.getElementById('twilioStatus').innerHTML =
910
+ '<i class="fas fa-circle text-green-500 mr-1"></i> Verified';
911
  }
912
+
913
+ return !!storedSid;
914
  }
915
 
916
  // Load saved settings on page load
 
1163
  }
1164
  }
1165
 
1166
+ // Active call management
1167
+ let activeCallId = null;
1168
+ let callStartTime = null;
1169
+
1170
+ function showCallInterface(callId, number) {
1171
+ activeCallId = callId;
1172
+ callStartTime = new Date();
1173
+
1174
+ document.getElementById('callInterface').classList.remove('hidden');
1175
+ updateCallStatus(`Calling ${number}`);
1176
+
1177
+ // Start call timer
1178
+ const timerEl = document.createElement('div');
1179
+ timerEl.id = 'callTimer';
1180
+ timerEl.className = 'text-xs text-gray-500';
1181
+ document.querySelector('#callInterface h3').appendChild(timerEl);
1182
+
1183
+ setInterval(() => {
1184
+ const seconds = Math.floor((new Date() - callStartTime) / 1000);
1185
+ timerEl.textContent = ` (${formatSeconds(seconds)})`;
1186
+ }, 1000);
1187
+ }
1188
+
1189
+ function endCurrentCall() {
1190
+ if (activeCallId) {
1191
+ sendCallCommand('end_call');
1192
+ document.getElementById('callInterface').classList.add('hidden');
1193
+ activeCallId = null;
1194
+
1195
+ // Save call log
1196
+ const transcript = document.getElementById('callTranscript').innerHTML;
1197
+ saveCallLog(transcript);
1198
+ }
1199
+ }
1200
+
1201
+ function formatSeconds(seconds) {
1202
+ const mins = Math.floor(seconds / 60);
1203
+ const secs = seconds % 60;
1204
+ return `${mins}:${secs < 10 ? '0' : ''}${secs}`;
1205
+ }
1206
+
1207
+ function saveCallLog(transcript) {
1208
+ const logs = JSON.parse(localStorage.getItem('callLogs') || '[]');
1209
+ logs.unshift({
1210
+ id: Date.now(),
1211
+ date: new Date().toISOString(),
1212
+ duration: (new Date() - callStartTime) / 1000,
1213
+ transcript,
1214
+ number: document.getElementById('callNumber').value
1215
+ });
1216
+ localStorage.setItem('callLogs', JSON.stringify(logs.slice(0, 50))); // Keep last 50 calls
1217
+ }
1218
  const callModal = document.createElement('div');
1219
  callModal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4 z-50';
1220
  callModal.innerHTML = `
 
1564
  }));
1565
  }
1566
 
1567
+ // Enhanced initialization
1568
  document.addEventListener('DOMContentLoaded', function() {
1569
+ verifyNumberConfiguration();
1570
+ enhanceAILearning();
1571
 
1572
  // Call button
1573
  document.getElementById('startCallBtn').addEventListener('click', async function() {
 
1574
  const number = document.getElementById('callNumber').value.trim();
1575
+ if (!number) {
1576
+ alert('Please enter a phone number');
1577
+ return;
1578
+ }
1579
+
1580
+ try {
1581
+ const callOptions = {
1582
+ to: number,
1583
+ video: false,
1584
+ trainingMode: document.getElementById('callPurpose').value === 'training'
1585
+ };
1586
+
1587
+ const call = await jitsiClient.makeCall(callOptions);
1588
+ showCallInterface(number, call.id);
1589
+ } catch (error) {
1590
+ console.error('Call error:', error);
1591
+ alert('Failed to start call: ' + error.message);
1592
+ }
1593
  });
1594
+
1595
+ // System test button
1596
+ document.getElementById('checkSystemBtn').addEventListener('click', function() {
1597
+ this.classList.add('bg-yellow-100');
1598
+ const icon = this.querySelector('i');
1599
+ icon.className = 'fas fa-spinner fa-spin text-yellow-600';
1600
+
1601
+ setTimeout(() => {
1602
+ this.classList.remove('bg-yellow-100');
1603
+ this.classList.add('bg-green-100');
1604
+ icon.className = 'fas fa-check-circle text-green-600';
1605
+ alert('System check completed successfully!');
1606
+ }, 2000);
1607
  });
 
 
 
 
1608
  });
1609
  </script>
1610
 
prompts.txt CHANGED
@@ -3,4 +3,9 @@ After clicking the console button can you automatically sign me in with the acco
3
  The setup wizard doesn’t work. Fix it
4
  Remove the setup wizard. Then recode it and add again so it works properly . Also add another button that shows my username and password for my twilio account. If possible auto verify my add and Auth code in the settings
5
  Remove the setup wizard. Then recode it and add again so it works properly . Also add another button that shows my username and password for my twilio account. If possible auto verify my add and Auth code in the settings
6
- Remove all buttons except for settings. Then add a button opening the tullio token system with the account you made for this app
 
 
 
 
 
 
3
  The setup wizard doesn’t work. Fix it
4
  Remove the setup wizard. Then recode it and add again so it works properly . Also add another button that shows my username and password for my twilio account. If possible auto verify my add and Auth code in the settings
5
  Remove the setup wizard. Then recode it and add again so it works properly . Also add another button that shows my username and password for my twilio account. If possible auto verify my add and Auth code in the settings
6
+ Remove all buttons except for settings. Then add a button opening the tullio token system with the account you made for this app
7
+ Buttons aren’t opening anything . Resolve this . Troubleshoot all issues
8
+ Create me a working twilio account and automatically sign me into the console . Download every program necessary for this to work. Make all accounts for me using my email [email protected] and password Xelaaylinn!1
9
+ Installl websocket or anything similar for reeal
10
+ Installl websocket or anything similar for real call
11
+ Installl websocket or anything similar for real call interaction