1. Adding Hotline SDK to your Unity App:


1.1 Download the Hotline Unity package from here 


1.1.1 Download sample Hotline integration script from here


1.2 Import Unity package 

Open Projects Tab, right click on asset folder then select Import Package -> Custom Package

Select the Hotline.unitypackage and import it into your project.


Note: For an iOS only app, do not import the assets under “Android” folder from the package.Similarly for an Android only app, do not import assets under "iOS" folder.


2. Initialize and configure Hotline 

You need to initialize the Hotline SDK to connect Hotline to your app. You can also send user information including Name, Email, Phone Number and custom properties to help segment users. 


2.1 Add HotlineSDK namespace into your app as follows


using HotlineSDK;


2.2 Initialize the SDK

private static HotlineSDK _hotline;

public static Hotline getHotline() {
  if (_hotline == null) {
   _hotline = HotlineiOSSDK.getInstance();
  }
  return _hotline;
 }
 //Add your app id and app key
HotlineConfig config = new HotlineConfig("App_Id", "App_Key");

// Enable notification banner to show updates when the app is open only for iOS
config.setNotificationBanner(true);

// Enable picture message for messages
config.SetPictureMessageEnabled(true);

// Enable attaching pictures straight from camera
config.SetCameraCaptureEnabled(true);

// Initialize SDK with the above configuration
getHotline().init(config);


Note: you can get the App_Id and App_Key from the dashboard


2.3 Send User Info

You can send basic user information at any point to give you more context on the user when your support agents are messaging with users

HotlineUser hlUser = new HotlineUser();
hlUser.setEmail("user_101@demo.com");
hlUser.setName("iOSUser101");
hlUser.setPhoneNumber("+91", "1234556789");
getInstance().UpdateUser(hlUser);


2.4 Send Custom Properties

Add and send custom user properties(key value pairs), into dictionary and pass it to the SDK as mentioned below :

Dictionary<string, string> properties = new Dictionary<string, string> {
    { "property1", "value1" },
    { "property2", "value2" }
};
getHotline ().UpdateUserProperties (properties);


2.5 Clear user data

Clear user data at logout by invoking the clearUserData API. This will clear all user data including conversations from the app and users’ can no longer access old conversations after this. 

getHotline ().ClearUserData ()


3. Launching the Support Experience

Use the code below to launch into the FAQ or Conversation based support experience from a call to action in your app. Your call to action or entry point could be a menu item in your game or an option in main screen of the game.


3.1 FAQs

Use the showFAQs() API to launch the FAQs screen. By default the FAQ Categories is displayed as a grid with a “Contact Us” button at the bottom. For customising this, check the FAQ Options.

Eg. To launch default FAQ experience:

getHotline ().ShowFAQs ()


Customize the FAQ experience

Customizations to the FAQ Flow can be achieved by specifying the relevant options in the FaqOptions instance passed to the showFAQs() API as listed below.

 

FaqOptions faqOptions = new FaqOptions();

// Pass false to change it to display FAQs as list, default is Grid
faqOptions.ShowFaqCategoriesAsGrid(true);

// Pass false to hide “Contact Us” option in FAQ screens
faqOptions.ShowContactUsOnFaqScreens(true);

// Pass true to display “Contact Us” in top bar (ActionBar/AppBar)
faqOptions.ShowContactUsOnAppBar(true);

// Specify the tags with which the faqs should be filtered 
// and optionally the title for the filtered faq view.
string[] faqTags = {
 "Tag1",
 “Tag2”
};
faqOptions.filterByTags(faqTags, "Filtered_Screen_Title");

getHotline().ShowFAQs(faqOptions);


3.2 Conversations

Use the showConversations() API to launch the Conversation Flow.If the app has multiple channels configured, the user will see the channel list.If the app has only one channel configured, the user will be directy taken to the conversation.


getHotline ().ShowConversations ()


4. Enable Push Notifications



4.1 iOS


Register your app for notification

Include the following header for receiving notification in iOS


using NotificationServices = UnityEngine.iOS.NotificationServices;
using NotificationType = UnityEngine.iOS.NotificationType;


To register your iOS app to receive remote notifications, implement RegisterAppForiOSNotification()


void RegisterAppForiOSNotification () {
    tokenSent = false;
    NotificationServices.RegisterForNotifications (
    NotificationType.Alert |
    NotificationType.Badge |
    NotificationType.Sound);
}


Call RegisterDeviceToken() into your script’s update() method to ensure the deviceToken is passed to Hotline, which is required for push notifications of your script file.


getInstance().UpdateDeviceToken(device_token);
    void RegisterDeviceToken() {
        byte[] token = NotificationServices.deviceToken;
        if (token != null) {
            string hexToken = System.BitConverter.ToString(token).Replace("-", "");
            UpdateDeviceToken (hexToken);
            tokenSent = true;
        }
    }

    void UpdateDeviceToken (string device_Token) {
        getHotline ().UpdateDeviceToken (device_Token);
    }


Pass Remote Notification to Hotline

When a notification is received, invoke HandleNotification() method of Hotline SDK to allow the SDK to process and display the push notification.


private static void handleNotification(Dictionary < string, object > notifData) {
 // if notifData is not in dictionary format, please convert to one 
 // Pass notification data to Hotline if it’s a Hotline Notification
 if (HotlineiOSSDK.getInstance().IsHotlineNotification(result) getHotline().IsHotlineNotification(result)) {
  HotlineiOSSDK.getInstance().HandleNotification(result);
  getHotline().HandleNotification(result);
 } else {
  // Process your app’s notification here
 }
}


Refer Unity’s documentation for device token and registering app for notifications here. https://docs.unity3d.com/ScriptReference/iOS.NotificationServices.RegisterForNotifications.html


4.2 Android


Register for push notification using your own GCM implementation or via other push plugins :

Step 1: Pass device token to Hotline : Call UpdateDeviceToken() to pass the device token received from GCM for the specific user’s device

getHotline().UpdateDeviceToken(gcm_device_token);



Step 2: Pass the notification to Hotline : From your app’s push implementation or push plugins handle notification or receive notification methods, pass notifications to Hotline by invoking HandleNotification() of Hotline as shown below

private static void handleNotification(Dictionary < string, string > result) {
 // if response result is not in dictionary format, please convert into one
 if (getHotline().IsHotlineNotification(result)) {
  getHotline().HandleNotification(result);
 }
}



Customize notifications

NotificationConfig notifConfig = new NotificationConfig();

//Set false to disable notification audio
notifConfig.SetNotificationSoundEnabled(true);

//Set false to disable deeplink on notification click
notifConfig.SetLaunchDeepLinkTargetOnNotificationClick(true);

//Update notification configuration values
getHotline().SetNotificationConfig(notifConfig);



5. Unread Count 

For users who don’t have push enabled, a badge count can be displayed somewhere in your app to grab user’s attention to unread messages. Invoke the GetUnreadCountAsync() API from your script’s update() or start() method 


getHotline().GetUnreadCountAsync(ProcessCount);
public void ProcessCount(int count) {
    //count is unread message count for your app
    Debug.Log("Your unread message count : " + count);
}