-
Notifications
You must be signed in to change notification settings - Fork 0
/
HelpshiftExampleScript.cs
292 lines (239 loc) · 9.43 KB
/
HelpshiftExampleScript.cs
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
using UnityEngine;
using UnityEngine.UI;
using System;
using System.Collections.Generic;
#if UNITY_IOS || UNITY_ANDROID
using Helpshift;
#endif
namespace HelpshiftExample
{
public class HelpshiftExampleScript : MonoBehaviour
{
#if UNITY_IOS || UNITY_ANDROID
private HelpshiftSdk _helpshiftX;
Dictionary<string, object> cifDictionary = new Dictionary<string, object>();
void Awake()
{
Debug.Log("Unity - Awake called");
_helpshiftX = HelpshiftSdk.GetInstance();
string domainName = "<your-domain>.helpshift.com";
string appId;
#if UNITY_ANDROID
appId = "<your-app-android-app-id>";
#elif UNITY_IOS
appId = "<your-app-ios-app-id>";
#endif
_helpshiftX.Install(appId, domainName, GetInstallConfig());
_helpshiftX.SetHelpshiftEventsListener(new HSEventsListener());
_helpshiftX.SetHelpshiftProactiveConfigCollector(new ProactiveConfigCollector());
#if UNITY_ANDROID
FirebaseIntegration.initFirebase();
#endif
}
public void ShowConversation()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.ShowConversation(GetConversationConfig());
Debug.Log("Helpshift - ShowConversation called");
#endif
}
public void ShowFAQs()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.ShowFAQs(GetConversationConfig());
Debug.Log("Helpshift - ShowFAQs called");
#endif
}
public void ShowFAQSection()
{
#if UNITY_ANDROID || UNITY_IOS
string faqSectionId = getDataFromInputField("faq_section_id");
_helpshiftX.ShowFAQSection(faqSectionId, GetConversationConfig());
Debug.Log("Helpshift - ShowFAQSection called");
#endif
}
public void ShowSingleFAQ()
{
#if UNITY_ANDROID || UNITY_IOS
string faqId = getDataFromInputField("faq_id");
_helpshiftX.ShowSingleFAQ(faqId, GetConversationConfig());
Debug.Log("Helpshift - ShowSingleFAQ called");
#endif
}
public void AddUserTrail()
{
#if UNITY_ANDROID || UNITY_IOS
string userTrail = getDataFromInputField("usertrail_input");
_helpshiftX.AddUserTrail(userTrail);
#endif
}
public void AddDebugLog()
{
#if UNITY_ANDROID || UNITY_IOS
string tag = getDataFromInputField("log_tag");
string message = getDataFromInputField("log_message");
string level = getDataFromDropDownField("log_dropdown");
Debug.Log("Helpshift - Calling debug log: Level: " + level + ", tag " + tag + ", message: " + message);
switch(level)
{
case "Verbose": HelpshiftLog.v(tag, message); break;
case "Debug": HelpshiftLog.d(tag, message); break;
case "Info": HelpshiftLog.i(tag, message); break;
case "Warn": HelpshiftLog.w(tag, message); break;
case "Error": HelpshiftLog.e(tag, message); break;
}
#endif
}
public void SetSDKLanguage()
{
#if UNITY_ANDROID || UNITY_IOS
string langCode = getDataFromInputField("language_input");
_helpshiftX.SetSDKLanguage(langCode);
#endif
}
public void LeaveBreadCrumb()
{
#if UNITY_ANDROID || UNITY_IOS
string crumb = getDataFromInputField("breadcrumb_input");
_helpshiftX.LeaveBreadcrumb(crumb);
#endif
}
public void ClearBreadCrumb()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.ClearBreadcrumbs();
#endif
}
public void ClearAnonUser()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.ClearAnonymousUserOnLogin(getFlagFromToggleField("clear_anon_flag"));
#endif
}
public void RequestUnreadCount()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.RequestUnreadMessageCount(getFlagFromToggleField("from_remote"));
Debug.Log("Helpshift - RequestUnreadCount called");
#endif
}
public void Login()
{
#if UNITY_ANDROID || UNITY_IOS
try
{
_helpshiftX.Login(GetUserDetails());
Debug.Log("Helpshift - Login called");
} catch (Exception e)
{
Debug.Log("Error in Helpshift - Login." + e.Message);
}
#endif
}
public void Logout()
{
#if UNITY_ANDROID || UNITY_IOS
_helpshiftX.Logout();
Debug.Log("Helpshift - Logout called");
#endif
}
public void AddCIF()
{
#if UNITY_ANDROID || UNITY_IOS
Debug.Log("Helpshift - Add CIF called");
Dictionary<string, string> cif = new Dictionary<string, string>();
string cifType = getDataFromDropDownField("cif_type");
string cifValue = getDataFromInputField("cif_value");
cif.Add("type", cifType);
cif.Add("value", cifValue);
string cifName = getDataFromInputField("cif_name");
if (!String.IsNullOrEmpty(cifType) && !String.IsNullOrEmpty(cifName))
{
cifDictionary.Add(cifName, cif);
} else
{
Debug.Log("Error adding CIF, invalid type or name");
}
#endif
}
private Dictionary<string, string> GetUserDetails()
{
string userId = getDataFromInputField("user_id");
string userName = getDataFromInputField("user_name");
string userEmail = getDataFromInputField("user_email");
string userAuthToken = getDataFromInputField("user_auth_token");
Dictionary<string, string> userDetails = new Dictionary<string, string>();
if (String.IsNullOrEmpty(userId) && String.IsNullOrEmpty(userEmail))
{
throw new Exception("Invalid User data.");
}
if (!String.IsNullOrEmpty(userId)) userDetails["userId"] = userId;
if (!String.IsNullOrEmpty(userEmail)) userDetails["userEmail"] = userEmail;
if (!String.IsNullOrEmpty(userName)) userDetails["userName"] = userName;
if (!String.IsNullOrEmpty(userAuthToken)) userDetails["userAuthToken"] = userAuthToken;
return userDetails;
}
private Dictionary<string, object> GetConversationConfig()
{
string tags = getDataFromInputField("comma_separate");
string[] tagsArray = tags.Split(',');
bool fullPrivacy = getFlagFromToggleField("full_privacy");
string contactUsValue = getDataFromDropDownField("enable_contactus_dropdown");
Dictionary<string, object> config = new Dictionary<string, object>();
config["customIssueFields"] = cifDictionary;
config["tags"] = tagsArray;
config["fullPrivacy"] = fullPrivacy;
config["enableContactUs"] = contactUsValue;
return config;
}
public static Dictionary<string, object> GetCifs()
{
Dictionary<string, string> joiningDate = new Dictionary<string, string>();
joiningDate.Add("type", "date");
joiningDate.Add("value", "1505927361535");
Dictionary<string, string> stockLevel = new Dictionary<string, string>();
stockLevel.Add("type", "n");
stockLevel.Add("value", "1505");
Dictionary<string, string> employeeName = new Dictionary<string, string>();
employeeName.Add("type", "sl");
employeeName.Add("value", "Bugs helpshift");
Dictionary<string, string> isPro = new Dictionary<string, string>();
isPro.Add("type", "b");
isPro.Add("value", "true");
Dictionary<string, object> cifDictionary = new Dictionary<string, object>();
cifDictionary.Add("joining_date", joiningDate);
cifDictionary.Add("stock_level", stockLevel);
cifDictionary.Add("employee_name", employeeName);
cifDictionary.Add("is_pro", isPro);
return cifDictionary;
}
private Dictionary<string, object> GetInstallConfig()
{
Dictionary<string, object> installDictionary = new Dictionary<string, object>();
installDictionary.Add(HelpshiftSdk.ENABLE_LOGGING, true);
#if UNITY_ANDROID
installDictionary.Add(HelpshiftSdk.NOTIFICATION_SOUND_ID, "custom_notification");
installDictionary.Add(HelpshiftSdk.NOTIFICATION_ICON,"notification_icon");
//installDictionary.Add(HelpshiftSdk.NOTIFICATION_CHANNEL_ID, "Example_HS_Support");
installDictionary.Add(HelpshiftSdk.NOTIFICATION_LARGE_ICON, "notification_icon");
#endif
return installDictionary;
}
private string getDataFromInputField(string fieldName)
{
InputField field = GameObject.Find(fieldName).GetComponent<InputField>();
return String.IsNullOrEmpty(field.text) ? "" : field.text;
}
private bool getFlagFromToggleField(string fieldName)
{
Toggle field = GameObject.Find(fieldName).GetComponent<Toggle>();
return field.isOn;
}
private string getDataFromDropDownField(string fieldName)
{
Dropdown field = GameObject.Find(fieldName).GetComponent<Dropdown>();
return field.options[field.value].text;
}
#endif
}
}