getCRMDirectory

getCRMDirectory

Mandatory: No

Description: When the Address Book is opened from the navigation bar, the CRM Connector application will send a requestGetCRMDirectory request to the client application. This request is to fetch contacts from the CRM and send them back to CRM Connector to populate the Address Book directory.

Example

// For publishMessage method explanation see Getting started.
const sendCRMData = () => {
  // Your own implementation to obtain the directory data based on the CRM.
  publishMessage(clientIframe, CRM_CONNECT_ORIGIN, 'ClientAppMessage', 'crmDirectory', <data>);
}
  • clientIframe represents the iFrame where the application is embedded. usually we can set an id and access in this way
// This is a dummy id. You can use another one if you see fit.
clientIframe = document.getElementById('crmConnectIframeId');
  • CRM_CONNECT_ORIGIN represents the URL or origin of the CRM Connector application. For a more explicit documentation see Getting started.

  • data represents the entire directory of the contacts fetched by Client Application.

Note: For each message sent by CRM Connector that needs to be intercepted by the client application, ensure there is a mechanism in place to verify and process the received messages.

Implementation example

// You can replace these validating methods with anything that suits you better
export const validateContactMethods = (user) => Boolean(user && (user.email || user.phone));

export const getDirectoryNumbers = (users) => users
  .filter(validateContactMethods)
  .map(({ id, name, phone, email }) => ({ id, name, phone, email }));

export const loadCRMUsers = async () => {
  const response = await <Your_implementation_of_fetching_the_users>;
  
  // Replace response.array with your actual CRM API response
  if (response.status !== 200 || !<response.array>.length) {
    // Error handling mechanism
    return;
  }

  const responseUsers = <response.array>;
  const directoryNumbers = getDirectoryNumbers(responseUsers);
  
  if (!responseUsers.length) {
    return;
  }

  return {
    count: directoryNumbers.length.toString(),
    results: directoryNumbers
  }
}

Message formats

CRM Connector

{ "type": "CRMConnectMessage", "action": "requestGetCRMDirectory", "data": <crmConnectorDataObject> }

CRM Connector data object format

{ 
  "global": <boolean>, 
  "ccdef": <string> // Subject to removal
}

Client Application

{ "type": "ClientAppMessage", "action": "crmDirectory", "data": <crmDirectoryObject> }

Expected crmDirectoryObject format

{
  "count": <string>, // The number of valid contact methods
  "results": <array> // The array consisting of the valid contact methods
}