Custom Phone Integrations

On This Page

Available in Version 5.0 and up

A custom phone integration is only possible if your phone provider has an API that allows you to see who is on the phone in real time.

While Kubaru doesn’t have any native phone system integrations, we do provide you with needed inputs so that you can custom-build your own. This allows you to pause agents from receiving assignments while on the phone. You can additionally set a call wrap-up period so that they continue to be paused for a specified number of minutes after ending a call. Additionally, you can choose which routers will pause members while they are on a call.

Custom-Developing the Integration

The bulk of building the integration typically comes down to getting the call data into Salesforce. We cannot provide any specifics on how to fetch your data from your phone system, as how this is done will vary from provider to provider. And while this is only possible if your provider has an API that allows you to see who is on the phone in real time, many providers offer this ability. For example, here is Aircall’s API documentation.

Once you’ve identified your API method and have established a protocol to call out to the phone application, you will need to implement that protocol in a Callable apex class, which should then execute a method that performs a callout and syncs the data to Kubaru.

After fetching the phone data, you will need to land it in the nwcs_ldl__OnPhone__c (checkbox) field on the Kubaru package’s nwcs_ldl__User__c object, which reflects whether the user is on the phone (true) or not (false). While this is a custom object, it makes reference to the standard user in its nwcs_ldl__User__c field (user lookup). Also note that the Name field of each record has the same value as the Name field of the standard user record.

Here is some example Apex code that demonstrates how to structure your Callable apex class. In this example, we structure the callable class to initiate the method. From there, we make a callout to a phone system (a fictional one in this example), and obtain a set of email addresses of users who are on the phone in the response, and ensure that the data in the nwcs_ldl__User__c table matches with the retrieved data.

Please note that this example is not intended to be used as-is in your Salesforce environment.

Apex
// class must have global access modifier
global class KubaruPhoneIntegration implements Callable, database.allowsCallouts
{
    // call method must have global access modifier
    global static Object call (String method, Map<String,Object> args)
    {
        switch on method
        {
            when 'SyncPhoneData'
            {
                SyncPhoneData();
                return method + ' was successfully executed';
            }
        }
        
        return 'Could not find method "' + method + '"';
    }
    
    // must have constructor with no parameters that has global access modifier
    global KubaruPhoneIntegration(){}
    public static void SyncPhoneData()
    {
        Set<String> usersOnPhoneEmails = new Set<String>();
        
        // call out to phone system API, get emails of users who are on the phone and add their email addresses to Set<String> usersOnPhoneEmails
        HttpRequest request = new HttpRequest();
        request.setEndpoint('https://myphonesystem.com/getUsersOnPhoneByEmail');
        request.setHeader('Authorization','Bearer myApiToken-xxxxxx-1234567890');
        request.setHeader('Content-Type','application/json;charset=UTF-8');
        request.setMethod('GET');
        
        // in this example, each data packet has an email address as its key
        // the response format in reality will vary from system to system
        String response = new Http().send(request).getBody();
        Map<String,Object> resBody = (Map<String,Object>)JSON.deserializeUntyped(response);
        
        usersOnPhoneEmails.addAll(resBody.keySet());
        
        // fetch Kubaru user records that are either on the phone, or who are currently marked as such
        List<nwcs_ldl__User__c> users = [SELECT Id, nwcs_ldl__OnPhone__c, nwcs_ldl__User__r.Email FROM nwcs_ldl__User__c WHERE nwcs_ldl__OnPhone__c = true OR nwcs_ldl__User__r.Email IN :usersOnPhoneEmails];
        
        List<nwcs_ldl__User__c> updatedUsers = new List<nwcs_ldl__User__c>();
        
        // iterate through Kubaru users and ensure nwcs_ldl__OnPhone__c value matches phone data
        for (nwcs_ldl__User__c u : users)
        {
            if (usersOnPhoneEmails.contains(u.nwcs_ldl__User__r.Email))
            {
                if (!u.nwcs_ldl__OnPhone__c)
                {
                    u.nwcs_ldl__OnPhone__c = true;
                    updatedUsers.add(u);
                }
            }
            else if (u.nwcs_ldl__OnPhone__c)
            {
                u.nwcs_ldl__OnPhone__c = false;
                updatedUsers.add(u);
            }
        }
        
        // perform DML on any Kubaru users that were updated
        if (!updatedUsers.isEmpty())
            update updatedUsers;
    }
}

Things to keep in mind

  • Our own “call” execution of the above class will use your input string for the “method” param as detailed in the next section. However we only ever pass in an empty map (i.e. new Map()) into the “args” param.
  • Integrating Your Code With Kubaru

    Kubaru provides a convenient way for you to integrate your apex class with our recurring jobs so that your phone data can be synced nearly in real time.

    Follow these steps to enable your custom phone integration:

    1. Navigate to the Settings tab of the Kubaru Console.
    2. Check Show Custom Phone Integration Options.
    3. Click the link “Manage Apex Class”, select your callable apex class in Apex Class Name, and add the name of the call method parameter in Call Method if applicable.
    4. Click Save.
    5. Now navigate to each router for which you would like to enable the pause behavior and click the Manage Members button. Or for rule-based routers, edit a rule.
    6. Check Pause When On Phone.
    7. (Optional) Enter a value for “Do not resume assignments until ____ minutes after a call is ended” if you want to give users time to wrap up a call before receiving additional assignments. Leaving this blank will result in the user becoming available immediately after the call has ended.

    Things to keep in mind

  • Our recurring jobs typically run several times a minute. If you integrate an apex class that consumes a callout, this means you will incur that many callouts on an ongoing basis. Be mindful of your API usage limits.
  • Any failures that occur while attempting to execute your apex class will be caught so as to not cause any failures of our application’s normal processes, and an email will be sent to notify those designated in Kubaru Admin Alerts.
  • Was this article helpful?

    On This Page