2024-08-30 11:52:07 +00:00
|
|
|
import { ANONYMOUS_USERNAME, type User } from "constants/userConstants";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getAppsmithConfigs } from "ee/configs";
|
2022-02-25 06:13:16 +00:00
|
|
|
import { sha256 } from "js-sha256";
|
2024-08-06 14:52:22 +00:00
|
|
|
import { getLicenseKey } from "ee/utils/licenseHelpers";
|
2022-02-25 06:13:16 +00:00
|
|
|
|
2023-04-28 20:00:15 +00:00
|
|
|
const { appVersion, cloudHosting, intercomAppID } = getAppsmithConfigs();
|
2022-02-25 06:13:16 +00:00
|
|
|
|
|
|
|
|
export default function bootIntercom(user?: User) {
|
|
|
|
|
if (intercomAppID && window.Intercom) {
|
2024-08-30 11:52:07 +00:00
|
|
|
let name: string | undefined = user?.name;
|
|
|
|
|
let email: string | undefined = user?.email;
|
|
|
|
|
let username =
|
|
|
|
|
user?.username === ANONYMOUS_USERNAME ? undefined : user?.username;
|
2024-09-18 16:35:28 +00:00
|
|
|
|
2024-08-30 11:52:07 +00:00
|
|
|
if (!cloudHosting && username) {
|
|
|
|
|
// We are hiding their information when self-hosted
|
2022-02-25 06:13:16 +00:00
|
|
|
username = sha256(username || "");
|
|
|
|
|
// keep email undefined so that users are prompted to enter it when they reach out on intercom
|
|
|
|
|
email = undefined;
|
|
|
|
|
} else {
|
|
|
|
|
name = user?.name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.Intercom("boot", {
|
|
|
|
|
app_id: intercomAppID,
|
|
|
|
|
user_id: username,
|
|
|
|
|
email,
|
|
|
|
|
// keep name undefined instead of an empty string so that intercom auto assigns a name
|
|
|
|
|
name,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-04-28 20:00:15 +00:00
|
|
|
export const updateIntercomProperties = (instanceId: string, user?: User) => {
|
|
|
|
|
if (intercomAppID && window.Intercom) {
|
|
|
|
|
const { email } = user || {};
|
|
|
|
|
|
|
|
|
|
window.Intercom("update", {
|
|
|
|
|
email,
|
|
|
|
|
"Appsmith version": `Appsmith ${
|
|
|
|
|
!cloudHosting ? appVersion.edition : ""
|
|
|
|
|
} ${appVersion.id}`,
|
|
|
|
|
instanceId,
|
2023-05-15 11:18:34 +00:00
|
|
|
"License ID": getLicenseKey(),
|
2023-04-28 20:00:15 +00:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|