feat: add user hash for intercom (#8263)
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com>pull/8390/head
parent
877220caa0
commit
8a2ab68e9a
|
@ -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=
|
||||
|
||||
|
|
|
@ -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 }),
|
||||
});
|
|
@ -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 (
|
||||
|
|
|
@ -187,12 +187,12 @@ export default function HelpMenuItem({ onHelpItemSelect }: HelpMenuItemProps) {
|
|||
<p className="">{t("specific_issue")}</p>
|
||||
<button
|
||||
className="hover:text-emphasis text-defualt font-medium underline"
|
||||
onClick={() => {
|
||||
onClick={async () => {
|
||||
setActive(true);
|
||||
if (isFreshChatEnabled) {
|
||||
setFreshChat(true);
|
||||
} else if (isInterComEnabled) {
|
||||
open();
|
||||
await open();
|
||||
} else {
|
||||
loadChat({ open: true });
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ export default function IntercomMenuItem(props: IntercomMenuItemProps) {
|
|||
|
||||
return (
|
||||
<button
|
||||
onClick={() => {
|
||||
open();
|
||||
onClick={async () => {
|
||||
await open();
|
||||
onHelpItemSelect();
|
||||
}}
|
||||
className="hover:bg-subtle hover:text-emphasis text-default flex w-full px-5 py-2 pr-4 text-sm font-medium">
|
||||
|
|
|
@ -25,12 +25,21 @@ export const useIntercom = () => {
|
|||
const { hasPaidPlan } = useHasPaidPlan();
|
||||
const { hasTeamPlan } = useHasTeamPlan();
|
||||
|
||||
const open = () => {
|
||||
const open = async () => {
|
||||
let userHash;
|
||||
|
||||
const req = await fetch(`/api/intercom-hash`);
|
||||
const res = await req.json();
|
||||
if (res?.hash) {
|
||||
userHash = res.hash;
|
||||
}
|
||||
|
||||
hookData.boot({
|
||||
name: data?.name ?? "",
|
||||
email: data?.email,
|
||||
userId: String(data?.id),
|
||||
createdAt: String(dayjs(data?.createdDate).unix()),
|
||||
...(userHash && { userHash }),
|
||||
customAttributes: {
|
||||
//keys should be snake cased
|
||||
user_name: data?.username,
|
||||
|
|
|
@ -277,6 +277,7 @@
|
|||
"ZOHOCRM_CLIENT_ID",
|
||||
"ZOHOCRM_CLIENT_SECRET",
|
||||
"ZOOM_CLIENT_ID",
|
||||
"ZOOM_CLIENT_SECRET"
|
||||
"ZOOM_CLIENT_SECRET",
|
||||
"INTERCOM_SECRET"
|
||||
]
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue