diff --git a/apps/webapp/app/env.server.ts b/apps/webapp/app/env.server.ts index 9d49dcd03c..f0931683b4 100644 --- a/apps/webapp/app/env.server.ts +++ b/apps/webapp/app/env.server.ts @@ -715,6 +715,9 @@ const EnvironmentSchema = z.object({ QUEUE_SSE_AUTORELOAD_INTERVAL_MS: z.coerce.number().int().default(5_000), QUEUE_SSE_AUTORELOAD_TIMEOUT_MS: z.coerce.number().int().default(60_000), + SLACK_BOT_TOKEN: z.string().optional(), + SLACK_SIGNUP_REASON_CHANNEL_ID: z.string().optional(), + // kapa.ai KAPA_AI_WEBSITE_ID: z.string().optional(), }); diff --git a/apps/webapp/app/routes/_app.orgs.new/route.tsx b/apps/webapp/app/routes/_app.orgs.new/route.tsx index 29f8963f7d..a171153510 100644 --- a/apps/webapp/app/routes/_app.orgs.new/route.tsx +++ b/apps/webapp/app/routes/_app.orgs.new/route.tsx @@ -5,7 +5,6 @@ import { RadioGroup } from "@radix-ui/react-radio-group"; import type { ActionFunction, LoaderFunctionArgs } from "@remix-run/node"; import { json, redirect } from "@remix-run/node"; import { Form, useActionData, useNavigation } from "@remix-run/react"; -import { uiComponent } from "@team-plain/typescript-sdk"; import { typedjson, useTypedLoaderData } from "remix-typedjson"; import { z } from "zod"; import { MainCenteredContainer } from "~/components/layout/AppLayout"; @@ -23,10 +22,9 @@ import { TextArea } from "~/components/primitives/TextArea"; import { useFeatures } from "~/hooks/useFeatures"; import { createOrganization } from "~/models/organization.server"; import { NewOrganizationPresenter } from "~/presenters/NewOrganizationPresenter.server"; -import { logger } from "~/services/logger.server"; import { requireUser, requireUserId } from "~/services/session.server"; +import { sendNewOrgMessage } from "~/services/slack.server"; import { organizationPath, rootPath } from "~/utils/pathBuilder"; -import { sendToPlain } from "~/utils/plain.server"; const schema = z.object({ orgName: z.string().min(3).max(50), @@ -63,32 +61,11 @@ export const action: ActionFunction = async ({ request }) => { const whyUseUs = formData.get("whyUseUs"); if (whyUseUs) { - try { - await sendToPlain({ - userId: user.id, - email: user.email, - name: user.name ?? user.displayName ?? user.email, - title: "New org feedback", - components: [ - uiComponent.text({ - text: `${submission.value.orgName} just created a new organization.`, - }), - uiComponent.divider({ spacingSize: "M" }), - uiComponent.text({ - size: "L", - color: "NORMAL", - text: "What problem are you trying to solve?", - }), - uiComponent.text({ - size: "L", - color: "NORMAL", - text: whyUseUs.toString(), - }), - ], - }); - } catch (error) { - logger.error("Error sending data to Plain when creating an org:", { error }); - } + await sendNewOrgMessage({ + orgName: submission.value.orgName, + whyUseUs: whyUseUs.toString(), + userEmail: user.email, + }); } return redirect(organizationPath(organization)); diff --git a/apps/webapp/app/services/slack.server.ts b/apps/webapp/app/services/slack.server.ts new file mode 100644 index 0000000000..68010d6842 --- /dev/null +++ b/apps/webapp/app/services/slack.server.ts @@ -0,0 +1,43 @@ +import { WebClient } from "@slack/web-api"; +import { env } from "~/env.server"; +import { logger } from "./logger.server"; + +const slack = new WebClient(env.SLACK_BOT_TOKEN); + +type SendNewOrgMessageParams = { + orgName: string; + whyUseUs: string; + userEmail: string; +}; + +export async function sendNewOrgMessage({ orgName, whyUseUs, userEmail }: SendNewOrgMessageParams) { + if (!env.SLACK_BOT_TOKEN || !env.SLACK_SIGNUP_REASON_CHANNEL_ID) { + return; + } + try { + await slack.chat.postMessage({ + channel: env.SLACK_SIGNUP_REASON_CHANNEL_ID, + text: `New org created: ${orgName}`, + blocks: [ + { + type: "header", + text: { type: "plain_text", text: "New org created" }, + }, + { + type: "section", + text: { type: "mrkdwn", text: `*Org name:* ${orgName}` }, + }, + { + type: "section", + text: { type: "mrkdwn", text: `*What problem are you trying to solve?*\n${whyUseUs}` }, + }, + { + type: "context", + elements: [{ type: "mrkdwn", text: `Created by: ${userEmail}` }], + }, + ], + }); + } catch (error) { + logger.error("Error sending data to Slack when creating an org:", { error }); + } +}