Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 9 Current »

If enabled for your account, you can create a custom rule that determines whether ContactWorld records a call based on the outbound, or dialed, number.

The custom rule that you create takes precedence for individual calls over your default ContactWorld account settings. You can use this feature in various ways depending on how your Salesforce org is set up.

Your custom rule applies to all outbound calls, whether they were initiated using Connect or Click to dial.

To automate outbound call recording, create a custom Apex class that implements the NVMContactWorld.ICustomValueProvider interface and defines the GetCustomValue method. Your GetCustomValue method must describe the logic that determines whether or not to record the call for a given number, and return a String object that tells ContactWorld the outcome.

When using this feature make sure that your default account configuration complies with any regional legislation.

To create the custom class, familiarize yourself with creating Apex classes in Salesforce. For information on creating Apex classes, see Salesforce help.

NVMContactWorld.ICustomValueProvider interface definition

global interface ICustomValueProvider {
  String GetCustomValue(String context);
}

The context contains the outbound phone number in JSON format: {"outboundNumber":"4155551212"}. You do not need to provide context because ContactWorld passes the value to the method for you when an agent initiates an outbound call. The GetCustomValue method in your class must return a String object.

When creating your new class, you must declare both the class and the method as global so that the ContactWorld managed package can access the class and invoke the method.

To get the outboundNumber from the context, use an Apex JSON parser as in the  getOutboundNumberFromJson method in our example. Future releases of ContactWorld may add some extra attributes to the context, so if use any other method to get the outboundNumber (such as regular expressions or string splitting), your class may stop working.

When you have created your class, you must ensure that ContactWorld uses the class. For information about configuring the class that ContactWorld uses to automate call recording, see Configuring custom settings for optional Vonage Contact Center features in Salesforce.

ContactWorld uses the value of the returned String object to determine whether or not to record the call:

  • If the value of the String object is 'true', the call is recorded
  • If the value of the String object is 'false', the call is not recorded
  • If the value of the String object is any other value including null, the default account settings for recording calls applies

If an error occurs when an agent makes a call that triggers the apex code, a message appears in the agent's ContactPad. This message alerts them that the default call recording settings for the account have been applied and suggests that they contact their system administrator.

 Example 1

In our example, the dialed number for the outbound call is supplied to the implementing class as the context parameter of the GetCustomValue method. The rules about whether or not to record the call are stored in a Map object: Map<String,Boolean> called regionRules. The keys of the Map are the area codes and the Boolean values provide the decisions.

global class CallRecordingByAreaCode implements NVMContactWorld.ICustomValueProvider{
     
    // Build a regular expression to extract the area code from a full phone number   
    private static final String leftBracketPatternSegment = Pattern.quote('(');
    private static final String rightBracketPatternSegment = Pattern.quote(')');
    private static final String captureAreaCodePatternSegment = '([0-9]{3})';
    private static final String restOfPhoneNumberPatternSegment = '.*';
     
    private static final Pattern areaCodePattern = Pattern.compile(
            leftBracketPatternSegment +
            captureAreaCodePatternSegment +
            rightBracketPatternSegment +
            restOfPhoneNumberPatternSegment);
     
    // A map contains your rules for deciding whether or not to record a call
    private static final Map<String,Boolean> regionRules = new Map<String,Boolean>{
        // Fresno, CA
        '209' => true,
        // Atlanta, GA
        '404' => false,
        // Chicago, IL
        '708' => true,
        // Boston, MA
        '978' => false           
    };
         
         
    // This method is your implementation of our interface
    global String GetCustomValue(String context){
     
        Boolean decision = null;
        String outboundNumber = getOutboundNumberFromJson(context);
         
        String areaCode = getAreaCodeFromPhoneNumber(outboundNumber);       
        decision = regionRules.get(areaCode);
     
        return String.valueOf(decision);       
    }
    
    private static String getOutboundNumberFromJson(String context){
        Map<String, String> mapFromJson = (Map<String,String>)System.JSON.deserialize(context, Map<String,String>.class);
        String outboundNumber = mapFromJson.get('outboundNumber');
        System.debug(outboundNumber);
        return outboundNumber;
    }     
     
    private static String getAreaCodeFromPhoneNumber(String phoneNumber){
        String areaCode = null;     
        Matcher areaCodeMatcher = areaCodePattern.matcher(phoneNumber);
         
        if(areaCodeMatcher.matches()){
            areaCode = areaCodeMatcher.group(1);
            System.debug('area code: ' + areaCode);
        }
         
        return areaCode;
    }
}
  • No labels