Skip to main content

Crm Sync Settings

This package contains functions for retrieving and updating a team's CRM Sync Settings and Poller data.

CRM Sync Settings

A team's CRM Sync Settings data can be retrieved. Poller data can be retrieved provided a list of poller types given by CRM Sync Settings. All GET requests are cached for 1 day.

Getting CRM Sync Settings

CRM Sync Settings can be retrieved asynchronously using getCrmSyncSettings.

import { getCrmSyncSettings } from '@shared/crm-sync-settings'

async function retrieveSettings() {
const settings = await getCrmSyncSettings()

console.log(settings)
}

Getting CRM Sync Settings using a hook

import { useCrmSyncSettings } from '@shared/module-allotments'

function retrieveSettings() {
const { data, isLoading } = useCrmSyncSettings()

// ...

return <span>Is CRM Sync enabled ? {data.enabled ? 'Yes' : 'No'}</span>
}

Updating a value in CRM Sync Settings

We can update a team's CRM Sync Settings using updateCrmSyncSettings.

import { updateCrmSyncSettings } from '@shared/crm-sync-settings'

async function updateSettings() {
const response = await updateCrmSyncSettings({
enabled: true,
})

console.log(response)
}

This function automatically busts the CRM sync settings cache.

These fields are currently properties available on CRM Sync Settings that can be updated with the correct type.

fieldtype
calls_as_native_crm_typeboolean
crm_link_orderstring[]
crm_sync_alert_emailstring
crm_typestring
dialer_alternate_logging_enabledboolean
emails_as_native_crm_typeboolean
enabledboolean
gmail_alternate_logging_enabledboolean
has_crmboolean
main_account_idnumber
meetings_as_eventsboolean
merge_and_delete_enabledboolean
poller_typesstring[]
recognize_crm_deletionsboolean
record_type_idstring
sync_ownershipboolean
person_accounts_enabledboolean

Busting the Cache

We can bust the team's CRM Sync Settings cache across all areas its' properties are being used with invalidateCrmSyncSettings.

import { invalidateCrmSyncSettings } from '@shared/crm-sync-settings'

// Bust the cache and wait to refetch until CRM Sync Settings is asked for
invalidateCrmSyncSettings()

// Bust the cache and refetch immediately if anything is using CRM Sync Settings
invalidateCrmSyncSettings({ refetch: true })

Pollers

Getting Poller data

Getting Poller data can be retrieved asynchronously using getCrmSyncSettings and getPollers. You need to retrieve poller types from CrmSyncSettings first. Poller types are an array of strings to only include: Account, Lead, Contact, or Opportunity.

import { getCrmSyncSettings, getPollers } from '@shared/crm-sync-settings'

async function retreiveSettingsWithPollers() {
const settings = getCrmSyncSettings()
const pollers = await getPollers(settings.poller_types)

console.log(pollers)
}

Updating a Poller's properties

We can update a poller's frequency or custom poll interval using updatePollers.

import { updatePoller } from '@shared/crm-sync-settings'

async function updatePollerFrequency() {
const response = await updatePoller({
type: 'Opportunity',
frequency: 10,
})

console.log(response)
}

These fields can be updated except for type. type must be passed in order to identify which poller to update.

fieldtypenotes
typestring
frequencynumber
custom_poll_intervalstring2021-07-21T17:46:09-04:00

⚠️ Poller Status API Usage and Fallback Strategy

  • Rhapsody now uses the public poller/index endpoints from xx-proxy and crm-repo to fetch poller status. These endpoints are read-only and provide aggregated poller status data.
  • The Melody API is used only as a fallback for fetching poller status if the new endpoints are unavailable or the feature flag is off.
  • Updating poller status (e.g., frequency, custom interval) is only possible via the Melody API. The new poller/index endpoints do not support updates.
  • All code paths and documentation should reflect that Melody is fallback for fetching, but still primary for updates.

Note: If you are updating poller properties, you must use the Melody API. If you are fetching poller status, the new endpoints are used by default, with Melody as fallback.