Skip to content

Post new sign up reasons to slack, not plain #1995

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apps/webapp/app/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
});
Expand Down
35 changes: 6 additions & 29 deletions apps/webapp/app/routes/_app.orgs.new/route.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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),
Expand Down Expand Up @@ -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));
Expand Down
43 changes: 43 additions & 0 deletions apps/webapp/app/services/slack.server.ts
Original file line number Diff line number Diff line change
@@ -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 });
}
}
Loading