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.
| field | type |
|---|---|
| calls_as_native_crm_type | boolean |
| crm_link_order | string[] |
| crm_sync_alert_email | string |
| crm_type | string |
| dialer_alternate_logging_enabled | boolean |
| emails_as_native_crm_type | boolean |
| enabled | boolean |
| gmail_alternate_logging_enabled | boolean |
| has_crm | boolean |
| main_account_id | number |
| meetings_as_events | boolean |
| merge_and_delete_enabled | boolean |
| poller_types | string[] |
| recognize_crm_deletions | boolean |
| record_type_id | string |
| sync_ownership | boolean |
| person_accounts_enabled | boolean |
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.
| field | type | notes |
|---|---|---|
| type | string | |
| frequency | number | |
| custom_poll_interval | string | 2021-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.