import { createLogger } from '../../logger' ; import type { IntercomPayload } from './types' ; import * as Constants from './constants' ; const log = createLogger ( __filename ) ; let userId = null ; export const setUserId = ( newUserId ) : void => { userId = newUserId ; } ; export const getIntercomAppId = ( ) : string | null | undefined => process . env . OT_APP_INTERCOM_ID ; const okToCall = ( ) : boolean => { return ! ! getIntercomAppId ( ) && ! ! global . Intercom && ! ! userId ; } ; export const bootIntercom = ( props ) : void => { if ( okToCall ( ) ) { const iprops = { ... props , user_id : userId , hide_default_launcher : true , } ; log . debug ( 'Booting intercom' , props ) ; global . Intercom ( Constants . INTERCOM_BOOT , iprops ) ; } } ; export const updateIntercomProfile = ( props ) : void => { if ( okToCall ( ) ) { const iprops = { ... props , user_id : userId , hide_default_launcher : true , } ; log . debug ( 'Updating intercom profile' , props ) ; global . Intercom ( Constants . INTERCOM_UPDATE , iprops ) ; } } ; export const sendIntercomEvent = ( eventName , metadata ) : void => { if ( okToCall ( ) ) { log . debug ( 'Sending intercom event' , { eventName , metadata } ) ; global . Intercom ( Constants . INTERCOM_TRACK_EVENT , eventName , metadata ) ; } } ;