Automating call recording for outbound calls using Apex

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

The custom rule that you create takes precedence for individual calls over your default Vonage Contact Center 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 VCCCore.ISelectCallRecording interface and defines the GetIsCallRecordingRequired method. Your GetIsCallRecordingRequired method must describe the logic that determines whether or not to record the call for a given number and return a VCCCore.CallRecordingResult object that tells Vonage Contact Center 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.

VCCCore.ISelectCallRecording interface definition:

global interface ISelectCallRecording {

VCCCore.CallRecordingResult GetIsCallRecordingRequired(String clickToDialJson);

}

The clickToDialJson contains the outbound phone number in JSON format: {"outboundNumber":"4155551212"}. You do not need to provide clickToDialJson because Vonage Contact Center passes the value to the method for you when an agent initiates an outbound call. The GetIsCallRecordingRequired method in your class must return a VCCCore.CallRecordingResult object.

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

To get the outboundNumber from the clickToDialJson, use an Apex JSON parser as in the  getOutboundNumberFromJson method in our example. Future releases of Vonage Contact Center 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 Vonage Contact Center uses the class. For information about configuring the class that Vonage Contact Center uses to automate call recording, see Configuring custom settings for optional Vonage Contact Center features in Salesforce.

Vonage Contact Center uses the values in the returned CallRecordingResult object to determine whether or not to record the call:

ValueData TypeDescription
isRecordingRequiredBoolean
  • 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 apply
isErrorBooleanIf true, isError indicates to Vonage that an error occurred in your custom code.
errorMessageStringIf isError is true, this string should contain a useful error message.

Constructors available on VCCCore.CallRecordingResult:

  • global CallRecordingResult(Boolean isRecordingRequired)

  • global CallRecordingResult(Boolean isError, String errorMessage)

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 VCCCore.ISelectCallRecording{
     
    // 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 VCCCore.CallRecordingResult GetIsCallRecordingRequired(String clickToDialJson);{
     
        Boolean decision = null;
        String outboundNumber = getOutboundNumberFromJson(clickToDialJson);
         
        String areaCode = getAreaCodeFromPhoneNumber(outboundNumber);       
        decision = regionRules.get(areaCode);
     
        return new VCCCore.CallRecordingResult(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;
    }
}
Support and documentation feedback

For general assistance, please contact Customer Support.

For help using this documentation, please send an email to docs_feedback@vonage.com. We're happy to hear from you. Your contribution helps everyone at Vonage! Please include the name of the page in your email.