1111 .email { color : # 444 ; margin-bottom : 16px ; }
1212 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 ; }
14+ a .button .disabled { background : # ccc ; cursor : not-allowed; }
1415 </ style >
1516</ head >
1617< body >
1718 < div class ="box ">
1819 < h1 id ="welcome-message "> Benvenuto!</ h1 >
1920 < p class ="email " id ="email-line "> </ p >
2021
21- < a id ="btn-open-chat " class ="button " > Apri Chat Supporto </ a >
22+ < a id ="btn-open-chat " class ="button disabled " > Caricamento Chat... </ a >
2223 </ div >
2324
2425 < script >
25- // --- PARTE 1: GESTIONE GRAFICA BENVENUTO ---
2626 const name = localStorage . getItem ( 'name' ) ;
2727 const email = localStorage . getItem ( 'email' ) ;
2828
29- // Mostra il nome
29+ // UI: Nome
3030 const displayName = name || 'Utente' ;
3131 document . getElementById ( 'welcome-message' ) . innerText = `Benvenuto, ${ displayName } !` ;
3232
33- // Mostra la mail
33+ // UI: Email
3434 if ( email ) {
3535 document . getElementById ( 'email-line' ) . innerText = `Email: ${ email } ` ;
3636 } else {
3737 document . getElementById ( 'email-line' ) . innerText = `Email non disponibile` ;
3838 }
3939
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." ) ;
40+ // UI: Gestione Click Bottone
41+ const btnChat = document . getElementById ( 'btn-open-chat' ) ;
42+
43+ btnChat . onclick = function ( ) {
44+ if ( btnChat . classList . contains ( 'disabled' ) ) {
45+ console . warn ( "Chat non ancora pronta." ) ;
46+ return ;
4947 }
48+
49+ console . log ( "Tentativo di apertura chat..." ) ;
50+ // Avvia la chat
51+ embeddedservice_bootstrap . utilAPI . launchChat ( )
52+ . then ( ( ) => console . log ( "Chat aperta." ) )
53+ . catch ( ( e ) => console . error ( "Errore apertura chat:" , e ) ) ;
5054 } ;
5155 </ script >
5256
53- < script type ='text/javascript '>
57+ < script type ='text/javascript '>
58+ // Variabile globale per capire quando è pronto
59+ window . isSalesforceReady = false ;
60+
5461 function initEmbeddedMessaging ( ) {
62+ console . log ( "--> INIZIO INIT SALESFORCE <--" ) ;
5563 try {
56- // Recupera email
5764 const userEmail = localStorage . getItem ( 'email' ) || '' ;
58-
59- // LOG DI CONTROLLO 1
60- console . log ( "1. Email trovata nel localStorage:" , userEmail ) ;
65+ console . log ( "1. Email recuperata:" , userEmail ) ;
6166
6267 embeddedservice_bootstrap . settings . language = 'it' ;
6368
69+ // Configurazione (con il nome corretto che mi hai dato prima)
6470 embeddedservice_bootstrap . init (
6571 '00DfZ000000Aod3' ,
6672 'Case_Support_Agent_With_variable' ,
@@ -69,30 +75,33 @@ <h1 id="welcome-message">Benvenuto!</h1>
6975 scrt2URL : 'https://chogangroup--devai1.sandbox.my.salesforce-scrt.com'
7076 }
7177 ) . then ( ( ) => {
72- // LOG DI CONTROLLO 2
73- console . log ( "2. Init completata. Tento di inviare i campi nascosti.. ." ) ;
74-
75- // Preparo l'oggetto
76- const hiddenFields = {
78+ // SUCCESSO!
79+ console . log ( "2. Init completata con successo ." ) ;
80+
81+ // Passaggio parametri nascosti
82+ embeddedservice_bootstrap . prechatAPI . setHiddenPrechatFields ( {
7783 "Login_Email_Consulente" : userEmail
78- } ;
84+ } ) ;
85+ console . log ( "3. Parametri nascosti impostati." ) ;
7986
80- // Invio
81- embeddedservice_bootstrap . prechatAPI . setHiddenPrechatFields ( hiddenFields ) ;
82-
83- // LOG DI CONTROLLO 3
84- console . log ( "3. EMAIL INVIATA A SALESFORCE:" , hiddenFields ) ;
85- console . log ( "Se non la vedi nel Flow, controlla che la variabile Flow sia 'Available for Input'." ) ;
87+ // Abilitiamo il bottone
88+ const btn = document . getElementById ( 'btn-open-chat' ) ;
89+ btn . innerText = "Parla con l'Agente" ;
90+ btn . classList . remove ( 'disabled' ) ;
91+ window . isSalesforceReady = true ;
8692
8793 } ) . catch ( error => {
88- console . error ( "ERRORE durante l'inizializzazione:" , error ) ;
94+ console . error ( "ERRORE FATALE INIT:" , error ) ;
95+ document . getElementById ( 'btn-open-chat' ) . innerText = "Errore Chat" ;
8996 } ) ;
9097
9198 } catch ( err ) {
92- console . error ( 'Error loading Embedded Messaging : ' , err ) ;
99+ console . error ( 'Eccezione nello script di init : ' , err ) ;
93100 }
94101 } ;
95102 </ script >
103+
104+ < script type ='text/javascript ' src ='https://chogangroup--devai1.sandbox.my.site.com/ESWCaseSupportAgentTes1764164304917/assets/js/bootstrap.min.js ' onload ='initEmbeddedMessaging() '> </ script >
96105
97106</ body >
98107</ html >
0 commit comments