Automating callback numbers for Click to dial using Apex

If enabled for your account, you can configure Vonage Contact Center to dynamically select a callback number. The dynamically selected callback number takes precedence for individual calls over both the callback number defined by your agent in ContactPad and your account's default callback number. For information about callback numbers, see Callback numbers.

To use a callback number, that number must be configured and available for your account. To add a new callback number to use with your account, contact support.

You can use this feature in various ways depending on how your Salesforce org is set up. To override callback numbers, create a custom Apex class that implements the VCCCore.ISelectPresentedClid interface and defines the GetPresentedClid method. The GetPresentedClid method describes how VCC can generate or locate the callback number. VCC can then present this number as the callback number.

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

Configure custom settings

When you have created your class, ensure that VCC uses the class in Salesforce. For information about configuring the class that VCC uses to select the presented CLID, see Configuring custom settings for optional Vonage Contact Center features in Salesforce.

You can create different Apex classes to define callback behaviors for different departments and users. Define the required class for specific profiles or users in hierachical custom settings.

VCCCore.ISelectPresentedClid interface definition

global interface ISelectPresentedClid{
	PresentedClidResponse GetPresentedClid(String clickToDialJson);
}

The clickToDialJson contains the phone number that the agent clicked to dial, and the object ID and type of the Salesforce object from which the agent clicked. clickToDialJson is in JSON string format, for example, {"number":"4155551212","objectId":"001x0000003DIGj","object":"Account"}. You do not need to provide clickToDialJson because Salesforce passes the value to the method for you when an agent initiates a Click to dial event.

GetPresentedClid returns the callback number as a VCCCore.PresentedClidResult object.

Value
Data Type
Description
presentedClidString

String containing the CLID to present.

isErrorBooleanIf true, 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.PresentedClidResult:

  • global PresentedClidResult (String presentedCLid)

  • global PresentedClidResult (Boolean isError, String errorMessage)

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

VCC validates the presentedClid value returned by the GetPresentedClid method according to the following rules:

  • if a null or blank value is returned, the Click to dial call continues and VCC uses the agent's default callback number, if set, or the account's default callback number
  • if a non-null value is returned but the value is not configured as a callback number for the account, the agent receives an error message
  • if a non-null value is returned and the value is configured as a callback number for the account, but that callback number is restricted from the agent, the agent receives an error message
  • if a non-null value is returned and the value is configured as a callback number for the account and that callback number is not restricted from the agent, the Click to dial call continues, and the value is used as the callback number for the call
 Example 1

In our first example, the presented callback number is stored in and retrieved from a custom field, called ClickToDialPresentedClid, on an Account object. Firstly we created an Account object field called ClickToDialPresentedClid. For information about creating custom fields, see Salesforce help.

Secondly, we created a new Apex class called SelectPresentedClidForContactByAccount:

global class SelectPresentedClidForContactByAccount implements VCCCore.ISelectPresentedClid{
    
    // The clickToDialResult parameter contains the response string from the Salesforce ClickToDial event.
    // Salesforce passes the clickToDialResult parameter to us:
    // for example '{number: "07890123456", objectId: "0032000001FTGSo", object: "Contact"}'
    // Find more information at: https://www.salesforce.com/us/developer/docs/api_cti/Content/sforce_api_cti_onclicktodial.htm
 
    global VCCCore.PresetedClidResult GetPresentedClid(String clickToDialJson){
         
        Map<String,Object> clickToDialResultMap = (Map<String,Object>)JSON.deserializeUntyped(clickToDialJson);
        String contactId = (String)clickToDialResultMap.get('objectId');
         
        Contact c = [SELECT Id, AccountId FROM Contact WHERE Id = :contactId];
        Account a = [SELECT Id, ClickToDialPresentedClid__c FROM Account WHERE Id = :c.AccountId];
         
        String presentedClid = a.ClickToDialPresentedClid__c;
         
        return new VCCCore.PresentedClidRsult(presentedClid);       
    }
}

When an agent clicks to dial a number in a contact record, VCC runs our GetPresentedClid method in the SelectPresentedClidForContactByAccount class, which implements the ISelectPresentedClid interface. The GetPresentedClid method performs the following tasks:

  • receives the details (clickToDialJson) of the Click to dial event
  • uses the objectId from clickToDialJson to identify the contact record from which the agent initiated the call
  • locates the record for the account to which the contact belongs
  • returns the number from the custom field (ClickToDialPresentedClid__c) on the account record

VCC uses the returned number as the callback number. The number appears both in ContactPad and on handset of the person that the agent has clicked to dial.

 Example 2

In our second example, the presented callback number is set according to whether the customer's telephone number is a mobile—or cell—number, a number with a London area code, or other number.

The Apex class that implements NVMContactWorld.SelectPresentedClidByPolicy is called SelectPresentedClidForContactByAccount:

global class SelectPresentedClidByPolicy implements VCCCore.ISelectPresentedClid{
     
    // The clickToDialResult parameter contains the response string from the Salesforce ClickToDial event.
    // Salesforce passes the clickToDialResult parameter to us:
    // for example '{number: "07890123456", objectId: "0032000001FTGSo", object: "Contact"}'
    // Find more information at: https://www.salesforce.com/us/developer/docs/api_cti/Content/sforce_api_cti_onclicktodial.htm
  
    global VCCCore.PresentedClidResult GetPresentedClid(String clickToDialJson){
          
        Map<String,Object> clickToDialResultMap = (Map<String,Object>)JSON.deserializeUntyped(clickToDialJson);
        String customerNumber = (String)clickToDialResultMap.get('number');
        
        //Account default
        String presentedClid = '01234567890';
          
        if (customerNumber.startsWith('07') || customerNumber.startsWith('+447')) {
            //Mobile, or cell, numbers
            presentedClid = '07123456789';
        } else if (customerNumber.startsWith('0207') || customerNumber.startsWith('+44207')) {
            //Basingstoke numbers
            presentedClid = '02071234567';
        }
          
        return new VCCCore.PresentedClidResult(presentedClid);    
    }
}

When an agent clicks to dial a number in a contact record, VCC runs the GetPresentedClid method in the SelectPresentedClidByPolicy. The GetPresentedClid method performs the following tasks:

  • receives the details (clickToDialJson) of the Click to dial event
  • uses the number from clickToDialJson to identify the customer's telephone number, which the agent clicked to dial
  • returns the appropriate number:
    • if the customer's number is a mobile number, the method returns a mobile number
    • if the customer's number has a London area code, the method returns a London area code
    • if the customer's number is any other number, the method returns the default number (01234567890)

VCC uses the returned number as the callback number. The number appears both in ContactPad and on handset of the person that the agent has clicked to dial.

This feature is not currently available for calls made from the NVM Call action in Salesforce1.

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.