From 8a2ab68e9a307870857588fe4f92a75e2515f6af Mon Sep 17 00:00:00 2001 From: Nafees Nazik <84864519+G3root@users.noreply.github.com> Date: Thu, 20 Apr 2023 01:52:07 +0530 Subject: [PATCH] feat: add user hash for intercom (#8263) Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Peer Richelsen --- .env.example | 3 ++ apps/web/pages/api/intercom-hash.ts | 28 +++++++++++++++++++ apps/web/pages/settings/billing/index.tsx | 4 +-- .../ee/support/components/HelpMenuItem.tsx | 4 +-- .../support/lib/intercom/IntercomMenuItem.tsx | 4 +-- .../ee/support/lib/intercom/useIntercom.ts | 11 +++++++- turbo.json | 3 +- 7 files changed, 49 insertions(+), 8 deletions(-) create mode 100644 apps/web/pages/api/intercom-hash.ts diff --git a/.env.example b/.env.example index 0c369e0dd8..4ddb81f5eb 100644 --- a/.env.example +++ b/.env.example @@ -79,6 +79,9 @@ CALENDSO_ENCRYPTION_KEY= # Intercom Config NEXT_PUBLIC_INTERCOM_APP_ID= +# Secret to enable Intercom Identity Verification +INTERCOM_SECRET= + # Zendesk Config NEXT_PUBLIC_ZENDESK_KEY= diff --git a/apps/web/pages/api/intercom-hash.ts b/apps/web/pages/api/intercom-hash.ts new file mode 100644 index 0000000000..54f2419331 --- /dev/null +++ b/apps/web/pages/api/intercom-hash.ts @@ -0,0 +1,28 @@ +import type { NextApiRequest, NextApiResponse } from "next"; +import crypto from "node:crypto"; + +import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; +import { defaultHandler } from "@calcom/lib/server"; + +async function handler(req: NextApiRequest, res: NextApiResponse) { + const session = await getServerSession({ req, res }); + const secret = process.env.INTERCOM_SECRET; + + if (!session) { + return res.status(401).json({ message: "user not authenticated" }); + } + + if (!secret) { + return res.status(400).json({ message: "Intercom Identity Verification secret not set" }); + } + + const hmac = crypto.createHmac("sha256", secret); + hmac.update(String(session.user.id)); + const hash = hmac.digest("hex"); + + return res.status(200).json({ hash }); +} + +export default defaultHandler({ + GET: Promise.resolve({ default: handler }), +}); diff --git a/apps/web/pages/settings/billing/index.tsx b/apps/web/pages/settings/billing/index.tsx index 00cf1c14b9..142c6df4fb 100644 --- a/apps/web/pages/settings/billing/index.tsx +++ b/apps/web/pages/settings/billing/index.tsx @@ -39,8 +39,8 @@ const BillingView = () => { const returnTo = router.asPath; const billingHref = `/api/integrations/stripepayment/portal?returnTo=${WEBAPP_URL}${returnTo}`; - const onContactSupportClick = () => { - open(); + const onContactSupportClick = async () => { + await open(); }; return ( diff --git a/packages/features/ee/support/components/HelpMenuItem.tsx b/packages/features/ee/support/components/HelpMenuItem.tsx index 7bcdf66e4c..98b2b378aa 100644 --- a/packages/features/ee/support/components/HelpMenuItem.tsx +++ b/packages/features/ee/support/components/HelpMenuItem.tsx @@ -187,12 +187,12 @@ export default function HelpMenuItem({ onHelpItemSelect }: HelpMenuItemProps) {

{t("specific_issue")}