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 which participants to record the call are stored in a Map object: Map<String,VCCCore.CallRecordingResult.RecordingParticipant> called regionRules. The keys of the Map are the area codes and the recording participant values to provide the decisions.
global class CallRecordingParticipantsByAreaCode 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 which participants to include when recording a call
private static final Map<String,VCCCore.CallRecordingResult.RecordingParticipant> regionRules = new Map<String,Boolean>{
// Fresno, CA
'209' => VCCCore.CallRecordingResult.RecordingParticipant.AgentsOnly,
// Atlanta, GA
'404' => VCCCore.CallRecordingResult.RecordingParticipant.All,
// Chicago, IL
'708' => VCCCore.CallRecordingResult.RecordingParticipant.All,
// Boston, MA
'978' => VCCCore.CallRecordingResult.RecordingParticipant.AccountDefault
};
// This method is your implementation of our interface
global VCCCore.CallRecordingResult GetIsCallRecordingRequired(String clickToDialJson);{
VCCCore.CallRecordingResult.RecordingParticipant decision = null;
String outboundNumber = getOutboundNumberFromJson(clickToDialJson);
String areaCode = getAreaCodeFromPhoneNumber(outboundNumber);
decision = regionRules.get(areaCode);
return new VCCCore.CallRecordingResult(true, 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;
}
}