From 79cbcdc85a660117d24e82238ddd98129059ff78 Mon Sep 17 00:00:00 2001 From: Niklas Grieger Date: Tue, 15 Aug 2023 12:05:20 +0200 Subject: [PATCH] fix: merge module config and function param userData to window.intercomSettings --- src/runtime/Intercom.ts | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/runtime/Intercom.ts b/src/runtime/Intercom.ts index 352e8a0..0183b22 100644 --- a/src/runtime/Intercom.ts +++ b/src/runtime/Intercom.ts @@ -68,7 +68,10 @@ export interface IntercomUserData { company?: IntercomUserCompany /** An array of companies the user is associated to (Only applicable to users) */ companies?: Array + /** 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 */ @@ -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) } /**