@@ -106,27 +106,25 @@ document.getElementById('chat-form').addEventListener('submit', async function (
106106 // Send telemetry data if the switch is enabled
107107 if ( document . getElementById ( 'telemetrySwitch' ) . checked ) {
108108 const chatHistoryString = conversationHistory . map ( entry => `${ entry . role } : ${ entry . content } ` ) . join ( '\n' ) ;
109+ const userIP = await getUserIP ( ) ;
109110 const telemetryData = {
110- embeds : [ {
111- title : "Chat Message is sent" ,
112- fields : [
113- { name : "IP" , value : "123.45.678" , inline : true } ,
114- { name : "Browser" , value : getBrowserName ( ) , inline : true } ,
115- { name : "OS" , value : getOSName ( ) , inline : true } ,
116- { name : "Message sent" , value : `User: ${ userInput } ` , inline : false } ,
117- { name : "Message received" , value : stripHtmlTags ( botResponse ) , inline : false } ,
118- { name : "Chat History" , value : stripHtmlTags ( chatHistoryString ) , inline : false }
119- ]
120- } ]
111+ ip : userIP ,
112+ browser : getBrowserName ( ) ,
113+ os : getOSName ( ) ,
114+ model : selectedModel ,
115+ messageSent : userInput ,
116+ messageReceived : stripHtmlTags ( botResponse ) ,
117+ chatHistory : stripHtmlTags ( chatHistoryString )
121118 } ;
122119
123- await fetch ( 'https://discord.com/api/webhooks/1306698777469386782/u7aCY1rDHTKrDgGq_Mk_dOoOHpaivk6VYUrByuV3lkugvtJVWyqCg1lLsAGIbaMZHzGO' , {
124- method : 'POST' ,
125- headers : {
126- 'Content-Type' : 'application/json'
127- } ,
128- body : JSON . stringify ( telemetryData )
129- } ) ;
120+ // Load the SendTelemetry.js script dynamically
121+ const script = document . createElement ( 'script' ) ;
122+ script . src = '../api/SendTelemetry.jss' ;
123+ script . onload = function ( ) {
124+ // Call the sendTelemetry function once the script is loaded
125+ window . sendTelemetry ( telemetryData ) ;
126+ } ;
127+ document . body . appendChild ( script ) ;
130128 }
131129 } catch ( error ) {
132130 EditMessage ( document . querySelector ( ".ai-message:last-child" ) , `<img src='./imgs/cross.png', alt='❌' width='16px'> Oops... We got an error: ${ error } ` ) ;
@@ -217,4 +215,15 @@ document.getElementById('userInput').addEventListener('keydown', function (event
217215 }
218216} ) ;
219217
218+ async function getUserIP ( ) {
219+ try {
220+ const response = await fetch ( 'https://api.ipify.org?format=json' ) ;
221+ const data = await response . json ( ) ;
222+ return data . ip ;
223+ } catch ( error ) {
224+ console . error ( 'Error fetching IP:' , error ) ;
225+ return 'Unknown' ;
226+ }
227+ }
228+
220229console . log ( "OS is:" + getOSName ( ) ) ;
0 commit comments