File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,8 +6,14 @@ import waitForLoad from '../utils/waitForLoad'
66
77declare global {
88 interface Window {
9- //eslint-disable-next-line @typescript-eslint/no-explicit-any
10- FrontChat : any
9+ FrontChat ?: {
10+ (
11+ command : string ,
12+ params ?: Record < string , string | boolean | object >
13+ ) : void
14+ // This isn't part of the FrontChat API; we add it to track when Front is fully initialized
15+ hasInitialized : boolean
16+ }
1117 }
1218}
1319
@@ -46,13 +52,12 @@ const load = ({
4652 const loaded = loadScript ( ( ) => {
4753 beforeInit ( )
4854
49- window . FrontChat ( 'init' , {
55+ window . FrontChat ?. ( 'init' , {
5056 chatId : providerKey ,
5157 onInitCompleted : ( ) => {
5258 setState ( 'complete' )
5359 onReady ( )
54- // 👇 Add state to Track when Front is fully initialized
55- window . FrontChat . hasInitialized = true
60+ if ( window . FrontChat ) window . FrontChat . hasInitialized = true
5661 }
5762 //Read more: https://dev.frontapp.com/docs/chat-sdk-reference
5863 } )
@@ -62,8 +67,8 @@ const load = ({
6267
6368const open = ( ) : void => {
6469 waitForLoad (
65- ( ) => window . FrontChat ?. hasInitialized ,
66- ( ) => window . FrontChat ( 'show' )
70+ ( ) => ! ! window . FrontChat ?. hasInitialized ,
71+ ( ) => window . FrontChat ?. ( 'show' )
6772 )
6873}
6974
You can’t perform that action at this time.
0 commit comments