Skip to content

Commit

Permalink
Add sms pumping check
Browse files Browse the repository at this point in the history
  • Loading branch information
IObert committed Nov 13, 2024
1 parent 8c57167 commit db1fbf2
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/app/api/kioskOrder/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,32 @@ export async function POST(request: Request) {

// 1. Validate user input
const lookupService = await getLookupService();
const lookupResult = await lookupService.phoneNumbers(data.phone).fetch();
const lookupResult = await lookupService
.phoneNumbers(data.phone)
.fetch({ fields: "sms_pumping_risk" });
if (!data.phone || !data?.item?.title || !data.event) {
return new Response("Missing required fields", {
status: 400,
statusText: "Missing required fields",
});
}

// TODO potentially check sms_pumping_risk here
if (!lookupResult.valid) {
return new Response("Phone number is invalid", {
status: 400,
statusText: "Phone number is invalid",
});
}
if (lookupResult?.smsPumpingRisk?.sms_pumping_risk_score >= 60) {
return new Response(
"Phone number is at high risk of SMS pumping. Please try again later.",
{
status: 400,
statusText:
"Phone number is at high risk of SMS pumping. Please try again later.",
},
);
}

// 2. Fetch event data
const syncService = await getSyncService();
Expand All @@ -80,7 +91,9 @@ export async function POST(request: Request) {
}

// 3. Create new conversation
const sender = data.whatsapp ? `whatsapp:${lookupResult.phoneNumber}` : lookupResult.phoneNumber;
const sender = data.whatsapp
? `whatsapp:${lookupResult.phoneNumber}`
: lookupResult.phoneNumber;
const participantConversations = await getConversationsOfSender(sender);
const activeConversations = participantConversations.filter(
(conv) => conv.conversationState === "active",
Expand Down

0 comments on commit db1fbf2

Please sign in to comment.