Skip to content

Commit

Permalink
fix: merge module config and function param userData to window.interc…
Browse files Browse the repository at this point in the history
…omSettings
  • Loading branch information
devonik committed Aug 15, 2023
1 parent 60eb33c commit 79cbcdc
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/runtime/Intercom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export interface IntercomUserData {
company?: IntercomUserCompany
/** An array of companies the user is associated to (Only applicable to users) */
companies?: Array<IntercomUserCompany>
/** Can be set in update. Intercom ID */
app_id?: string | undefined
/** Can be set in update. Hide the default launcher icon. Setting to false will forcefully show the launcher icon (See https://docs.intercom.com/configure-intercom-for-your-product-or-site/customize-the-intercom-messenger/turn-off-show-or-hide-the-intercom-messenger) */
hide_default_launcher?: boolean
}
export default class Intercom {
/** Intercom ID */
Expand Down Expand Up @@ -137,20 +140,27 @@ export default class Intercom {
/**
* Boot Intercom. If an appId is provided, this will be used for all future calls to Intercom.
*/
boot(userData: IntercomUserData = {}) {
if (userData.app_id)
this.appId = userData.app_id
boot(intercomSettings: IntercomUserData = {}) {
if (intercomSettings.app_id)
this.appId = intercomSettings.app_id

if (!window.intercomSettings)
window.intercomSettings = {}
window.intercomSettings.app_id = this.appId

Object.keys(this.config).forEach((key) => {
// Write configs into intercomSettings
for (const key of Object.keys(this.config)) {
const snakeCaseKey = key.replace(/([A-Z])/g, '_$1').toLowerCase()
window.intercomSettings[snakeCaseKey] = this.config[key]
})
}

// Write / Overwrite configs coming form function call e.g. by plugin call into intercomSettings
for (const key of Object.keys(intercomSettings)) {
const snakeCaseKey = key.replace(/([A-Z])/g, '_$1').toLowerCase()
window.intercomSettings[snakeCaseKey] = intercomSettings[key]
}

return this._updateData('boot', userData)
return this._updateData('boot', intercomSettings)
}

/**
Expand Down

0 comments on commit 79cbcdc

Please sign in to comment.