feat: implement tiered Intercom chat system replacing Plain (#23285)

* feat: implement tiered Intercom chat system replacing Plain

- Add TieredIntercomChat component with customer tier detection
- Add IntercomContactForm for free users using Intercom API
- Add /api/intercom-conversation endpoint for free user support
- Update UserDropdown to use tiered chat logic
- Replace Plain chat with Intercom in app providers
- Remove all Plain chat components and related files
- Use useHasPaidPlan hook for customer tier detection

Paying customers see Intercom widget, free users see contact form
that creates conversations via Intercom API.

Co-Authored-By: [email protected] <[email protected]>

* fix: add missing environment variables to turbo.json globalEnv

- Add NEXT_PUBLIC_WEBAPP_URL, NEXT_PUBLIC_WEBSITE_URL, NEXT_PUBLIC_STRIPE_PUBLIC_KEY
- Add NEXT_PUBLIC_IS_E2E, NEXT_PUBLIC_STRIPE_PREMIUM_PLAN_PRICE_MONTHLY
- Add NEXT_PUBLIC_BOOKER_NUMBER_OF_DAYS_TO_LOAD, NEXT_PUBLIC_STRIPE_CREDITS_PRICE_ID
- Resolves turbo/no-undeclared-env-vars ESLint errors blocking commits

Co-Authored-By: [email protected] <[email protected]>

* fix: resolve linting errors in platform examples base package

- Fix prettier/prettier formatting (quotes and comma)
- Add underscore prefix to unused variables
- Resolves CI failure in @calcom/base#lint check

Co-Authored-By: [email protected] <[email protected]>

* remove plain usage

* placement fixes

* fix: pop closing immediately issue

* stuff

* proper error and additional user info

* add key to .env.example and remove unused plain route

* fix conversation route

* refactor intercom dynamic provider

* code rabbit fixes

* feat: introduce tiered support feature flag

* fix: type check

* Apply suggestion from @coderabbitai[bot]

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-authored-by: Amit Sharma <[email protected]>
Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
This commit is contained in:
authored and GitHub committed 2025-09-09 18:20:22 +09:00
1 parent ca7c432728
commit 20b7ac8c0d
36 files changed
+635 -2208

No files matched your search

-92
View File
@@ -1,92 +0,0 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import prismaMock from "../../../../tests/libs/__mocks__/prismaMock";
import type { Params } from "app/_types";
import type { NextRequest } from "next/server";
import { describe, it, expect, vi, beforeAll, beforeEach } from "vitest";
import { getServerSession } from "@calcom/features/auth/lib/getServerSession";
import { IS_PLAIN_CHAT_ENABLED } from "@calcom/lib/constants";
import { POST } from "../../app/api/plain-hash/route";
// Mock NextResponse
vi.mock("next/server", () => ({
NextResponse: {
json: (data: any, init?: ResponseInit) => ({
json: async () => data,
status: init?.status || 200,
}),
},
}));
// Mock session
vi.mock("@calcom/features/auth/lib/getServerSession", () => ({
getServerSession: vi.fn(),
}));
vi.mock("next/headers", () => ({
headers: () => new Headers(),
cookies: () => ({ get: () => null }),
}));
vi.mock("@lib/buildLegacyCtx", () => ({
buildLegacyRequest: vi.fn().mockReturnValue({
headers: new Headers(),
cookies: {},
}),
}));
vi.mock("app/api/defaultResponderForAppDir", () => ({
defaultResponderForAppDir: (handler: () => Promise<Response>) => handler,
}));
vi.mock("@calcom/prisma", () => ({
default: prismaMock,
}));
describe("Plain Integration API", () => {
beforeAll(() => {
process.env.PLAIN_CHAT_HMAC_SECRET_KEY = "test-secret";
process.env.NEXT_PUBLIC_PLAIN_CHAT_ID = "test-chat-id";
// Force the feature to be enabled for tests
vi.mock("@calcom/lib/constants", () => ({
IS_PLAIN_CHAT_ENABLED: true,
}));
});
beforeEach(() => {
vi.resetAllMocks();
});
// Skip all tests if the feature is disabled
if (!IS_PLAIN_CHAT_ENABLED) {
it("skips tests when Plain Chat is disabled", () => {
console.log("Plain Chat is disabled, skipping tests");
});
return;
}
const tiers = [
{ tier: "free", teams: [] },
{ tier: "teams", teams: [{ team: { id: 2 } }] },
{ tier: "enterprise", teams: [{ team: { id: 3, isOrganization: true } }] },
];
it.each(tiers)("should return $tier tier", async ({ tier, teams }) => {
const userData = { id: 1, email: `${tier}@example.com`, name: `${tier} User` };
(getServerSession as any).mockResolvedValue({ user: userData });
prismaMock.user.findUnique.mockResolvedValue({ ...userData, teams });
const params = Promise.resolve<Params>({});
const data = await (await POST({} as NextRequest, { params })).json();
expect(data).toMatchObject({ userTier: tier, email: userData.email, fullName: userData.name });
});
it("should return 401 when no session exists", async () => {
(getServerSession as any).mockResolvedValue(null);
const params = Promise.resolve<Params>({});
expect((await POST({} as NextRequest, { params })).status).toBe(401);
});
});