jcsrb / hotline-phonegap

Hotline Phonegap Plugin

Home Page:https://hotline.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hotline Phonegap plugin

Twitter

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

For platform specific details please refer to the Documentation

Supported platforms :

  • Android
  • iOS

Note : This is an early version and so expect changes to the API

Integrating the Plugin :

  1. Add required platforms to your PhoneGap project
cordova platform add android
cordova platform add ios
  1. Add the hotline plugin to your project.
cordova plugin add https://github.com/freshdesk/hotline-phonegap.git

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 have are a Konotor user add a key called "domain" and "app.konotor.com". 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 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 so:

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>

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)

    • Update user info. Accepts a JSON with 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 follows
{
   "user_type" : "Paid",
   "plan" : "Gold"
}
  • Hotline.clearUserData()
    • Clear user data when users logs off your app.

You can pass in an optional callback function to an API as the first parameter, which gets called when native 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
});

Push Notifications

To setup push notifications we recommend using our forked version of the phonegap-plugin-push available [here] (https://github.com/freshdesk/phonegap-plugin-push) . 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.handlePush(data.additionalData);
    }
 });
});
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

About

Hotline Phonegap Plugin

https://hotline.io


Languages

Language:Objective-C 57.9%Language:Java 35.8%Language:JavaScript 6.3%