Skip to content

Commit 01d023b

Browse files
authored
chore: cleanup spam logic (#918)
1 parent 979a624 commit 01d023b

File tree

2 files changed

+3
-92
lines changed

2 files changed

+3
-92
lines changed

src/app/api/slack/route.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ const slackWebhookList = [process.env.SLACK_WEBHOOK_URL as string];
55
export async function POST(request: Request) {
66
try {
77
const body = await request.json();
8-
const { formId, firstname, lastname, email, company, message, isSpam } = body;
9-
10-
const spamPrefix = isSpam ? '🙄 ' : '';
8+
const { formId, firstname, lastname, email, company, message } = body;
119

1210
const responses = await Promise.all(
1311
slackWebhookList.map((webhookUrl) =>
@@ -17,7 +15,7 @@ export async function POST(request: Request) {
1715
'Content-Type': 'application/json',
1816
},
1917
body: JSON.stringify({
20-
text: `${spamPrefix}${formId} by ${firstname} ${lastname} (${email}) from ${company}\n\n${message}`,
18+
text: `${formId} by ${firstname} ${lastname} (${email}) from ${company}\n\n${message}`,
2119
}),
2220
}),
2321
),

src/components/shared/contact-form/contact-form.tsx

Lines changed: 1 addition & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -57,43 +57,6 @@ const getButtonTitle = (formId: string) => {
5757
}
5858
};
5959

60-
// Detects spam-like patterns in text (random mixed-case strings)
61-
const isLikelySpam = (text: string): boolean => {
62-
if (!text) return false;
63-
64-
const letters = text.replace(/[^a-zA-Z]/g, '');
65-
if (letters.length === 0) return false;
66-
67-
// Allow all uppercase (like "IBM", "NASA", "JOHN SMITH")
68-
if (letters === letters.toUpperCase()) return false;
69-
70-
// Allow all lowercase (like "john smith")
71-
if (letters === letters.toLowerCase()) return false;
72-
73-
// Count ANY case transitions (uppercase to lowercase OR lowercase to uppercase)
74-
const lowToHigh = (text.match(/[a-z][A-Z]/g) || []).length;
75-
const highToLow = (text.match(/[A-Z][a-z]/g) || []).length;
76-
const totalTransitions = lowToHigh + highToLow;
77-
78-
// Count uppercase letters
79-
const uppercaseCount = (letters.match(/[A-Z]/g) || []).length;
80-
const uppercaseRatio = uppercaseCount / letters.length;
81-
82-
// Spam pattern 1: 4+ total case transitions
83-
// Examples: CuxFbsjOMshzd (6), lxBMWgpkbCX (4), wUwqIVjOmhQbJi (10)
84-
// Legitimate: Christopher (2), McDonald (2), iPhone (2), MacBook (2)
85-
if (totalTransitions >= 4) return true;
86-
87-
// Spam pattern 2: Uppercase ratio in suspicious range (30-95%)
88-
// Too random to be legitimate mixed case (which is typically <30%)
89-
// Not all caps (which would be 100%)
90-
// Examples: lxBMWgpkbCX (42%), cVBaaQcPphWeXH (64%), CuxFbsjOMshzd (38%)
91-
// Legitimate: McDonald (25%), iPhone (33% but only 2 transitions), John (25%)
92-
if (uppercaseRatio > 0.3 && uppercaseRatio < 0.95) return true;
93-
94-
return false;
95-
};
96-
9760
// Retry a fetch request up to 3 times with exponential backoff
9861
const fetchWithRetry = async (url: string, options: RequestInit): Promise<Response> => {
9962
const maxRetries = 3;
@@ -121,52 +84,6 @@ const fetchWithRetry = async (url: string, options: RequestInit): Promise<Respon
12184
throw lastError || new Error('Request failed');
12285
};
12386

124-
const detectSpamSubmission = (values: ValueType): boolean => {
125-
const { firstname, lastname, company, email, message } = values;
126-
127-
let spamScore = 0;
128-
129-
// High confidence spam indicators (3 points each)
130-
if (isLikelySpam(firstname)) spamScore += 3;
131-
if (isLikelySpam(lastname)) spamScore += 3;
132-
if (isLikelySpam(company)) spamScore += 3;
133-
if (company.trim().length <= 2) spamScore += 3;
134-
135-
// Medium confidence indicators (2 points each)
136-
const freeEmailDomains = [
137-
'gmail.com',
138-
'yahoo.com',
139-
'hotmail.com',
140-
'outlook.com',
141-
'aol.com',
142-
'icloud.com',
143-
't-online.de',
144-
];
145-
const emailDomain = email.toLowerCase().split('@')[1] || '';
146-
if (!emailDomain) {
147-
// Invalid email format (missing domain) - likely spam
148-
spamScore += 2;
149-
} else if (freeEmailDomains.includes(emailDomain)) {
150-
spamScore += 2;
151-
}
152-
153-
// Low confidence indicators (1 point each)
154-
const messageWords = (message || '')
155-
.trim()
156-
.split(/\s+/)
157-
.filter((word) => word.length > 0);
158-
if (messageWords.length < 5) spamScore += 1;
159-
160-
// Flag as spam if score >= 5
161-
// Examples:
162-
// - Random case name (3) + free email (2) = spam
163-
// - Random case name (3) + short company (3) = spam
164-
// - Free email (2) + short message (1) + short company (3) = spam
165-
// - Free email (2) + short company (3) = not spam (legitimate small companies)
166-
// - Free email (2) + short message (1) = not spam
167-
return spamScore >= 5;
168-
};
169-
17087
const ContactForm = ({
17188
className,
17289
formId,
@@ -205,9 +122,6 @@ const ContactForm = ({
205122
setButtonState(STATES.LOADING);
206123
setFormError('');
207124

208-
const isSpam = detectSpamSubmission(values);
209-
const spamPrefix = isSpam ? '🙄 ' : '';
210-
211125
try {
212126
if (
213127
formId == VIEW_LIVE_DEMO ||
@@ -241,7 +155,6 @@ const ContactForm = ({
241155
email,
242156
company,
243157
message,
244-
isSpam,
245158
}),
246159
});
247160

@@ -256,7 +169,7 @@ const ContactForm = ({
256169
body: JSON.stringify({
257170
msg_type: 'text',
258171
content: {
259-
text: `${spamPrefix}${formId} by ${firstname} ${lastname} (${email}) from ${company}\n\n${message}`,
172+
text: `${formId} by ${firstname} ${lastname} (${email}) from ${company}\n\n${message}`,
260173
},
261174
}),
262175
}).catch(() => {

0 commit comments

Comments
 (0)