Skip to content

Open-source manufacturing ERP, MES and QMS. Quoting, MRP, inventory, shop floor, quality and lot/serial traceability on one Postgres schema, with a REST API and MCP server. Self-host or use Carbon Cloud.

build: move subscribe function to www app

Brad Barbindd6cd7f940b5
diff --git a/apps/www/app/lib/slack.server.ts b/apps/www/app/lib/slack.server.ts
new file mode 100644
index 0000000000..97953c94f3
--- /dev/null
+++ b/apps/www/app/lib/slack.server.ts
@@ -0,0 +1,32 @@
+import { SLACK_BOT_TOKEN } from "@carbon/auth";
+import { WebClient } from "@slack/web-api";
+
+interface SlackMessage {
+ channel: string;
+ text: string;
+ blocks?: any[];
+}
+
+class SlackClient {
+ private client: WebClient;
+
+ constructor(token: string) {
+ this.client = new WebClient(token);
+ }
+
+ async sendMessage({ channel, text, blocks }: SlackMessage): Promise<void> {
+ try {
+ await this.client.chat.postMessage({
+ channel,
+ text,
+ blocks,
+ });
+ } catch (error) {
+ console.error("Error sending Slack message:", error);
+ }
+ }
+}
+
+export function getSlackClient(): SlackClient {
+ return new SlackClient(SLACK_BOT_TOKEN);
+}
diff --git a/apps/www/app/routes/api+/subscribe.tsx b/apps/www/app/routes/api+/subscribe.tsx
new file mode 100644
index 0000000000..f767933c15
--- /dev/null
+++ b/apps/www/app/routes/api+/subscribe.tsx
@@ -0,0 +1,37 @@
+import { getSlackClient } from "~/lib/slack.server";
+
+import { validator } from "@carbon/form";
+import { json, type ActionFunctionArgs } from "@vercel/remix";
+import { z } from "zod";
+
+export const config = { runtime: "nodejs" };
+
+export const emailValidator = z.object({
+ email: z.string().email(),
+});
+
+export async function action({ request }: ActionFunctionArgs) {
+ const formData = await request.formData();
+ const validation = await validator(emailValidator).validate(formData);
+
+ if (validation.error) {
+ return json(
+ { success: false, message: "Email is required" },
+ { status: 400 }
+ );
+ }
+
+ const slackClient = getSlackClient();
+ await slackClient.sendMessage({
+ channel: "#leads",
+ text: "New lead from website",
+ blocks: [
+ {
+ type: "section",
+ text: { type: "mrkdwn", text: `New lead: ${validation.data.email}` },
+ },
+ ],
+ });
+
+ return json({ success: true, message: "Email submitted" });
+}