1(function ($) { 2 window.marked.use({ 3 async: false, 4 }); 5 const app = new Vue({ 6 el: '#chatBot', 7 components: {}, 8 data: { 9 messages: [], 10 messageText: '', 11 socket: null, 12 apiBaseUrl: 'https://api.myaicorp.com/v2', 13 wsChatUrl: 'wss://api.myaicorp.com/v2/completion/chat', 14 wsCompletionUrl: 'wss://api.myaicorp.com/v2/completion/stream', 15 id_selected: 0, 16 id_generico: 523, 17 id_metropolitana: 527, 18 id_lleida: 520, 19 ides: { 20 'ES': [651, 653, 655], 21 'CA': [523, 527, 520], 22 'EN': [652, 654 , 656], 23 }, 24 loading: false, 25 sections: '', 26 chatbotTitle: '', 27 relevantSections: '', 28 socketClosed: false, 29 showMenu: false, 30 openChat: false, 31 showTePuedoAyudar: false, 32 showTePuedoAyudarNomostrar: true, 33 valoracionSent: false, 34 sendingValoracion: 0, 35 valoracionSentNoShow: true, 36 valoracionSentText: '', 37 catalanTxt: 'Català ', 38 espanolTxt: 'Espanyol', 39 inglesTxt: 'Anglès', 40 authenticationService: { 41 currentUser: { 42 id: 0, 43 username: '', 44 firstName: '', 45 lastName: '', 46 token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1bmlxdWVfbmFtZSI6InRyaWFsQGlib29hZ2VuY3kuY29tIiwiaHR0cDovL3NjaGVtYXMueG1sc29hcC5vcmcvd3MvMjAwNS8wNS9pZGVudGl0eS9jbGFpbXMvc2lkIjoiMDhkYTJiN2YtNmVkMC00OGE1LThmY2QtODk3YTUzZGNlNjc2IiwiZ3JvdXBzaWQiOiIwMDAwMDAwMC0wMDAwLTAwMDAtMDAwMC0wMDAwMDAwMDAwMDAiLCJuYmYiOjE3MTQ1NDY3NzIsImV4cCI6MTcxNDU1MDM3MiwiaWF0IjoxNzE0NTQ2NzcyfQ.5EG6D5NV1oD9Yf-N_m5A1fEcx963MB7X8QHesOEWebU' 47 } 48 } 49 }, 50 created: function () { 51 }, 52 methods: { 53 init: function (idd_selected, el) { 54 55 let currentLang = document.documentElement.lang ?? 'CA'; 56 if(currentLang === 'en-US') currentLang = 'EN'; 57 if(currentLang === 'es-ES') currentLang = 'ES'; 58 this.changeLanguage(currentLang.toUpperCase()); 59 60 if(idd_selected !== 0 ) { 61 idd_selected = this[el]; 62 } 63 64 this.id_selected = idd_selected; 65 this.valoracionSent = false; 66 this.messages.splice(0); 67 68 if (this.socket) { 69 this.disconnect(); 70 } 71 72 73 74 if (idd_selected === 0) { 75 } else { 76 77 this.socket = new WebSocket(this.wsChatUrl); 78 this.socket.onmessage = this.onmessage; 79 this.socket.onerror = this.onerror; 80 this.socket.onopen = this.onopen; 81 82 83 this.messages.push( 84 { 85 // text: window.marked.parse(window.chatbot_config.locales[currentLang]['en-que-puedo']), 86 text: '', 87 isOwn: false} 88 ); 89 } 90 const that = this; 91 setTimeout(function() { 92 that.$refs.userInput?.focus(); 93 }, 100); 94 }, 95 onopen: function () { 96 this.authenticate(this.id_selected); 97 window.dataLayer = window.dataLayer || []; 98 !!window.dataLayer && window.dataLayer.push({ 99 'event': 'Chatbot Init', 100 'category': 'Chatbot Open', 101 'action': 'Bot Selected', 102 'label': 'Id', 103 'value': this.id_selected 104 }); 105 }, 106 disconnect() { 107 this.socket && this.socket.close(); 108 this.socket = null; 109 }, 110 authenticate(id_seccion) { 111 if (!this.socket) 112 return; 113 114 const o = `<|SOM|><|KEY|>DsI1Qedtydh48a1kjXKxxL6YKcu9Pqgh|${id_seccion}<|EOM|>`; 115 this.socket.send(o) 116 }, 117 sendMessage(t) { 118 if(0 === this.sendingValoracion) { 119 this.loading = true; 120 } 121 this.socket && this.socket.send(`<|SOM|><|TXT|>${t}<|EOM|>`) 122 }, 123 124 onmessage: function (event) { 125 const t = event.data; 126 if(0 === this.sendingValoracion) { 127 this.loading = true; 128 } 129 t.split("<|EOM|>").forEach(i => { 130 const o = new RegExp("(<\\|SOM\\|>)(<\\|.*\\|>)(.*)", "s").exec(i); 131 if (null != o) 132 switch (o[2]) { 133 case "<|TXT|>": 134 const regex = /[`]/g; 135 const t = o[3].replace(regex, '');
136 if(0 === this.sendingValoracion) { 137 this.messages[this.messages.length - 1].text += t; 138 } 139 break; 140 case "<|FL|>": 141 if (this.messages.length > 1) { 142 this.showTePuedoAyudar = false; 143 if(this.valoracionSentNoShow) { 144 this.valoracionSent = false; 145 } 146 } 147 if(0 < this.sendingValoracion) { 148 this.sendingValoracion++; 149 } 150 if(2 < this.sendingValoracion ) { 151 this.sendingValoracion = 0; 152 } 153 if(0 === this.sendingValoracion) { 154 this.messages.push({text: '', isOwn: false}); 155 } 156 this.loading = false; 157 let that = this; 158 setTimeout(function() { 159 that.$refs.userInput?.focus(); 160 }, 100); 161 break; 162 case "<|SEC|>": 163 this.sections = o[3].split("\n"); 164 break; 165 case "<|REL|>": 166 this.relevantSections = o[3].split("\n"); 167 break; 168 case "<|END|>": 169 this.disconnect(); 170 this.socketClosed = false; 171 this.loading = false; 172 break; 173 case "<|ERR|>": 174 switch (o[3]) { 175 case "0": 176 this.messages.push({text: 'Trial expired', isOwn: false}); 177 this.loading = false; 178 break; 179 case "1": 180 this.messages.push({text: 'Trial expired', isOwn: false}); 181 this.loading = false; 182 break; 183 case "2": 184 this.messages.push({text: 'Trial expired', isOwn: false}); 185 this.loading = false; 186 break; 187 case "3": 188 this.messages.push({text: 'Trial expired', isOwn: false}); 189 this.loading = false; 190 191 } 192 } 193 } 194 ); 195 }, 196 onerror: function (event) { 197 }, 198 getClass: function (message) { 199 return message.isOwn ? 'own' : ''; 200 }, 201 handleMessageSubmit: function () { 202 this.showTePuedoAyudar = false; 203 this.messages.push({text: (this.messageText), isOwn: true}); 204 this.messages.push({text: '', isOwn: false}); 205 this.sendMessage(this.messageText); 206 this.messageText = ''; 207 }, 208 scrollToBottom() { 209 const that = this; 210 setTimeout(function () { 211 that.$refs.bottomEl?.scrollIntoView({behavior: 'smooth'}); 212 }, 100); 213 }, 214 clickMenu: function () { 215 this.showMenu = !this.showMenu; 216 }, 217 restartConversation: function () { 218 this.showMenu = false;
219 this.loading = false; 220 this.init(0); 221 }, 222 downloadConversation: function () { 223 let textContent = ''; 224 for (const obj of this.messages) { 225 if (obj.text.length == 0) continue; 226 const prefix = !obj.isOwn ? 'BOT: ' : 'USR:'; 227 textContent += prefix + obj.text + '\n\n'; // Agrega una nueva lÃnea después de cada texto 228 } 229 230 231 // Create a Blob object from the text content 232 const blob = new Blob([textContent], {type: 'text/plain'}); 233 234 // Create a URL for the Blob object 235 const url = URL.createObjectURL(blob); 236 237 // Create a virtual download link and trigger the download 238 const downloadLink = document.createElement('a'); 239 downloadLink.href = url; 240 downloadLink.download = 'bot-text.txt'; // Set the desired filename 241 downloadLink.click(); 242 243 // Remove the temporary URL from memory 244 URL.revokeObjectURL(url); 245 this.showMenu = false; 246 }, 247 deleteConversation: function () { 248 this.showMenu = false;
249 this.loading = false; 250 this.openChat = false; 251 this.init(0); 252 }, 253 closeConversation: function () { 254 this.showTePuedoAyudar = false 255 this.openChat = false; 256 this.showMenu = false; 257 }, 258 enviarValoracion: function (valoracion) { 259 this.valoracionSent = true; 260 this.sendingValoracion = 1; 261 setTimeout(() => { 262 this.valoracionSentNoShow = false; 263 }, 2000); 264 265 let currentLang = document.documentElement.lang ?? 'CA'; 266 if(currentLang === 'en-US') currentLang = 'EN'; 267 if(currentLang === 'es-ES') currentLang = 'ES'; 268 this.valoracionSentText = window.chatbot_config.locales[currentLang]['gracias-valoracion']; 269 270 this.sendMessage(`{AVALUACIO=${valoracion}`); 271 window.dataLayer = window.dataLayer || []; 272 !!window.dataLayer && window.dataLayer.push({ 273 'event': 'Chatbot Feedback', 274 'category': 'Chatbot Experience', 275 'action': 'User Rating', 276 'label': 'Rating', 277 'value': valoracion 278 }); 279 }, 280 toggleChat: function (ev) { 281 this.openChat = !this.openChat; 282 window.dataLayer = window.dataLayer || []; 283 !!window.dataLayer && window.dataLayer.push({ 284 'event': 'Chatbot Abrir chat', 285 'category': 'Chatbot', 286 'action': this.openChat ? 'Abrir' : 'Cerrar', 287 'value': this.openChat 288 }); 289 ev.stopPropagation(); 290 }, 291 initHablemos: function () { 292 this.showTePuedoAyudar = false; 293 this.$refs.userInput?.focus(); 294 }, 295 closeConversationSatisfied: function () { 296 window.dataLayer = window.dataLayer || []; 297 !!window.dataLayer && window.dataLayer.push({ 298 'event': 'Chatbot Conversation', 299 'category': 'Chatbot Experience', 300 'action': 'Conversation Outcome', 301 'label': 'Satisfied' 302 }); 303 // this.closeConversation(); 304 }, 305 markedParse: function(text) { 306 let txt = window.marked.parse(text); 307 txt = txt.replaceAll( 'href', 'target="_blank" href' ); 308 return txt; 309 }, 310 changeLanguage: function (lang) { 311 if(this.id_generico === this.ides[lang][0] ) { 312 return; 313 } 314 this.id_generico = this.ides[lang][0]; 315 this.id_metropolitana = this.ides[lang][1]; 316 this.id_lleida = this.ides[lang][2]; 317 318 this.valoracionSentNoShow = true; 319 this.restartConversation(); 320 321 322 const activeLanguage = window.chatbot_config.locales[lang.toLowerCase()]; 323 324 this.catalanTxt = activeLanguage.catalan|| 'Català '; 325 this.espanolTxt = activeLanguage.espanol || 'Español'; 326 this.inglesTxt = activeLanguage.ingles || 'Inglés'; 327 328 //console.log('Selected language:', activeLanguage); 329 330 window.dataLayer = window.dataLayer || []; 331 !!window.dataLayer && window.dataLayer.push({ 332 'event': 'Chatbot Change Language', 333 'category': 'Chatbot Experience', 334 'action': 'Language Changed', 335 'label': lang 336 }); 337 } 338 }, 339 computed: {}, 340 watch: { 341 'messages.length': function () { 342 this.scrollToBottom(); 343 }, 344 }, 345 mounted() { 346 } 347 }); 348})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.