@@ -67,7 +67,7 @@ export class Intercom {
6767 app_id
6868 }
6969
70- return this . callIntercom ( 'boot' , data )
70+ return this . _callIntercom ( 'boot' , data )
7171 } )
7272 }
7373
@@ -79,11 +79,7 @@ export class Intercom {
7979 * This method will effectively clear out any user data that you have been passing through the JS API.
8080 */
8181 public shutdown ( ) : void {
82- if ( ! isPlatformBrowser ( this . platformId ) ) {
83- return
84- }
85-
86- return this . callIntercom ( 'shutdown' )
82+ return this . _callIntercom ( 'shutdown' )
8783 }
8884
8985 /**
@@ -95,23 +91,15 @@ export class Intercom {
9591 * in addition to logging an impression at the current URL and looking for new messages for the user.
9692 */
9793 public update ( data ?: any ) : void {
98- if ( ! isPlatformBrowser ( this . platformId ) ) {
99- return
100- }
101-
102- return this . callIntercom ( 'update' , data )
94+ return this . _callIntercom ( 'update' , data )
10395
10496 }
10597
10698 /**
10799 * This will hide the main Messenger panel if it is open. It will not hide the Messenger Launcher.
108100 */
109101 public hide ( ) : void {
110- if ( ! isPlatformBrowser ( this . platformId ) ) {
111- return
112- }
113-
114- return this . callIntercom ( 'hide' )
102+ return this . _callIntercom ( 'hide' )
115103 }
116104
117105 /**
@@ -122,26 +110,18 @@ export class Intercom {
122110 *
123111 */
124112 public show ( message ?: string ) : void {
125- if ( ! isPlatformBrowser ( this . platformId ) ) {
126- return
127- }
128-
129113 if ( message ) {
130114 return this . showNewMessage ( message )
131115 }
132- return this . callIntercom ( 'show' )
116+ return this . _callIntercom ( 'show' )
133117
134118 }
135119
136120 /**
137121 * To open the message window with the message list you can call `showMessages()`.
138122 */
139123 public showMessages ( ) : void {
140- if ( ! isPlatformBrowser ( this . platformId ) ) {
141- return
142- }
143-
144- return this . callIntercom ( 'showMessages' )
124+ return this . _callIntercom ( 'showMessages' )
145125 }
146126
147127 /**
@@ -150,10 +130,7 @@ export class Intercom {
150130 * This function takes an optional parameter that can be used to pre-populate the message composer as shown below.
151131 */
152132 public showNewMessage ( message ?: string ) : void {
153- if ( ! isPlatformBrowser ( this . platformId ) ) {
154- return
155- }
156- return this . callIntercom ( 'showNewMessage' , message )
133+ return this . _callIntercom ( 'showNewMessage' , message )
157134
158135 }
159136
@@ -165,10 +142,7 @@ export class Intercom {
165142 * You can also add custom information to events in the form of event metadata.
166143 */
167144 public trackEvent ( eventName : string , metadata ?: any ) : void {
168- if ( ! isPlatformBrowser ( this . platformId ) ) {
169- return
170- }
171- return this . callIntercom ( 'trackEvent' , eventName , metadata )
145+ return this . _callIntercom ( 'trackEvent' , eventName , metadata )
172146 }
173147
174148
@@ -178,11 +152,7 @@ export class Intercom {
178152 * This user_id can be used to retrieve the visitor or lead through the REST API.
179153 */
180154 public getVisitorId ( ) : string {
181- if ( ! isPlatformBrowser ( this . platformId ) ) {
182- return
183- }
184-
185- return this . callIntercom ( 'getVisitorId' )
155+ return this . _callIntercom ( 'getVisitorId' )
186156 }
187157
188158 /**
@@ -191,43 +161,49 @@ export class Intercom {
191161 * @readonly
192162 */
193163 get visitorId ( ) : string {
194- if ( ! isPlatformBrowser ( this . platformId ) ) {
195- return
196- }
197- return this . callIntercom ( 'getVisitorId' )
164+ return this . _callIntercom ( 'getVisitorId' )
198165 }
199166
200167 /**
201168 * Gives you the ability to hook into the show event. Requires a function argument.
202169 */
203170 public onShow ( handler : ( ) => void ) : void {
204- if ( ! isPlatformBrowser ( this . platformId ) ) {
205- return
206- }
207- return this . callIntercom ( 'onShow' , handler )
171+ return this . _callIntercom ( 'onShow' , handler )
208172 }
209173
210174 /**
211175 * Gives you the ability to hook into the hide event. Requires a function argument.
212176 */
213177 public onHide ( handler : ( ) => void ) : void {
214- if ( ! isPlatformBrowser ( this . platformId ) ) {
215- return
216- }
217- return this . callIntercom ( 'onHide' , handler )
178+ return this . _callIntercom ( 'onHide' , handler )
218179 }
219180
220181 /**
221182 * This method allows you to register a function that will be called when the current number of unread messages changes.
222183 */
223184 public onUnreadCountChange ( handler : ( unreadCount ?: number ) => void ) : void {
185+ return this . _callIntercom ( 'onUnreadCountChange' , handler )
186+ }
187+
188+ /**
189+ * If you would like to trigger a tour based on an action a user or visitor takes in your site or application,
190+ * ou can use this API method. You need to call this method with the id of the tour you wish to show. The id of
191+ * the tour can be found in the “Use tour everywhere” section of the tour editor.
192+ *
193+ * Please note that tours shown via this API must be published and the “Use tour everywhere” section must be
194+ * turned on. If you're calling this API using an invalid tour id, nothing will happen.
195+ */
196+ public startTour ( tourId : number ) : void {
197+ return this . _callIntercom ( 'startTour' , tourId )
198+ }
199+
200+ /**
201+ * Private handler to run Intercom methods safely
202+ */
203+ private _callIntercom ( fn : string , ...args ) {
224204 if ( ! isPlatformBrowser ( this . platformId ) ) {
225205 return
226206 }
227- return this . callIntercom ( 'onUnreadCountChange' , handler )
228- }
229-
230- private callIntercom ( fn : string , ...args ) {
231207 if ( ( < any > window ) . Intercom ) {
232208 return ( < any > window ) . Intercom ( fn , ...args )
233209 }
0 commit comments