Hotline Phonegap plugin:


This plugin integrates Hotline's SDK into a Phonegap/Cordova project.


For platform specific details please refer to the Documentation.


To integrate Hotline Cordova SDK with your app you will need your App ID and App Key. You can get the same from the Settings page. Do not share them with anyone.

Supported platforms :

  • Android
  • iOS

1. Integrating the plugin:

      1.1 Add required platforms to your Cordova project 

phonegap platform add android
phonegap platform add ios

  

       1.2 Add the Hotline project to your project

   

phonegap plugin add hotline

   

2. Initializing the plugin:


Hotline.init() needs to be called from ondeviceready event listener to make sure the SDK is initialized before use.

  

document.addEventListener("deviceready", function(){
  // Initialize Hotline with your AppId & AppKey from your portal https://web.hotline.io/settings/apisdk
  window.Hotline.init({
    appId       : "<Your App Id>",
    appKey      : "<Your App Key>"
  });
});

  

If you are a Konotor user add a key called "domain" and "app.konotor.com" as its value. So your init code would look like this:

   

document.addEventListener("deviceready", function(){
  //Initialize Hotline
  window.Hotline.init({
    appId       : "<Your App Id>",
    appKey      : "<Your App Key>",
    domain      : "app.konotor.com"
  });
});

   

The following optional boolean parameters can be passed to the init object:

    • agentAvatarEnabled
    • cameraCaptureEnabled
    • voiceMessagingEnabled
    • pictureMessagingEnabled
    • showNotificationBanner( iOS only)

Here is a sample init code with the optional init parameters.  

window.Hotline.init({
          appId       : "<Your App Id>",
          appKey      : "<Your App Key>",
          agentAvatarEnabled      : true,
          cameraCaptureEnabled    : false,
          voiceMessagingEnabled   : true,
          pictureMessagingEnabled : true
      });

  

The init function is also a callback function and can be implemented like this:

  

window.Hotline.init({
          appId       : "<Your App Id>",
          appKey      : "<Your App Key>",
          agentAvatarEnabled      : true,
          cameraCaptureEnabled    : false,
          voiceMessagingEnabled   : true,
          pictureMessagingEnabled : true
      }, function(success){
          console.log("This is called form the init callback");
      });

  

Once initialized you can call Hotline APIs using the window.Hotline object.

   

//After initializing Hotline 
showSupportChat = function() { 
    window.Hotline.showConversations();
};
document.getElementById("launch_conversations").onclick = showSupportChat;


//in index.html
//<button id="launch_conversations"> Inbox </button>

   

3. Hotline APIs


  • Hotline.showFAQs() - Launch FAQ/ Self Help 
               The following FAQOptions can be passed to the showFAQs() call
                      -showFaqCategoriesAsGrid
                      -showContactUsOnAppBar
                      -showContactUsOnFaqScreens
                      -showContactUsOnFaqNotHelpful
                Here is a sample call to showFAQs() with the additional parameters:

 

window.Hotline.showFAQs( {
        showFaqCategoriesAsGrid     :true,
        showContactUsOnAppBar       :true,
        showContactUsOnFaqScreens   :true,
        showContactUsOnFaqNotHelpful:false
 });

     

          Tags can also be passed as parameters to filer solution articles,

               Here is a sample call to showFAQs() implementing tags.
      
window.Hotline.showFAQs( {
        tags :["sample","video"],
        filteredViewTitle   : "Tags"
});

  

  • Hotline.showConversations() - Launch Channels/ Conversations.
  • Hotline.unreadCount(callback) - Fetch count of unread messages from agents.
  • Hotline.updateUser(UserInfo) - UpdateUser accepts a UserInfo JSON of the following format:

   

{ 
   "name" : "John Doe", 
   "email" : "johndoe@dead.man", 
   "externalId" : "some unique Identifier from your system", 
   "countryCode" : "+91", 
   "phoneNumber" : "1234234123"
}

  

  • Hotline.updateUserProperties(userPropertiesJson) - update custom user properties using a JSON containing key, value pairs. A sample JSON is as follows: 
{
   "user_type" : "Paid",
   "plan" : "Gold"
}

 

  • Hotline.clearUserData() - clear the user data when a user logs off your app.
       you can pass in an optional callback function to any API call as the first parameter, which gets called when the API is completed. 
Eg:

  

window.Hotline.unreadCount(function(success,val) {
    //success indicates whether the API call was successful
    //val contains the no of unread messages
});

  

4. Push Notifications


To setup push notifications we recommend using our forked version of the phonegap-plugin-push available here

It can be installed by the following command : 

  

cordova plugin add https://github.com/freshdesk/phonegap-plugin-push.git

  


When you receive a deviceToken from GCM or APNS , you need to update the deviceToken in hotline as follows

 

// Example illustrates usage for phonegap-push-plugin
    push.on('registration',function(data) {
        window.Hotline.updateRegistrationToken(data.registrationId);
});

 

Whenever a push notification is received. You will need to check if the notification originated from Hotline and have Hotline SDK handle it.

 

// Example illustrates usage for phonegap-push-plugin
push.on('notification',function(data) {
  window.Hotline.isHotlinePushNotification(data.additionalData, function(success, isHotlineNotif) {
    if( success && isHotlineNotif ) {
      window.Hotline.handlePushNotification(data.additionalData);
    }
 });
});

 

Android notification properties can be changed with the updateAndroidNotificationProperties API. The properties that can be updated are.


- "notificationSoundEnabled" : Notification sound enabled or not.

- "smallIcon" : Setting a small notification icon (move the image to drawables folder and pass the name of the jpeg file as parameter).

- "largeIcon" : setting a large notification icon.

- "deepLinkTargetOnNotificationClick" : Toggles if the deeplink target of a notification should open on click.

- "notificationPriority" : set the priority of notification through hotline.

- "launchActivityOnFinish" : Activity to launch on up navigation from the messages screen launched from notification. The messages screen will have no activity to navigate up to in the back-stack when its launched from notification. Specify the activity class name to be launched.


The API is called like:

 

window.Hotline.updateAndroidNotificationProperties({
                "smallIcon" : "image",
                "largeIcon" : "image",
                "notificationPriority" : window.Hotline.NotificationPriority.PRIORITY_MAX,
                "notificationSoundEnabled" : false,
                "deepLinkTargetOnNotificationClick" : true
                "launchActivityOnFinish" : "MainActivity.class.getName()"
            });

 

List of hotline Priorities:


- Hotline.NotificationPriority.PRIORITY_DEFAULT

- Hotline.NotificationPriority.PRIORITY_HIGH

- Hotline.NotificationPriority.PRIORITY_LOW

- Hotline.NotificationPriority.PRIORITY_MAX

- Hotline.NotificationPriority.PRIORITY_MIN

They follow the same priority order as Android's NotificaitonCompat.



DEPRECATED!


If you have been using the registerPushNotification call up until now, we recommend you use the method suggested above as we are removing support for it

 

window.Hotline.registerPushNotification('ANDROID_SENDER_ID'); // takes care of registration and handling of push notification on iOS and Android.

 

Caveats:


Android :

  • Needs appcompat-v7 : 21+
  • Needs support-v4 : 21+
  • MinSdkVersion must be atleast 10 (in config.xml)


iOS :

  • Needs iOS 7 and above


In case of any queries, you can reach us anytime at support@hotline.io .