feat: integrate Slack notifications for contact form submissions

- Added a new Slack notification feature to alert sales or support channels upon contact form submissions.
- Implemented a `notifySlack` function to format and send messages to Slack using a webhook.
- Enhanced error handling to ensure email notifications proceed even if Slack notifications fail.
This commit is contained in:
Mauricio Siu
2025-12-09 12:37:13 -06:00
parent 02f84c3788
commit 289a6732f3
2 changed files with 185 additions and 0 deletions

View File

@@ -1,4 +1,5 @@
import { getHubSpotUTK, submitToHubSpot } from "@/lib/hubspot";
import { notifySlack } from "@/lib/slack";
import type { NextRequest } from "next/server";
import { NextResponse } from "next/server";
import { Resend } from "resend";
@@ -70,6 +71,23 @@ export async function POST(request: NextRequest) {
}
}
// Send notification to Slack (sales or support channel)
try {
const slackSuccess = await notifySlack(body);
if (slackSuccess) {
console.log(
`Successfully sent ${body.inquiryType} inquiry notification to Slack`,
);
} else {
console.warn(
`Failed to send ${body.inquiryType} inquiry notification to Slack, but continuing with email`,
);
}
} catch (error) {
console.error("Error sending to Slack:", error);
// Continue with email even if Slack fails
}
// Format email content
const emailSubject = `[${body.inquiryType.toUpperCase()}] New contact form submission from ${body.firstName} ${body.lastName}`;
const emailBody = `