99 .box { background : # fff ; padding : 24px ; border-radius : 10px ; box-shadow : 0 10px 30px rgba (0 , 0 , 0 , 0.1 ); text-align : center; }
1010 h1 { margin : 0 0 10px ; }
1111 .email { color : # 444 ; margin-bottom : 16px ; }
12- a .button { display : inline-block; padding : 10px 14px ; background : # 0969da ; color : # fff ; border-radius : 6px ; text-decoration : none; }
12+ a .button { display : inline-block; padding : 10px 14px ; background : # 0969da ; color : # fff ; border-radius : 6px ; text-decoration : none; cursor : pointer; }
1313 a .button : hover { background : # 0758b7 ; }
1414 </ style >
1515</ head >
1818 < h1 id ="welcome-message "> Benvenuto!</ h1 >
1919 < p class ="email " id ="email-line "> </ p >
2020
21- < a id ="chat-link " class ="button " href =" # " > Caricamento... </ a >
21+ < a id ="btn-open-chat " class ="button "> Apri Chat Supporto </ a >
2222 </ div >
2323
2424 < script >
25- // Recupera i dati salvati
25+ // --- PARTE 1: GESTIONE GRAFICA BENVENUTO ---
2626 const name = localStorage . getItem ( 'name' ) ;
2727 const email = localStorage . getItem ( 'email' ) ;
2828
29- // 1. Gestione del Nome
30- // Se 'name' esiste usa quello, altrimenti usa 'Utente'
29+ // Mostra il nome
3130 const displayName = name || 'Utente' ;
3231 document . getElementById ( 'welcome-message' ) . innerText = `Benvenuto, ${ displayName } !` ;
3332
34- // 2. Gestione della Email
33+ // Mostra la mail
3534 if ( email ) {
3635 document . getElementById ( 'email-line' ) . innerText = `Email: ${ email } ` ;
3736 } else {
3837 document . getElementById ( 'email-line' ) . innerText = `Email non disponibile` ;
3938 }
4039
41- // 3. Gestione del Link Chat
42- // Creiamo l'URL dinamico
43- const chatUrl = `chat.html?email=${ encodeURIComponent ( email || '' ) } ` ;
44-
45- // Aggiorniamo il bottone nell'HTML
46- const chatLink = document . getElementById ( 'chat-link' ) ;
47- chatLink . href = chatUrl ;
48- chatLink . innerText = 'Vai alla chat' ;
40+ // Gestione click sul bottone "Apri Chat"
41+ document . getElementById ( 'btn-open-chat' ) . onclick = function ( ) {
42+ console . log ( "Tentativo di apertura chat..." ) ;
43+ if ( window . embeddedservice_bootstrap && window . embeddedservice_bootstrap . utilAPI ) {
44+ window . embeddedservice_bootstrap . utilAPI . launchChat ( )
45+ . then ( ( ) => console . log ( "Chat aperta con successo" ) )
46+ . catch ( ( ) => alert ( "Impossibile aprire la chat al momento." ) ) ;
47+ } else {
48+ alert ( "Il servizio di chat si sta ancora caricando, riprova tra un secondo." ) ;
49+ }
50+ } ;
4951 </ script >
52+
5053 < script type ='text/javascript '>
51- function initEmbeddedMessaging ( ) {
52- try {
53- embeddedservice_bootstrap . settings . language = 'it' ; // For example, enter 'en' or 'en-US'
54+ function initEmbeddedMessaging ( ) {
55+ try {
56+ // Recupera email
57+ const userEmail = localStorage . getItem ( 'email' ) || '' ;
58+
59+ embeddedservice_bootstrap . settings . language = 'it' ;
60+
61+ embeddedservice_bootstrap . init (
62+ '00DfZ000000Aod3' ,
63+ 'Case_Support_Agent_Test' ,
64+ 'https://chogangroup--devai1.sandbox.my.site.com/ESWCaseSupportAgentTes1764164304917' ,
65+ {
66+ scrt2URL : 'https://chogangroup--devai1.sandbox.my.salesforce-scrt.com'
67+ }
68+ ) . then ( ( ) => {
69+ // APPENA IL WIDGET È PRONTO:
70+ // 1. Passiamo l'email nascosta
71+ embeddedservice_bootstrap . prechatAPI . setHiddenPrechatFields ( {
72+ "Login_Email_Consulente" : userEmail
73+ } ) ;
74+ console . log ( "Salesforce pronto. Email passata:" , userEmail ) ;
75+ } ) ;
5476
55- embeddedservice_bootstrap . init (
56- '00DfZ000000Aod3' ,
57- 'Case_Support_Agent_Test' ,
58- 'https://chogangroup--devai1.sandbox.my.site.com/ESWCaseSupportAgentTes1764164304917' ,
59- {
60- scrt2URL : 'https://chogangroup--devai1.sandbox.my.salesforce-scrt.com'
61- }
62- ) ;
63- } catch ( err ) {
64- console . error ( 'Error loading Embedded Messaging: ' , err ) ;
65- }
66- } ;
67- </ script >
68- < script type ='text/javascript ' src ='https://chogangroup--devai1.sandbox.my.site.com/ESWCaseSupportAgentTes1764164304917/assets/js/bootstrap.min.js ' onload ='initEmbeddedMessaging() '> </ script >
77+ } catch ( err ) {
78+ console . error ( 'Error loading Embedded Messaging: ' , err ) ;
79+ }
80+ } ;
81+ </ script >
82+
83+ < script type ='text/javascript ' src ='https://chogangroup--devai1.sandbox.my.site.com/ESWCaseSupportAgentTes1764164304917/assets/js/bootstrap.min.js ' onload ='initEmbeddedMessaging() '> </ script >
6984
7085</ body >
7186</ html >
0 commit comments