Skip to content

Commit d90cc09

Browse files
authored
Implements MOD-171: Intercom messenger integration on servers panel (#2959)
* feat: intercom Signed-off-by: Evan Song <theevansong@gmail.com> * fix: double check Signed-off-by: Evan Song <theevansong@gmail.com> * fix: address double booting Signed-off-by: Evan Song <theevansong@gmail.com> --------- Signed-off-by: Evan Song <theevansong@gmail.com>
1 parent c741ba2 commit d90cc09

File tree

3 files changed

+110
-44
lines changed

3 files changed

+110
-44
lines changed

apps/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"dependencies": {
3636
"@formatjs/intl-localematcher": "^0.5.4",
37+
"@intercom/messenger-js-sdk": "^0.0.14",
3738
"@ltd/j-toml": "^1.38.0",
3839
"@modrinth/assets": "workspace:*",
3940
"@modrinth/ui": "workspace:*",

apps/frontend/src/pages/servers/manage/[id].vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ import {
266266
import DOMPurify from "dompurify";
267267
import { ButtonStyled } from "@modrinth/ui";
268268
import { refThrottled } from "@vueuse/core";
269+
import { Intercom, shutdown } from "@intercom/messenger-js-sdk";
269270
import type { ServerState, Stats, WSEvent, WSInstallationResultEvent } from "~/types/servers";
270271
271272
const socket = ref<WebSocket | null>(null);
@@ -275,6 +276,19 @@ const reconnectInterval = ref<ReturnType<typeof setInterval> | null>(null);
275276
const isFirstMount = ref(true);
276277
const isMounted = ref(true);
277278
279+
const INTERCOM_APP_ID = ref("ykeritl9");
280+
const auth = await useAuth();
281+
// @ts-expect-error - Auth is untyped
282+
const userId = ref(auth.value?.user?.id ?? null);
283+
// @ts-expect-error - Auth is untyped
284+
const username = ref(auth.value?.user?.username ?? null);
285+
// @ts-expect-error - Auth is untyped
286+
const email = ref(auth.value?.user?.email ?? null);
287+
const createdAt = ref(
288+
// @ts-expect-error - Auth is untyped
289+
auth.value?.user?.created ? Math.floor(new Date(auth.value.user.created).getTime() / 1000) : null,
290+
);
291+
278292
const route = useNativeRoute();
279293
const router = useRouter();
280294
const serverId = route.params.id as string;
@@ -735,6 +749,8 @@ const openInstallLog = () => {
735749
const cleanup = () => {
736750
isMounted.value = false;
737751
752+
shutdown();
753+
738754
stopPolling();
739755
stopUptimeUpdates();
740756
if (reconnectInterval.value) {
@@ -774,6 +790,27 @@ onMounted(() => {
774790
connectWebSocket();
775791
}
776792
793+
if (username.value && email.value && userId.value && createdAt.value) {
794+
const currentUser = auth.value?.user as any;
795+
const matches =
796+
username.value === currentUser?.username &&
797+
email.value === currentUser?.email &&
798+
userId.value === currentUser?.id &&
799+
createdAt.value === Math.floor(new Date(currentUser?.created).getTime() / 1000);
800+
801+
if (matches) {
802+
Intercom({
803+
app_id: INTERCOM_APP_ID.value,
804+
userId: userId.value,
805+
name: username.value,
806+
email: email.value,
807+
created_at: createdAt.value,
808+
});
809+
} else {
810+
console.warn("[PYROSERVERS][INTERCOM] mismatch");
811+
}
812+
}
813+
777814
DOMPurify.addHook(
778815
"afterSanitizeAttributes",
779816
(node: {

0 commit comments

Comments
 (0)