Skip to content

Commit

Permalink
Implements MOD-171: Intercom messenger integration on servers panel (#…
Browse files Browse the repository at this point in the history
…2959)

* feat: intercom

Signed-off-by: Evan Song <[email protected]>

* fix: double check

Signed-off-by: Evan Song <[email protected]>

* fix: address double booting

Signed-off-by: Evan Song <[email protected]>

---------

Signed-off-by: Evan Song <[email protected]>
  • Loading branch information
ferothefox authored Nov 22, 2024
1 parent c741ba2 commit d90cc09
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 44 deletions.
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"dependencies": {
"@formatjs/intl-localematcher": "^0.5.4",
"@intercom/messenger-js-sdk": "^0.0.14",
"@ltd/j-toml": "^1.38.0",
"@modrinth/assets": "workspace:*",
"@modrinth/ui": "workspace:*",
Expand Down
37 changes: 37 additions & 0 deletions apps/frontend/src/pages/servers/manage/[id].vue
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ import {
import DOMPurify from "dompurify";
import { ButtonStyled } from "@modrinth/ui";
import { refThrottled } from "@vueuse/core";
import { Intercom, shutdown } from "@intercom/messenger-js-sdk";
import type { ServerState, Stats, WSEvent, WSInstallationResultEvent } from "~/types/servers";
const socket = ref<WebSocket | null>(null);
Expand All @@ -275,6 +276,19 @@ const reconnectInterval = ref<ReturnType<typeof setInterval> | null>(null);
const isFirstMount = ref(true);
const isMounted = ref(true);
const INTERCOM_APP_ID = ref("ykeritl9");
const auth = await useAuth();
// @ts-expect-error - Auth is untyped
const userId = ref(auth.value?.user?.id ?? null);
// @ts-expect-error - Auth is untyped
const username = ref(auth.value?.user?.username ?? null);
// @ts-expect-error - Auth is untyped
const email = ref(auth.value?.user?.email ?? null);
const createdAt = ref(
// @ts-expect-error - Auth is untyped
auth.value?.user?.created ? Math.floor(new Date(auth.value.user.created).getTime() / 1000) : null,
);
const route = useNativeRoute();
const router = useRouter();
const serverId = route.params.id as string;
Expand Down Expand Up @@ -735,6 +749,8 @@ const openInstallLog = () => {
const cleanup = () => {
isMounted.value = false;
shutdown();
stopPolling();
stopUptimeUpdates();
if (reconnectInterval.value) {
Expand Down Expand Up @@ -774,6 +790,27 @@ onMounted(() => {
connectWebSocket();
}
if (username.value && email.value && userId.value && createdAt.value) {
const currentUser = auth.value?.user as any;
const matches =
username.value === currentUser?.username &&
email.value === currentUser?.email &&
userId.value === currentUser?.id &&
createdAt.value === Math.floor(new Date(currentUser?.created).getTime() / 1000);
if (matches) {
Intercom({
app_id: INTERCOM_APP_ID.value,
userId: userId.value,
name: username.value,
email: email.value,
created_at: createdAt.value,
});
} else {
console.warn("[PYROSERVERS][INTERCOM] mismatch");
}
}
DOMPurify.addHook(
"afterSanitizeAttributes",
(node: {
Expand Down
Loading

0 comments on commit d90cc09

Please sign in to comment.