forked from BasedHardware/omi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintercom.dart
More file actions
110 lines (93 loc) · 3.8 KB
/
Copy pathintercom.dart
File metadata and controls
110 lines (93 loc) · 3.8 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
import 'dart:async';
import 'package:intercom_flutter/intercom_flutter.dart';
import 'package:omi/backend/preferences.dart';
import 'package:omi/env/env.dart';
import 'package:omi/utils/platform/platform_service.dart';
class IntercomManager {
static final IntercomManager _instance = IntercomManager._internal();
static IntercomManager get instance => _instance;
static final SharedPreferencesUtil _preferences = SharedPreferencesUtil();
IntercomManager._internal();
Intercom get intercom => Intercom.instance;
bool get _isIntercomEnabled =>
PlatformService.isIntercomSupported && (Env.intercomAppId != null && Env.intercomAppId!.isNotEmpty);
factory IntercomManager() {
return _instance;
}
Future<void> initIntercom() async {
if (Env.intercomAppId == null) return;
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => intercom.initialize(
Env.intercomAppId!,
iosApiKey: Env.intercomIOSApiKey,
androidApiKey: Env.intercomAndroidApiKey,
),
);
}
Future displayChargingArticle(String device) async {
return PlatformService.executeIfSupportedAsync(_isIntercomEnabled, () async {
if (device == 'Omi DevKit 2') {
return await intercom.displayArticle('10003257-how-to-charge-devkit2');
} else if (device == 'Omi') {
return await intercom.displayArticle('12123047-how-to-charge-omi');
} else {
return await intercom.displayArticle('9907475-how-to-charge-the-device');
}
});
}
Future loginIdentifiedUser(String uid) async {
return PlatformService.executeIfSupportedAsync(_isIntercomEnabled, () => intercom.loginIdentifiedUser(userId: uid));
}
Future loginUnidentifiedUser() async {
return PlatformService.executeIfSupportedAsync(_isIntercomEnabled, () => intercom.loginUnidentifiedUser());
}
Future displayEarnMoneyArticle() async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => intercom.displayArticle('10401566-build-publish-and-earn-with-omi-apps'),
);
}
Future displayFirmwareUpdateArticle() async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => intercom.displayArticle('9995941-updating-your-devkit2-firmware'),
);
}
Future logEvent(String eventName, {Map<String, dynamic>? metaData}) async {
return PlatformService.executeIfSupportedAsync(_isIntercomEnabled, () => intercom.logEvent(eventName, metaData));
}
Future updateCustomAttributes(Map<String, dynamic> attributes) async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => intercom.updateUser(customAttributes: attributes),
);
}
Future updateUser(String? email, String? name, String? uid) async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => intercom.updateUser(email: email, name: name, userId: uid),
);
}
Future<void> setUserAttributes() async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => updateCustomAttributes({
'Notifications Enabled': _preferences.notificationsEnabled,
'Location Enabled': _preferences.locationEnabled,
'Apps Enabled Count': _preferences.enabledAppsCount,
'Apps Integrations Enabled Count': _preferences.enabledAppsIntegrationsCount,
'Speaker Profile': _preferences.hasSpeakerProfile,
'Calendar Enabled': _preferences.calendarEnabled,
'Primary Language': _preferences.userPrimaryLanguage,
'Authorized Storing Recordings': _preferences.permissionStoreRecordingsEnabled,
}),
);
}
Future<void> sendTokenToIntercom(String token) async {
return PlatformService.executeIfSupportedAsync(
_isIntercomEnabled,
() => Intercom.instance.sendTokenToIntercom(token),
);
}
}