forked from narusevic/nativescript-intercom-bridge
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathintercom-bridge.android.ts
More file actions
114 lines (90 loc) · 3.68 KB
/
intercom-bridge.android.ts
File metadata and controls
114 lines (90 loc) · 3.68 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
import * as application from 'tns-core-modules/application';
import * as utils from 'tns-core-modules/utils/utils';
declare let io: any;
export class IntercomBridge {
public static intercomPushClient = new io.intercom.android.sdk.push.IntercomPushClient();
static init(apiKey: string, appId: string) {
io.intercom.android.sdk.Intercom.initialize(utils.ad.getApplicationContext(), apiKey, appId);
}
static registerIdentifiedUser(options: {userId?: string|number, email?: string}) {
if (typeof options.userId == 'number') {
options.userId = String(options.userId);
}
let registration = io.intercom.android.sdk.identity.Registration.create();
if (options.userId && options.userId.length > 0) {
registration.withUserId(options.userId);
}
if (options.email && options.email.length > 0) {
registration.withEmail(options.email);
}
io.intercom.android.sdk.Intercom.client().registerIdentifiedUser(registration);
}
static registerUnidentifiedUser() {
io.intercom.android.sdk.Intercom.client().registerUnidentifiedUser();
}
static reset() {
io.intercom.android.sdk.Intercom.client().reset();
}
static logout() {
io.intercom.android.sdk.Intercom.client().logout();
}
static setUserHash(hmac: string) {
io.intercom.android.sdk.Intercom.client().setUserHash(hmac);
}
static updateUser(attributes: any) {
const Att = io.intercom.android.sdk.UserAttributes;
const builder = new Att.Builder();
Object.keys(attributes).forEach(key => {
if(key === 'customAttributes') {
return;
}
const methodName = key && typeof(key) === 'string' && `with${key.charAt(0).toUpperCase()}${key.slice(1)}`
const value = attributes[key];
if(!methodName || !builder[methodName]) {
return;
}
builder[methodName](value);
});
if(attributes && typeof attributes === 'object' && attributes.hasOwnProperty('customAttributes')) {
Object.keys(attributes.customAttributes).forEach(key => {
builder.withCustomAttribute(key, attributes.customAttributes[key]);
});
}
io.intercom.android.sdk.Intercom.client().updateUser(builder.build());
}
static logEvent(eventName: string, metaData?: any) {
if (!!metaData) {
io.intercom.android.sdk.Intercom.client().logEvent(eventName, metaData);
} else {
io.intercom.android.sdk.Intercom.client().logEvent(eventName);
}
}
static displayMessenger() {
io.intercom.android.sdk.Intercom.client().displayMessenger();
}
static displayMessageComposer(initialMessage?: string) {
if(!!initialMessage) {
io.intercom.android.sdk.Intercom.client().displayMessageComposer(initialMessage);
} else {
io.intercom.android.sdk.Intercom.client().displayMessageComposer();
}
}
static displayConversationsList() {
io.intercom.android.sdk.Intercom.client().displayConversationsList();
}
static unreadConversationCount() {
return io.intercom.android.sdk.Intercom.client().getUnreadConversationCount();
}
static setLauncherVisibility(visible: boolean) {
io.intercom.android.sdk.Intercom.client().setLauncherVisibility(visible ? io.intercom.android.sdk.Intercom.VISIBLE : io.intercom.android.sdk.Intercom.GONE);
}
static setInAppMessageVisibility(visible: boolean) {
io.intercom.android.sdk.Intercom.client().setInAppMessageVisibility(visible ? io.intercom.android.sdk.Intercom.VISIBLE : io.intercom.android.sdk.Intercom.GONE);
}
static hideMessenger() {
io.intercom.android.sdk.Intercom.client().hideMessenger();
}
static enableLogging() {
io.intercom.android.sdk.Intercom.setLogLevel(io.intercom.android.sdk.Intercom.LogLevel.DEBUG);
}
}