forked from hansemannn/titanium-freshchat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
51 lines (37 loc) · 1.22 KB
/
app.js
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
import Freshchat from 'ti.freshchat';
// -------- Set your credentials here --------
const APP_ID = 'YOUR_APP_ID';
const APP_KEY = 'YOUR_APP_KEY';
const APP_DOMAIN = null; // optional
// -------- Set your credentials here --------
const window = Ti.UI.createWindow({ layout: 'vertical' });
window.addEventListener('open', () => initializeSDK());
addButton('Sign in user', signInUser);
addButton('Update user', updateUser);
addButton('Reset user', signOutUser);
addButton('Track event', trackEvent);
addButton('Show conversations', showConversations);
window.open();
function initializeSDK() {
Freshchat.initialize({ appId: APP_ID, appKey: APP_KEY, domain: APP_DOMAIN });
}
function addButton(title, action) {
const btn = Ti.UI.createButton({ title, top: 50 });
btn.addEventListener('click', () => action());
window.add(btn);
}
function signInUser() {
Freshchat.signInUser({ firstName: 'John', lastName: 'Doe', email: '[email protected]' })
}
function signOutUser() {
Freshchat.signOutUser();
}
function updateUser() {
Freshchat.updateUserProperty('firstName', 'Hans');
}
function trackEvent() {
Freshchat.trackEvent('test_event', { prop1: true, hello: 'tirocks' });
}
function showConversations() {
Freshchat.showConversations();
}