Skip to content

Commit cf9460a

Browse files
samejrmatt-aitken
andauthored
Post new sign up reasons to slack, not plain (#1995)
* Post new sign up reasons to slack, not plain * Makes the Slack env vars optional --------- Co-authored-by: Matt Aitken <matt@mattaitken.com>
1 parent 7fe111a commit cf9460a

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

apps/webapp/app/env.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -715,6 +715,9 @@ const EnvironmentSchema = z.object({
715715
QUEUE_SSE_AUTORELOAD_INTERVAL_MS: z.coerce.number().int().default(5_000),
716716
QUEUE_SSE_AUTORELOAD_TIMEOUT_MS: z.coerce.number().int().default(60_000),
717717

718+
SLACK_BOT_TOKEN: z.string().optional(),
719+
SLACK_SIGNUP_REASON_CHANNEL_ID: z.string().optional(),
720+
718721
// kapa.ai
719722
KAPA_AI_WEBSITE_ID: z.string().optional(),
720723
});

apps/webapp/app/routes/_app.orgs.new/route.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { RadioGroup } from "@radix-ui/react-radio-group";
55
import type { ActionFunction, LoaderFunctionArgs } from "@remix-run/node";
66
import { json, redirect } from "@remix-run/node";
77
import { Form, useActionData, useNavigation } from "@remix-run/react";
8-
import { uiComponent } from "@team-plain/typescript-sdk";
98
import { typedjson, useTypedLoaderData } from "remix-typedjson";
109
import { z } from "zod";
1110
import { MainCenteredContainer } from "~/components/layout/AppLayout";
@@ -23,10 +22,9 @@ import { TextArea } from "~/components/primitives/TextArea";
2322
import { useFeatures } from "~/hooks/useFeatures";
2423
import { createOrganization } from "~/models/organization.server";
2524
import { NewOrganizationPresenter } from "~/presenters/NewOrganizationPresenter.server";
26-
import { logger } from "~/services/logger.server";
2725
import { requireUser, requireUserId } from "~/services/session.server";
26+
import { sendNewOrgMessage } from "~/services/slack.server";
2827
import { organizationPath, rootPath } from "~/utils/pathBuilder";
29-
import { sendToPlain } from "~/utils/plain.server";
3028

3129
const schema = z.object({
3230
orgName: z.string().min(3).max(50),
@@ -63,32 +61,11 @@ export const action: ActionFunction = async ({ request }) => {
6361
const whyUseUs = formData.get("whyUseUs");
6462

6563
if (whyUseUs) {
66-
try {
67-
await sendToPlain({
68-
userId: user.id,
69-
email: user.email,
70-
name: user.name ?? user.displayName ?? user.email,
71-
title: "New org feedback",
72-
components: [
73-
uiComponent.text({
74-
text: `${submission.value.orgName} just created a new organization.`,
75-
}),
76-
uiComponent.divider({ spacingSize: "M" }),
77-
uiComponent.text({
78-
size: "L",
79-
color: "NORMAL",
80-
text: "What problem are you trying to solve?",
81-
}),
82-
uiComponent.text({
83-
size: "L",
84-
color: "NORMAL",
85-
text: whyUseUs.toString(),
86-
}),
87-
],
88-
});
89-
} catch (error) {
90-
logger.error("Error sending data to Plain when creating an org:", { error });
91-
}
64+
await sendNewOrgMessage({
65+
orgName: submission.value.orgName,
66+
whyUseUs: whyUseUs.toString(),
67+
userEmail: user.email,
68+
});
9269
}
9370

9471
return redirect(organizationPath(organization));
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { WebClient } from "@slack/web-api";
2+
import { env } from "~/env.server";
3+
import { logger } from "./logger.server";
4+
5+
const slack = new WebClient(env.SLACK_BOT_TOKEN);
6+
7+
type SendNewOrgMessageParams = {
8+
orgName: string;
9+
whyUseUs: string;
10+
userEmail: string;
11+
};
12+
13+
export async function sendNewOrgMessage({ orgName, whyUseUs, userEmail }: SendNewOrgMessageParams) {
14+
if (!env.SLACK_BOT_TOKEN || !env.SLACK_SIGNUP_REASON_CHANNEL_ID) {
15+
return;
16+
}
17+
try {
18+
await slack.chat.postMessage({
19+
channel: env.SLACK_SIGNUP_REASON_CHANNEL_ID,
20+
text: `New org created: ${orgName}`,
21+
blocks: [
22+
{
23+
type: "header",
24+
text: { type: "plain_text", text: "New org created" },
25+
},
26+
{
27+
type: "section",
28+
text: { type: "mrkdwn", text: `*Org name:* ${orgName}` },
29+
},
30+
{
31+
type: "section",
32+
text: { type: "mrkdwn", text: `*What problem are you trying to solve?*\n${whyUseUs}` },
33+
},
34+
{
35+
type: "context",
36+
elements: [{ type: "mrkdwn", text: `Created by: ${userEmail}` }],
37+
},
38+
],
39+
});
40+
} catch (error) {
41+
logger.error("Error sending data to Slack when creating an org:", { error });
42+
}
43+
}

0 commit comments

Comments
 (0)