-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathIntercomModule.java
More file actions
658 lines (595 loc) · 23 KB
/
IntercomModule.java
File metadata and controls
658 lines (595 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
package com.intercom.reactnative;
import android.app.Activity;
import android.app.Application;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.module.annotations.ReactModule;
import com.google.firebase.messaging.RemoteMessage;
import org.jetbrains.annotations.NotNull;
import java.util.List;
import java.util.Map;
import io.intercom.android.sdk.Intercom;
import io.intercom.android.sdk.IntercomContent;
import io.intercom.android.sdk.IntercomError;
import io.intercom.android.sdk.IntercomSpace;
import io.intercom.android.sdk.IntercomStatusCallback;
import io.intercom.android.sdk.UserAttributes;
import io.intercom.android.sdk.api.ReactNativeHeaderInterceptor;
import io.intercom.android.sdk.helpcenter.api.CollectionContentRequestCallback;
import io.intercom.android.sdk.helpcenter.api.CollectionRequestCallback;
import io.intercom.android.sdk.helpcenter.api.HelpCenterArticleSearchResult;
import io.intercom.android.sdk.helpcenter.api.SearchRequestCallback;
import io.intercom.android.sdk.helpcenter.collections.HelpCenterCollection;
import io.intercom.android.sdk.helpcenter.sections.HelpCenterCollectionContent;
import io.intercom.android.sdk.identity.Registration;
import io.intercom.android.sdk.push.IntercomPushClient;
import io.intercom.android.sdk.ui.theme.ThemeMode;
import android.app.TaskStackBuilder;
@ReactModule(name = IntercomModule.NAME)
public class IntercomModule extends NativeIntercomSpecSpec {
public static final String NAME = "IntercomModule";
private static final IntercomPushClient intercomPushClient = new IntercomPushClient();
public IntercomModule(ReactApplicationContext reactContext) {
super(reactContext);
}
@Override
@NonNull
public String getName() {
return NAME;
}
public static boolean isIntercomPush(RemoteMessage remoteMessage) {
try {
Map message = remoteMessage.getData();
return intercomPushClient.isIntercomPush(message);
} catch (Exception err) {
Log.e(NAME, "isIntercomPush error:");
Log.e(NAME, err.toString());
return false;
}
}
public static void handleRemotePushWithCustomStack(@NonNull Application application, RemoteMessage remoteMessage,
TaskStackBuilder customStack) {
try {
if (remoteMessage == null) {
Log.w(NAME, "handleRemotePushWithCustomStack: remoteMessage is null");
return;
}
Map<String, String> message = remoteMessage.getData();
if (message == null) {
Log.w(NAME, "handleRemotePushWithCustomStack: message is null");
return;
}
intercomPushClient.handlePushWithCustomStack(application, message, customStack);
} catch (Exception err) {
Log.e(NAME, "handlePushWithCustomStack error:");
Log.e(NAME, err.toString());
}
}
public static void handleRemotePushMessage(@NonNull Application application, RemoteMessage remoteMessage) {
try {
TaskStackBuilder customStack = TaskStackBuilder.create(application);
Intent launchIntent = application.getPackageManager().getLaunchIntentForPackage(application.getPackageName());
if (launchIntent != null) {
customStack.addNextIntent(launchIntent);
}
handleRemotePushWithCustomStack(application, remoteMessage, customStack);
} catch (Exception err) {
Log.e(NAME, "handleRemotePushMessage error:");
Log.e(NAME, err.toString());
}
}
public static void sendTokenToIntercom(Application application, @NonNull String token) {
if (application == null || token == null || token.isEmpty()) {
Log.w(NAME, "sendTokenToIntercom: application or token is null or empty");
return;
}
try {
intercomPushClient.sendTokenToIntercom(application, token);
Log.d(NAME, "sendTokenToIntercom");
} catch (Exception err) {
Log.e(NAME, "sendTokenToIntercom error:");
Log.e(NAME, err.toString());
}
}
@ReactMethod
public void handlePushMessage(Promise promise) {
try {
Intercom.client().handlePushMessage();
promise.resolve(true);
Log.d(NAME, "handlePushMessage");
} catch (Exception err) {
Log.e(NAME, "handlePushMessage error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.HANDLE_PUSH_MESSAGE, err.toString());
}
}
@ReactMethod
public void sendTokenToIntercom(@NonNull String token, Promise promise) {
try {
if (token == null || token.isEmpty()) {
Log.w(NAME, "sendTokenToIntercom: token is null or empty");
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "token is null or empty");
return;
}
Activity activity = getCurrentActivity();
if (activity != null && activity.getApplication() != null) {
intercomPushClient.sendTokenToIntercom(activity.getApplication(), token);
Log.d(NAME, "sendTokenToIntercom");
promise.resolve(true);
} else {
Log.e(NAME, "sendTokenToIntercom");
Log.e(NAME, "no current activity");
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, "no current activity");
}
} catch (Exception err) {
Log.e(NAME, "sendTokenToIntercom error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SEND_TOKEN_TO_INTERCOM, err.toString());
}
}
@ReactMethod
public void loginUnidentifiedUser(Promise promise) {
Intercom.client().loginUnidentifiedUser(new IntercomStatusCallback() {
@Override
public void onSuccess() {
promise.resolve(true);
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
Log.e("ERROR", intercomError.getErrorMessage());
promise.reject(String.valueOf(intercomError.getErrorCode()), intercomError.getErrorMessage());
}
});
}
@ReactMethod
public void loginUserWithUserAttributes(ReadableMap params, Promise promise) {
Boolean hasEmail = params.hasKey("email") && IntercomHelpers.getValueAsStringForKey(params, "email").length() > 0;
Boolean hasUserId = params.hasKey("userId")
&& IntercomHelpers.getValueAsStringForKey(params, "userId").length() > 0;
Registration registration = null;
if (hasEmail && hasUserId) {
String email = IntercomHelpers.getValueAsStringForKey(params, "email");
String userId = IntercomHelpers.getValueAsStringForKey(params, "userId");
registration = new Registration().withEmail(email).withUserId(userId);
} else if (hasEmail) {
String email = IntercomHelpers.getValueAsStringForKey(params, "email");
registration = new Registration().withEmail(email);
} else if (hasUserId) {
String userId = IntercomHelpers.getValueAsStringForKey(params, "userId");
registration = new Registration().withUserId(userId);
} else {
Log.e(NAME, "loginUserWithUserAttributes called with invalid userId or email");
Log.e(NAME, "You must provide userId or email");
promise.reject(IntercomErrorCodes.IDENTIFIED_REGISTRATION, "Invalid userId or email");
}
if (registration != null) {
Intercom.client().loginIdentifiedUser(registration, new IntercomStatusCallback() {
@Override
public void onSuccess() {
promise.resolve(true);
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
Log.e("ERROR", intercomError.getErrorMessage());
promise.reject(String.valueOf(intercomError.getErrorCode()), intercomError.getErrorMessage());
}
});
}
}
@ReactMethod
public void setUserHash(String userHash, Promise promise) {
try {
Intercom.client().setUserHash(userHash);
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setUserHash error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_USER_HASH, err.toString());
}
}
@ReactMethod
public void updateUser(ReadableMap params, Promise promise) {
UserAttributes userAttributes = IntercomHelpers.buildUserAttributes(params);
Intercom.client().updateUser(userAttributes, new IntercomStatusCallback() {
@Override
public void onSuccess() {
promise.resolve(true);
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
Log.e("ERROR", intercomError.getErrorMessage());
promise.reject(String.valueOf(intercomError.getErrorCode()), intercomError.getErrorMessage());
}
});
}
@ReactMethod
public void isUserLoggedIn(Promise promise) {
promise.resolve(Intercom.client().isUserLoggedIn());
}
@ReactMethod
public void fetchLoggedInUserAttributes(Promise promise) {
Registration registration = Intercom.client().fetchLoggedInUserAttributes();
promise.resolve(IntercomHelpers.deconstructRegistration(registration));
}
@ReactMethod
public void logout(Promise promise) {
try {
Intercom.client().logout();
Log.d(NAME, "logout");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "logout error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.LOGOUT, err.toString());
}
}
@ReactMethod
public void getUnreadConversationCount(Promise promise) {
try {
promise.resolve(Intercom.client().getUnreadConversationCount());
Log.d(NAME, "getUnreadConversationCount");
} catch (Exception err) {
Log.e(NAME, "getUnreadConversationCount error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.GET_UNREAD_CONVERSATION, err.toString());
}
}
@ReactMethod
public void setLogLevel(String logLevel, Promise promise) {
try {
Intercom.setLogLevel(IntercomHelpers.stringToLogLevel(logLevel));
Log.d(NAME, "setLogLevel");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setLogLevel error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_LOG_LEVEL, err.toString());
}
}
@ReactMethod
public void logEvent(String eventName, @Nullable ReadableMap metaData, Promise promise) {
try {
if (metaData != null) {
Intercom.client().logEvent(eventName, IntercomHelpers.deconstructReadableMap(metaData, false));
} else {
Intercom.client().logEvent(eventName);
}
Log.d(NAME, "logEvent");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "logEvent error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.LOG_EVENT_HASH, err.toString());
}
}
@ReactMethod
public void presentIntercom(Promise promise) {
try {
Intercom.client().present();
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "presentMessenger error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.DISPLAY_MESSENGER, err.toString());
}
}
@ReactMethod
public void presentIntercomSpace(String space, Promise promise) {
try {
IntercomSpace selectedSpace = IntercomSpace.Home;
switch (space) {
case "TICKETS":
selectedSpace = IntercomSpace.Tickets;
break;
case "MESSAGES":
selectedSpace = IntercomSpace.Messages;
break;
case "HELP_CENTER":
selectedSpace = IntercomSpace.HelpCenter;
break;
default:
selectedSpace = IntercomSpace.Home;
}
Intercom.client().present(selectedSpace);
promise.resolve(true);
} catch (Exception error) {
Log.e(NAME, "presentIntercomSpace error:");
Log.e(NAME, error.toString());
promise.reject(IntercomErrorCodes.DISPLAY_MESSENGER, error.toString());
}
}
@ReactMethod
public void presentMessageComposer(@Nullable String initialMessage, Promise promise) {
try {
if (initialMessage != null) {
Intercom.client().displayMessageComposer(initialMessage);
} else {
Intercom.client().displayMessageComposer();
}
Log.d(NAME, "presentMessageComposer");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "presentMessageComposer error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.DISPLAY_MESSENGER_COMPOSER, err.toString());
}
}
@ReactMethod
public void presentContent(ReadableMap params, Promise promise) {
try {
Boolean hasContentType = params.hasKey("type") && params.getString("type").length() > 0;
if (hasContentType) {
IntercomContent content = null;
String contentType = params.getString("type");
switch (contentType) {
case "ARTICLE":
content = new IntercomContent.Article(params.getString("id"));
break;
case "CAROUSEL":
content = new IntercomContent.Carousel(params.getString("id"));
break;
case "SURVEY":
content = new IntercomContent.Survey(params.getString("id"));
break;
case "HELP_CENTER_COLLECTIONS":
List<String> collectionIds = IntercomHelpers.readableArrayToStringList(params.getArray("ids"));
content = new IntercomContent.HelpCenterCollections(collectionIds);
break;
case "CONVERSATION":
content = new IntercomContent.Conversation(params.getString("id"));
break;
}
if (content != null) {
Intercom.client().presentContent(content);
promise.resolve(true);
} else {
promise.reject(IntercomErrorCodes.DISPLAY_CONTENT, "Invalid content type");
}
} else {
promise.reject(IntercomErrorCodes.DISPLAY_CONTENT, "Intercom content must have a type");
}
} catch (Exception error) {
Log.e(NAME, error.toString());
promise.reject(IntercomErrorCodes.DISPLAY_CONTENT, error.toString());
}
}
@ReactMethod
public void fetchHelpCenterCollections(Promise promise) {
try {
CollectionRequestCallback collectionRequestCallback = new CollectionRequestCallback() {
@Override
public void onComplete(@NotNull List<HelpCenterCollection> list) {
promise.resolve(IntercomHelpCenterHelpers.parseHelpCenterCollectionsToReadableArray(list));
}
@Override
public void onError(int i) {
Log.e(NAME, "fetchHelpCenterCollections error");
promise.reject(String.valueOf(i), "fetchHelpCenterCollections error");
}
@Override
public void onFailure() {
Log.e(NAME, "fetchHelpCenterCollections failure");
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTIONS, "fetchHelpCenterCollections failure");
}
};
Log.d(NAME, "fetchHelpCenterCollections");
Intercom.client().fetchHelpCenterCollections(collectionRequestCallback);
} catch (Exception err) {
Log.e(NAME, "fetchHelpCenterCollections error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTIONS, err.toString());
}
}
@ReactMethod
public void fetchHelpCenterCollection(String collectionId, Promise promise) {
try {
if (collectionId.equals("")) {
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "collectionID can\'t be empty");
} else {
CollectionContentRequestCallback collectionContentCallback = new CollectionContentRequestCallback() {
@Override
public void onComplete(@NotNull HelpCenterCollectionContent helpCenterCollectionContent) {
promise.resolve(
IntercomHelpCenterHelpers.parseHelpCenterCollectionsContentToReadableMap(helpCenterCollectionContent));
}
@Override
public void onError(int i) {
Log.e(NAME, "fetchHelpCenterCollection error");
promise.reject(String.valueOf(i), "fetchHelpCenterCollection error");
}
@Override
public void onFailure() {
Log.e(NAME, "fetchHelpCenterCollection failure");
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, "fetchHelpCenterCollection failure");
}
};
Log.d(NAME, "fetchHelpCenterCollection");
Intercom.client().fetchHelpCenterCollection(collectionId, collectionContentCallback);
}
} catch (Exception err) {
Log.e(NAME, "fetchHelpCenterCollection error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.FETCH_HELP_CENTER_COLLECTION, err.toString());
}
}
@ReactMethod
public void searchHelpCenter(String searchTerm, Promise promise) {
if (searchTerm.equals("")) {
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchTerm can\'t be empty");
} else {
try {
SearchRequestCallback collectionContentCallback = new SearchRequestCallback() {
@Override
public void onComplete(@NotNull List<HelpCenterArticleSearchResult> helpCenterArticleSearchResult) {
promise.resolve(
IntercomHelpCenterHelpers.parseHelpCenterArticleSearchToReadableArray(helpCenterArticleSearchResult));
}
@Override
public void onError(int i) {
Log.e(NAME, "searchHelpCenter error");
promise.reject(String.valueOf(i), "searchHelpCenter error");
}
@Override
public void onFailure() {
Log.e(NAME, "searchHelpCenter failure");
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, "searchHelpCenter failure");
}
};
Log.d(NAME, "searchHelpCenter");
Intercom.client().searchHelpCenter(searchTerm, collectionContentCallback);
} catch (Exception err) {
Log.e(NAME, "searchHelpCenter error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SEARCH_HELP_CENTER, err.toString());
}
}
}
@ReactMethod
public void setInAppMessageVisibility(String visibility, Promise promise) {
try {
Intercom.client().setInAppMessageVisibility(IntercomHelpers.stringToVisibility(visibility));
Log.d(NAME, "setInAppMessageVisibility");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setInAppMessageVisibility error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_IN_APP_MESSAGE_VISIBILITY, err.toString());
}
}
@ReactMethod
public void hideIntercom(Promise promise) {
try {
Intercom.client().hideIntercom();
Log.d(NAME, "hideIntercom");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "hideIntercom error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.HIDE_INTERCOM, err.toString());
}
}
@ReactMethod
public void setLauncherVisibility(String visibility, Promise promise) {
try {
Intercom.client().setLauncherVisibility(IntercomHelpers.stringToVisibility(visibility));
Log.d(NAME, "setInAppMessageVisibility");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setInAppMessageVisibility error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_LAUNCHER_VISIBILITY, err.toString());
}
}
@ReactMethod
public void setBottomPadding(double paddingBottom, Promise promise) {
try {
Intercom.client().setBottomPadding((int) paddingBottom);
Log.d(NAME, "setBottomPadding");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setBottomPadding error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_BOTTOM_PADDING, err.toString());
}
}
@ReactMethod
public void setThemeMode(String themeMode, Promise promise) {
try {
ThemeMode themeModeEnum = null;
if (themeMode == null || themeMode.trim().isEmpty()) {
promise.reject(IntercomErrorCodes.SET_THEME_MODE,
"Theme mode cannot be null or empty. Use 'LIGHT', 'DARK', or 'SYSTEM'.");
return;
}
switch (themeMode) {
case "SYSTEM":
themeModeEnum = ThemeMode.SYSTEM;
break;
case "LIGHT":
themeModeEnum = ThemeMode.LIGHT;
break;
case "DARK":
themeModeEnum = ThemeMode.DARK;
break;
default:
promise.reject(IntercomErrorCodes.SET_THEME_MODE,
"Invalid theme mode: '" + themeMode + "'. Use 'LIGHT', 'DARK', or 'SYSTEM'.");
return;
}
Intercom.client().setThemeMode(themeModeEnum);
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "setThemeMode error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_THEME_MODE, "Error in setThemeMode: " + err.toString());
}
}
@ReactMethod
public void setUserJwt(String jwt, Promise promise) {
try {
Intercom.client().setUserJwt(jwt);
Log.d(NAME, "Setting JWT");
promise.resolve(true);
} catch (Exception err) {
Log.e(NAME, "Error Setting JWT:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_USER_JWT, err.toString());
}
}
@ReactMethod
public void setAuthTokens(ReadableMap authTokens, Promise promise) {
try {
List<io.intercom.android.sdk.AuthToken> authTokensList = IntercomHelpers.buildAuthTokensList(authTokens);
Intercom.client().setAuthTokens(authTokensList, new IntercomStatusCallback() {
@Override
public void onSuccess() {
promise.resolve(true);
}
@Override
public void onFailure(@NonNull IntercomError intercomError) {
Log.e("ERROR", intercomError.getErrorMessage());
promise.reject(String.valueOf(intercomError.getErrorCode()), intercomError.getErrorMessage());
}
});
} catch (Exception err) {
Log.e(NAME, "setAuthTokens error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.SET_AUTH_TOKENS, err.toString());
}
}
@ReactMethod
public void initialize(String apiKey, String appId, Promise promise) {
try {
Activity activity = getCurrentActivity();
if (activity != null && activity.getApplication() != null) {
IntercomModule.initialize(activity.getApplication(), apiKey, appId);
promise.resolve(true);
} else {
promise.reject(IntercomErrorCodes.INITIALIZE_ERROR, "Activity is null");
}
} catch (Exception err) {
Log.e(NAME, "initialize error:");
Log.e(NAME, err.toString());
promise.reject(IntercomErrorCodes.INITIALIZE_ERROR, err.toString());
}
}
@ReactMethod
public void setNeedsStatusBarAppearanceUpdate(Promise promise) {
// iOS-only method, no-op on Android
promise.resolve(true);
}
public static synchronized void initialize(Application application, String apiKey, String appId) {
String sdkVersion = BuildConfig.INTERCOM_VERSION_NAME;
ReactNativeHeaderInterceptor.setReactNativeVersion(application.getApplicationContext(), sdkVersion);
Intercom.initialize(application, apiKey, appId);
}
}