@capawesome/capacitor-intercom 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CapawesomeCapacitorIntercom.podspec +19 -0
- package/LICENSE +21 -0
- package/Package.swift +30 -0
- package/README.md +932 -0
- package/android/build.gradle +60 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/Intercom.java +441 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/IntercomHelper.java +38 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/IntercomPlugin.java +307 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/CustomException.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/CustomExceptions.java +23 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/events/UnreadConversationCountChangeEvent.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/HandlePushNotificationOptions.java +25 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/InitializeOptions.java +34 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/IsIntercomPushNotificationOptions.java +25 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/LogEventOptions.java +35 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/LoginUserOptions.java +33 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentContentOptions.java +71 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentMessageComposerOptions.java +20 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/PresentOptions.java +19 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SendPushTokenToIntercomOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetBottomPaddingOptions.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetInAppMessagesVisibleOptions.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetLauncherVisibleOptions.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetUserHashOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/SetUserJwtOptions.java +24 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/options/UpdateUserOptions.java +108 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/results/GetUnreadConversationCountResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/classes/results/IsIntercomPushNotificationResult.java +22 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/Callback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/EmptyCallback.java +5 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/NonEmptyResultCallback.java +7 -0
- package/android/src/main/java/io/capawesome/capacitorjs/plugins/intercom/interfaces/Result.java +7 -0
- package/android/src/main/res/.gitkeep +0 -0
- package/dist/docs.json +1345 -0
- package/dist/esm/definitions.d.ts +549 -0
- package/dist/esm/definitions.js +27 -0
- package/dist/esm/definitions.js.map +1 -0
- package/dist/esm/index.d.ts +4 -0
- package/dist/esm/index.js +7 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/web.d.ts +34 -0
- package/dist/esm/web.js +175 -0
- package/dist/esm/web.js.map +1 -0
- package/dist/plugin.cjs.js +215 -0
- package/dist/plugin.cjs.js.map +1 -0
- package/dist/plugin.js +217 -0
- package/dist/plugin.js.map +1 -0
- package/ios/Plugin/Classes/Events/UnreadConversationCountChangeEvent.swift +16 -0
- package/ios/Plugin/Classes/Options/HandlePushNotificationOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/InitializeOptions.swift +15 -0
- package/ios/Plugin/Classes/Options/IsIntercomPushNotificationOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/LogEventOptions.swift +15 -0
- package/ios/Plugin/Classes/Options/LoginUserOptions.swift +17 -0
- package/ios/Plugin/Classes/Options/PresentContentOptions.swift +29 -0
- package/ios/Plugin/Classes/Options/PresentMessageComposerOptions.swift +10 -0
- package/ios/Plugin/Classes/Options/PresentOptions.swift +10 -0
- package/ios/Plugin/Classes/Options/SendPushTokenToIntercomOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetBottomPaddingOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetInAppMessagesVisibleOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetLauncherVisibleOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetUserHashOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/SetUserJwtOptions.swift +13 -0
- package/ios/Plugin/Classes/Options/UpdateUserOptions.swift +38 -0
- package/ios/Plugin/Classes/Results/GetUnreadConversationCountResult.swift +16 -0
- package/ios/Plugin/Classes/Results/IsIntercomPushNotificationResult.swift +16 -0
- package/ios/Plugin/Enums/CustomError.swift +75 -0
- package/ios/Plugin/Info.plist +24 -0
- package/ios/Plugin/Intercom.swift +323 -0
- package/ios/Plugin/IntercomHelper.swift +17 -0
- package/ios/Plugin/IntercomPlugin.swift +261 -0
- package/ios/Plugin/Protocols/Result.swift +5 -0
- package/package.json +105 -0
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
ext {
|
|
2
|
+
junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
|
|
3
|
+
androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.1'
|
|
4
|
+
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
|
|
5
|
+
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
|
|
6
|
+
intercomSdkVersion = project.hasProperty('intercomSdkVersion') ? rootProject.ext.intercomSdkVersion : '18.4.0'
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
buildscript {
|
|
10
|
+
repositories {
|
|
11
|
+
google()
|
|
12
|
+
mavenCentral()
|
|
13
|
+
}
|
|
14
|
+
dependencies {
|
|
15
|
+
classpath 'com.android.tools.build:gradle:8.13.0'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
apply plugin: 'com.android.library'
|
|
20
|
+
|
|
21
|
+
android {
|
|
22
|
+
namespace = "io.capawesome.capacitorjs.plugins.intercom"
|
|
23
|
+
compileSdk = project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 36
|
|
24
|
+
defaultConfig {
|
|
25
|
+
minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 24
|
|
26
|
+
targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 36
|
|
27
|
+
versionCode 1
|
|
28
|
+
versionName "1.0"
|
|
29
|
+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
|
30
|
+
}
|
|
31
|
+
buildTypes {
|
|
32
|
+
release {
|
|
33
|
+
minifyEnabled false
|
|
34
|
+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
lintOptions {
|
|
38
|
+
abortOnError = false
|
|
39
|
+
}
|
|
40
|
+
compileOptions {
|
|
41
|
+
sourceCompatibility JavaVersion.VERSION_21
|
|
42
|
+
targetCompatibility JavaVersion.VERSION_21
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
repositories {
|
|
47
|
+
google()
|
|
48
|
+
mavenCentral()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
dependencies {
|
|
53
|
+
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
54
|
+
implementation project(':capacitor-android')
|
|
55
|
+
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
56
|
+
implementation "io.intercom.android:intercom-sdk-base:$intercomSdkVersion"
|
|
57
|
+
testImplementation "junit:junit:$junitVersion"
|
|
58
|
+
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
59
|
+
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
60
|
+
}
|
|
@@ -0,0 +1,441 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.intercom;
|
|
2
|
+
|
|
3
|
+
import android.app.Application;
|
|
4
|
+
import android.os.Handler;
|
|
5
|
+
import android.os.Looper;
|
|
6
|
+
import androidx.annotation.NonNull;
|
|
7
|
+
import androidx.annotation.Nullable;
|
|
8
|
+
import com.getcapacitor.JSObject;
|
|
9
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.CustomException;
|
|
10
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.CustomExceptions;
|
|
11
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.events.UnreadConversationCountChangeEvent;
|
|
12
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.HandlePushNotificationOptions;
|
|
13
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.InitializeOptions;
|
|
14
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.IsIntercomPushNotificationOptions;
|
|
15
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.LogEventOptions;
|
|
16
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.LoginUserOptions;
|
|
17
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.PresentContentOptions;
|
|
18
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.PresentMessageComposerOptions;
|
|
19
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.PresentOptions;
|
|
20
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SendPushTokenToIntercomOptions;
|
|
21
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SetBottomPaddingOptions;
|
|
22
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SetInAppMessagesVisibleOptions;
|
|
23
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SetLauncherVisibleOptions;
|
|
24
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SetUserHashOptions;
|
|
25
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.SetUserJwtOptions;
|
|
26
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.options.UpdateUserOptions;
|
|
27
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.results.GetUnreadConversationCountResult;
|
|
28
|
+
import io.capawesome.capacitorjs.plugins.intercom.classes.results.IsIntercomPushNotificationResult;
|
|
29
|
+
import io.capawesome.capacitorjs.plugins.intercom.interfaces.EmptyCallback;
|
|
30
|
+
import io.capawesome.capacitorjs.plugins.intercom.interfaces.NonEmptyResultCallback;
|
|
31
|
+
import io.intercom.android.sdk.Company;
|
|
32
|
+
import io.intercom.android.sdk.IntercomContent;
|
|
33
|
+
import io.intercom.android.sdk.IntercomError;
|
|
34
|
+
import io.intercom.android.sdk.IntercomSpace;
|
|
35
|
+
import io.intercom.android.sdk.IntercomStatusCallback;
|
|
36
|
+
import io.intercom.android.sdk.UnreadConversationCountListener;
|
|
37
|
+
import io.intercom.android.sdk.UserAttributes;
|
|
38
|
+
import io.intercom.android.sdk.identity.Registration;
|
|
39
|
+
import io.intercom.android.sdk.push.IntercomPushClient;
|
|
40
|
+
import java.util.List;
|
|
41
|
+
import java.util.Map;
|
|
42
|
+
|
|
43
|
+
public class Intercom {
|
|
44
|
+
|
|
45
|
+
@NonNull
|
|
46
|
+
private final IntercomPushClient pushClient = new IntercomPushClient();
|
|
47
|
+
|
|
48
|
+
@NonNull
|
|
49
|
+
private final IntercomPlugin plugin;
|
|
50
|
+
|
|
51
|
+
private boolean initialized = false;
|
|
52
|
+
|
|
53
|
+
@Nullable
|
|
54
|
+
private UnreadConversationCountListener unreadConversationCountListener;
|
|
55
|
+
|
|
56
|
+
public Intercom(@NonNull IntercomPlugin plugin) {
|
|
57
|
+
this.plugin = plugin;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
public void getUnreadConversationCount(@NonNull NonEmptyResultCallback<GetUnreadConversationCountResult> callback) {
|
|
61
|
+
runOnMainThread(() -> {
|
|
62
|
+
try {
|
|
63
|
+
requireInitialized();
|
|
64
|
+
int count = io.intercom.android.sdk.Intercom.client().getUnreadConversationCount();
|
|
65
|
+
callback.success(new GetUnreadConversationCountResult(count));
|
|
66
|
+
} catch (Exception exception) {
|
|
67
|
+
callback.error(exception);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
public void handlePushNotification(@NonNull HandlePushNotificationOptions options, @NonNull EmptyCallback callback) {
|
|
73
|
+
try {
|
|
74
|
+
Map<String, String> data = IntercomHelper.convertJSObjectToStringMap(options.getData());
|
|
75
|
+
pushClient.handlePush(getApplication(), data);
|
|
76
|
+
callback.success();
|
|
77
|
+
} catch (Exception exception) {
|
|
78
|
+
callback.error(exception);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
public void hide(@NonNull EmptyCallback callback) {
|
|
83
|
+
runOnMainThread(() -> {
|
|
84
|
+
try {
|
|
85
|
+
requireInitialized();
|
|
86
|
+
io.intercom.android.sdk.Intercom.client().hideIntercom();
|
|
87
|
+
callback.success();
|
|
88
|
+
} catch (Exception exception) {
|
|
89
|
+
callback.error(exception);
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
public void initialize(@NonNull InitializeOptions options, @NonNull EmptyCallback callback) {
|
|
95
|
+
runOnMainThread(() -> {
|
|
96
|
+
try {
|
|
97
|
+
String apiKey = options.getAndroidApiKey();
|
|
98
|
+
if (apiKey == null) {
|
|
99
|
+
throw CustomExceptions.ANDROID_API_KEY_MISSING;
|
|
100
|
+
}
|
|
101
|
+
io.intercom.android.sdk.Intercom.initialize(getApplication(), apiKey, options.getAppId());
|
|
102
|
+
initialized = true;
|
|
103
|
+
registerUnreadConversationCountListener();
|
|
104
|
+
callback.success();
|
|
105
|
+
} catch (Exception exception) {
|
|
106
|
+
callback.error(exception);
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
public void isIntercomPushNotification(
|
|
112
|
+
@NonNull IsIntercomPushNotificationOptions options,
|
|
113
|
+
@NonNull NonEmptyResultCallback<IsIntercomPushNotificationResult> callback
|
|
114
|
+
) {
|
|
115
|
+
try {
|
|
116
|
+
Map<String, String> data = IntercomHelper.convertJSObjectToStringMap(options.getData());
|
|
117
|
+
boolean isIntercomPush = pushClient.isIntercomPush(data);
|
|
118
|
+
callback.success(new IsIntercomPushNotificationResult(isIntercomPush));
|
|
119
|
+
} catch (Exception exception) {
|
|
120
|
+
callback.error(exception);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
public void logEvent(@NonNull LogEventOptions options, @NonNull EmptyCallback callback) {
|
|
125
|
+
try {
|
|
126
|
+
requireInitialized();
|
|
127
|
+
JSObject data = options.getData();
|
|
128
|
+
if (data == null) {
|
|
129
|
+
io.intercom.android.sdk.Intercom.client().logEvent(options.getName());
|
|
130
|
+
} else {
|
|
131
|
+
io.intercom.android.sdk.Intercom.client().logEvent(options.getName(), IntercomHelper.convertJSObjectToObjectMap(data));
|
|
132
|
+
}
|
|
133
|
+
callback.success();
|
|
134
|
+
} catch (Exception exception) {
|
|
135
|
+
callback.error(exception);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
public void loginUnidentifiedUser(@NonNull EmptyCallback callback) {
|
|
140
|
+
try {
|
|
141
|
+
requireInitialized();
|
|
142
|
+
io.intercom.android.sdk.Intercom.client().loginUnidentifiedUser(createStatusCallback(callback, "LOGIN_FAILED"));
|
|
143
|
+
} catch (Exception exception) {
|
|
144
|
+
callback.error(exception);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
public void loginUser(@NonNull LoginUserOptions options, @NonNull EmptyCallback callback) {
|
|
149
|
+
try {
|
|
150
|
+
requireInitialized();
|
|
151
|
+
Registration registration = Registration.create();
|
|
152
|
+
if (options.getUserId() != null) {
|
|
153
|
+
registration = registration.withUserId(options.getUserId());
|
|
154
|
+
}
|
|
155
|
+
if (options.getEmail() != null) {
|
|
156
|
+
registration = registration.withEmail(options.getEmail());
|
|
157
|
+
}
|
|
158
|
+
io.intercom.android.sdk.Intercom.client().loginIdentifiedUser(registration, createStatusCallback(callback, "LOGIN_FAILED"));
|
|
159
|
+
} catch (Exception exception) {
|
|
160
|
+
callback.error(exception);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
public void logout(@NonNull EmptyCallback callback) {
|
|
165
|
+
try {
|
|
166
|
+
requireInitialized();
|
|
167
|
+
io.intercom.android.sdk.Intercom.client().logout();
|
|
168
|
+
callback.success();
|
|
169
|
+
} catch (Exception exception) {
|
|
170
|
+
callback.error(exception);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public void present(@NonNull PresentOptions options, @NonNull EmptyCallback callback) {
|
|
175
|
+
runOnMainThread(() -> {
|
|
176
|
+
try {
|
|
177
|
+
requireInitialized();
|
|
178
|
+
io.intercom.android.sdk.Intercom.client().present(mapSpace(options.getSpace()));
|
|
179
|
+
callback.success();
|
|
180
|
+
} catch (Exception exception) {
|
|
181
|
+
callback.error(exception);
|
|
182
|
+
}
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
public void presentContent(@NonNull PresentContentOptions options, @NonNull EmptyCallback callback) {
|
|
187
|
+
runOnMainThread(() -> {
|
|
188
|
+
try {
|
|
189
|
+
requireInitialized();
|
|
190
|
+
io.intercom.android.sdk.Intercom.client().presentContent(mapContent(options));
|
|
191
|
+
callback.success();
|
|
192
|
+
} catch (Exception exception) {
|
|
193
|
+
callback.error(exception);
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
public void presentMessageComposer(@NonNull PresentMessageComposerOptions options, @NonNull EmptyCallback callback) {
|
|
199
|
+
runOnMainThread(() -> {
|
|
200
|
+
try {
|
|
201
|
+
requireInitialized();
|
|
202
|
+
String initialMessage = options.getInitialMessage();
|
|
203
|
+
if (initialMessage == null) {
|
|
204
|
+
io.intercom.android.sdk.Intercom.client().displayMessageComposer();
|
|
205
|
+
} else {
|
|
206
|
+
io.intercom.android.sdk.Intercom.client().displayMessageComposer(initialMessage);
|
|
207
|
+
}
|
|
208
|
+
callback.success();
|
|
209
|
+
} catch (Exception exception) {
|
|
210
|
+
callback.error(exception);
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
public void sendPushTokenToIntercom(@NonNull SendPushTokenToIntercomOptions options, @NonNull EmptyCallback callback) {
|
|
216
|
+
try {
|
|
217
|
+
pushClient.sendTokenToIntercom(getApplication(), options.getToken());
|
|
218
|
+
callback.success();
|
|
219
|
+
} catch (Exception exception) {
|
|
220
|
+
callback.error(exception);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
public void setBottomPadding(@NonNull SetBottomPaddingOptions options, @NonNull EmptyCallback callback) {
|
|
225
|
+
runOnMainThread(() -> {
|
|
226
|
+
try {
|
|
227
|
+
requireInitialized();
|
|
228
|
+
io.intercom.android.sdk.Intercom.client().setBottomPadding(options.getPadding());
|
|
229
|
+
callback.success();
|
|
230
|
+
} catch (Exception exception) {
|
|
231
|
+
callback.error(exception);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
public void setInAppMessagesVisible(@NonNull SetInAppMessagesVisibleOptions options, @NonNull EmptyCallback callback) {
|
|
237
|
+
runOnMainThread(() -> {
|
|
238
|
+
try {
|
|
239
|
+
requireInitialized();
|
|
240
|
+
io.intercom.android.sdk.Intercom.client()
|
|
241
|
+
.setInAppMessageVisibility(
|
|
242
|
+
options.getVisible()
|
|
243
|
+
? io.intercom.android.sdk.Intercom.Visibility.VISIBLE
|
|
244
|
+
: io.intercom.android.sdk.Intercom.Visibility.GONE
|
|
245
|
+
);
|
|
246
|
+
callback.success();
|
|
247
|
+
} catch (Exception exception) {
|
|
248
|
+
callback.error(exception);
|
|
249
|
+
}
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
public void setLauncherVisible(@NonNull SetLauncherVisibleOptions options, @NonNull EmptyCallback callback) {
|
|
254
|
+
runOnMainThread(() -> {
|
|
255
|
+
try {
|
|
256
|
+
requireInitialized();
|
|
257
|
+
io.intercom.android.sdk.Intercom.client()
|
|
258
|
+
.setLauncherVisibility(
|
|
259
|
+
options.getVisible()
|
|
260
|
+
? io.intercom.android.sdk.Intercom.Visibility.VISIBLE
|
|
261
|
+
: io.intercom.android.sdk.Intercom.Visibility.GONE
|
|
262
|
+
);
|
|
263
|
+
callback.success();
|
|
264
|
+
} catch (Exception exception) {
|
|
265
|
+
callback.error(exception);
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
public void setUserHash(@NonNull SetUserHashOptions options, @NonNull EmptyCallback callback) {
|
|
271
|
+
try {
|
|
272
|
+
requireInitialized();
|
|
273
|
+
io.intercom.android.sdk.Intercom.client().setUserHash(options.getUserHash());
|
|
274
|
+
callback.success();
|
|
275
|
+
} catch (Exception exception) {
|
|
276
|
+
callback.error(exception);
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
public void setUserJwt(@NonNull SetUserJwtOptions options, @NonNull EmptyCallback callback) {
|
|
281
|
+
try {
|
|
282
|
+
requireInitialized();
|
|
283
|
+
io.intercom.android.sdk.Intercom.client().setUserJwt(options.getJwt());
|
|
284
|
+
callback.success();
|
|
285
|
+
} catch (Exception exception) {
|
|
286
|
+
callback.error(exception);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
public void unregisterUnreadConversationCountListener() {
|
|
291
|
+
if (unreadConversationCountListener != null) {
|
|
292
|
+
io.intercom.android.sdk.Intercom.client().removeUnreadConversationCountListener(unreadConversationCountListener);
|
|
293
|
+
unreadConversationCountListener = null;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public void updateUser(@NonNull UpdateUserOptions options, @NonNull EmptyCallback callback) {
|
|
298
|
+
try {
|
|
299
|
+
requireInitialized();
|
|
300
|
+
UserAttributes attributes = buildUserAttributes(options);
|
|
301
|
+
io.intercom.android.sdk.Intercom.client().updateUser(attributes, createStatusCallback(callback, "UPDATE_FAILED"));
|
|
302
|
+
} catch (Exception exception) {
|
|
303
|
+
callback.error(exception);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
@NonNull
|
|
308
|
+
private Company buildCompany(@NonNull JSObject company) throws Exception {
|
|
309
|
+
String id = company.getString("id");
|
|
310
|
+
if (id == null) {
|
|
311
|
+
throw CustomExceptions.COMPANY_ID_MISSING;
|
|
312
|
+
}
|
|
313
|
+
Company.Builder builder = new Company.Builder();
|
|
314
|
+
builder.withCompanyId(id);
|
|
315
|
+
if (company.getString("name") != null) {
|
|
316
|
+
builder.withName(company.getString("name"));
|
|
317
|
+
}
|
|
318
|
+
if (company.getString("plan") != null) {
|
|
319
|
+
builder.withPlan(company.getString("plan"));
|
|
320
|
+
}
|
|
321
|
+
if (company.has("monthlySpend")) {
|
|
322
|
+
builder.withMonthlySpend(company.getInteger("monthlySpend"));
|
|
323
|
+
}
|
|
324
|
+
if (company.has("createdAt")) {
|
|
325
|
+
builder.withCreatedAt(company.optLong("createdAt"));
|
|
326
|
+
}
|
|
327
|
+
JSObject customAttributes = company.getJSObject("customAttributes");
|
|
328
|
+
if (customAttributes != null) {
|
|
329
|
+
builder.withCustomAttributes(IntercomHelper.convertJSObjectToObjectMap(customAttributes));
|
|
330
|
+
}
|
|
331
|
+
return builder.build();
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
@NonNull
|
|
335
|
+
private UserAttributes buildUserAttributes(@NonNull UpdateUserOptions options) throws Exception {
|
|
336
|
+
UserAttributes.Builder builder = new UserAttributes.Builder();
|
|
337
|
+
if (options.getName() != null) {
|
|
338
|
+
builder.withName(options.getName());
|
|
339
|
+
}
|
|
340
|
+
if (options.getEmail() != null) {
|
|
341
|
+
builder.withEmail(options.getEmail());
|
|
342
|
+
}
|
|
343
|
+
if (options.getUserId() != null) {
|
|
344
|
+
builder.withUserId(options.getUserId());
|
|
345
|
+
}
|
|
346
|
+
if (options.getPhone() != null) {
|
|
347
|
+
builder.withPhone(options.getPhone());
|
|
348
|
+
}
|
|
349
|
+
if (options.getLanguageOverride() != null) {
|
|
350
|
+
builder.withLanguageOverride(options.getLanguageOverride());
|
|
351
|
+
}
|
|
352
|
+
if (options.getSignedUpAt() != null) {
|
|
353
|
+
builder.withSignedUpAt(options.getSignedUpAt());
|
|
354
|
+
}
|
|
355
|
+
if (options.getUnsubscribedFromEmails() != null) {
|
|
356
|
+
builder.withUnsubscribedFromEmails(options.getUnsubscribedFromEmails());
|
|
357
|
+
}
|
|
358
|
+
if (options.getCustomAttributes() != null) {
|
|
359
|
+
builder.withCustomAttributes(IntercomHelper.convertJSObjectToObjectMap(options.getCustomAttributes()));
|
|
360
|
+
}
|
|
361
|
+
List<JSObject> companies = options.getCompanies();
|
|
362
|
+
if (companies != null) {
|
|
363
|
+
for (JSObject company : companies) {
|
|
364
|
+
builder.withCompany(buildCompany(company));
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
return builder.build();
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
@NonNull
|
|
371
|
+
private IntercomStatusCallback createStatusCallback(@NonNull EmptyCallback callback, @NonNull String errorCode) {
|
|
372
|
+
return new IntercomStatusCallback() {
|
|
373
|
+
@Override
|
|
374
|
+
public void onSuccess() {
|
|
375
|
+
callback.success();
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
@Override
|
|
379
|
+
public void onFailure(@NonNull IntercomError intercomError) {
|
|
380
|
+
callback.error(new CustomException(errorCode, intercomError.getErrorMessage()));
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
@NonNull
|
|
386
|
+
private Application getApplication() {
|
|
387
|
+
return (Application) plugin.getContext().getApplicationContext();
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@NonNull
|
|
391
|
+
private IntercomContent mapContent(@NonNull PresentContentOptions options) throws Exception {
|
|
392
|
+
switch (options.getType()) {
|
|
393
|
+
case "article":
|
|
394
|
+
return new IntercomContent.Article(options.getId());
|
|
395
|
+
case "carousel":
|
|
396
|
+
return new IntercomContent.Carousel(options.getId());
|
|
397
|
+
case "survey":
|
|
398
|
+
return new IntercomContent.Survey(options.getId());
|
|
399
|
+
case "conversation":
|
|
400
|
+
return new IntercomContent.Conversation(options.getId());
|
|
401
|
+
case "help-center-collections":
|
|
402
|
+
return new IntercomContent.HelpCenterCollections(options.getIds());
|
|
403
|
+
default:
|
|
404
|
+
throw CustomExceptions.TYPE_INVALID;
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
@NonNull
|
|
409
|
+
private IntercomSpace mapSpace(@NonNull String space) {
|
|
410
|
+
switch (space) {
|
|
411
|
+
case "messages":
|
|
412
|
+
return IntercomSpace.Messages;
|
|
413
|
+
case "help-center":
|
|
414
|
+
return IntercomSpace.HelpCenter;
|
|
415
|
+
case "tickets":
|
|
416
|
+
return IntercomSpace.Tickets;
|
|
417
|
+
default:
|
|
418
|
+
return IntercomSpace.Home;
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
private void registerUnreadConversationCountListener() {
|
|
423
|
+
if (unreadConversationCountListener != null) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
unreadConversationCountListener = count -> {
|
|
427
|
+
plugin.notifyUnreadConversationCountChangeListeners(new UnreadConversationCountChangeEvent(count));
|
|
428
|
+
};
|
|
429
|
+
io.intercom.android.sdk.Intercom.client().addUnreadConversationCountListener(unreadConversationCountListener);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
private void requireInitialized() throws Exception {
|
|
433
|
+
if (!initialized) {
|
|
434
|
+
throw CustomExceptions.NOT_INITIALIZED;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
private void runOnMainThread(@NonNull Runnable runnable) {
|
|
439
|
+
new Handler(Looper.getMainLooper()).post(runnable);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package io.capawesome.capacitorjs.plugins.intercom;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
import com.getcapacitor.JSObject;
|
|
5
|
+
import java.util.HashMap;
|
|
6
|
+
import java.util.Iterator;
|
|
7
|
+
import java.util.Map;
|
|
8
|
+
|
|
9
|
+
public class IntercomHelper {
|
|
10
|
+
|
|
11
|
+
@NonNull
|
|
12
|
+
public static Map<String, Object> convertJSObjectToObjectMap(@NonNull JSObject data) {
|
|
13
|
+
Map<String, Object> result = new HashMap<>();
|
|
14
|
+
Iterator<String> keys = data.keys();
|
|
15
|
+
while (keys.hasNext()) {
|
|
16
|
+
String key = keys.next();
|
|
17
|
+
Object value = data.opt(key);
|
|
18
|
+
if (value != null) {
|
|
19
|
+
result.put(key, value);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return result;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@NonNull
|
|
26
|
+
public static Map<String, String> convertJSObjectToStringMap(@NonNull JSObject data) {
|
|
27
|
+
Map<String, String> result = new HashMap<>();
|
|
28
|
+
Iterator<String> keys = data.keys();
|
|
29
|
+
while (keys.hasNext()) {
|
|
30
|
+
String key = keys.next();
|
|
31
|
+
Object value = data.opt(key);
|
|
32
|
+
if (value != null) {
|
|
33
|
+
result.put(key, value.toString());
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
}
|