Skip to content

Commit bdbf6fc

Browse files
committed
fix (onboarding): test whatsapp number issue
1 parent d864e9c commit bdbf6fc

File tree

5 files changed

+116
-19
lines changed

5 files changed

+116
-19
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import { NextResponse } from "next/server"
2+
import { withAuth } from "@lib/api-utils"
3+
4+
const appServerUrl =
5+
process.env.NEXT_PUBLIC_ENVIRONMENT === "selfhost"
6+
? process.env.INTERNAL_APP_SERVER_URL
7+
: process.env.NEXT_PUBLIC_APP_SERVER_URL
8+
9+
export const POST = withAuth(async function POST(request, { authHeader }) {
10+
try {
11+
const body = await request.json() // { phone_number: "..." }
12+
const response = await fetch(
13+
`${appServerUrl}/api/settings/whatsapp-notifications/verify`,
14+
{
15+
method: "POST",
16+
headers: {
17+
"Content-Type": "application/json",
18+
...authHeader
19+
},
20+
body: JSON.stringify(body)
21+
}
22+
)
23+
24+
const data = await response.json()
25+
if (!response.ok) {
26+
throw new Error(data.detail || "Failed to verify WhatsApp number")
27+
}
28+
return NextResponse.json(data)
29+
} catch (error) {
30+
console.error(
31+
"API Error in /settings/whatsapp-notifications/verify:",
32+
error
33+
)
34+
return NextResponse.json({ detail: error.message }, { status: 500 })
35+
}
36+
})

src/client/app/complete-profile/page.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const CompleteProfilePage = () => {
5353
setWhatsappStatus("checking")
5454
setWhatsappError("")
5555
try {
56-
const response = await fetch("/api/testing/whatsapp/verify", {
56+
const response = await fetch("/api/settings/whatsapp-notifications/verify", {
5757
method: "POST",
5858
headers: { "Content-Type": "application/json" },
5959
body: JSON.stringify({ phone_number: number })
@@ -67,9 +67,7 @@ const CompleteProfilePage = () => {
6767
setWhatsappError("")
6868
} else {
6969
setWhatsappStatus("invalid")
70-
setWhatsappError(
71-
"This number does not appear to be on WhatsApp."
72-
)
70+
setWhatsappError("This number does not appear to be on WhatsApp.")
7371
}
7472
} catch (error) {
7573
setWhatsappStatus("invalid")

src/client/app/onboarding/page.js

Lines changed: 53 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,25 @@ import { UseCaseCarousel } from "@components/onboarding/UseCaseCarousel"
2121

2222
// --- Helper Components ---
2323

24+
const FormattedPaQuestion = () => (
25+
<div className="text-neutral-200 space-y-4 mt-4 pl-4">
26+
<p>
27+
Are you someone who finds themselves spending too much time on
28+
administrative work? For example:
29+
</p>
30+
<ul className="list-disc list-inside pl-4 space-y-2 text-neutral-300">
31+
<li>Juggling multiple priorities</li>
32+
<li>Managing a small team or leading projects</li>
33+
<li>Scheduling meetings and organizing calendars</li>
34+
<li>Responding to routine emails</li>
35+
</ul>
36+
<p className="font-semibold pt-2">
37+
Do you ever feel the need for a personal assistant (human or AI) to
38+
handle these repetitive tasks?
39+
</p>
40+
</div>
41+
)
42+
2443
const TypingIndicator = () => (
2544
<motion.div
2645
initial={{ opacity: 0 }}
@@ -242,6 +261,17 @@ const OnboardingPage = () => {
242261
if (index < questions.length) {
243262
const question = questions[index]
244263
if (question) {
264+
if (question.id === "needs-pa") {
265+
setConversation((prev) => [
266+
...prev,
267+
{
268+
sender: "ai",
269+
text: message,
270+
type: "formatted-pa-question"
271+
}
272+
])
273+
return
274+
}
245275
message += `\n\n${question.question}`
246276
}
247277
}
@@ -265,11 +295,14 @@ const OnboardingPage = () => {
265295
setWhatsappStatus("checking")
266296
setWhatsappError("")
267297
try {
268-
const response = await fetch("/api/testing/whatsapp/verify", {
269-
method: "POST",
270-
headers: { "Content-Type": "application/json" },
271-
body: JSON.stringify({ phone_number: number })
272-
})
298+
const response = await fetch(
299+
"/api/settings/whatsapp-notifications/verify",
300+
{
301+
method: "POST",
302+
headers: { "Content-Type": "application/json" },
303+
body: JSON.stringify({ phone_number: number })
304+
}
305+
)
273306
const result = await response.json()
274307
if (!response.ok) {
275308
throw new Error(result.detail || "Verification request failed.")
@@ -714,15 +747,21 @@ const OnboardingPage = () => {
714747
{conversation.map((msg, index) => (
715748
<div key={index}>
716749
{msg.sender === "ai" ? (
717-
<p className="whitespace-pre-wrap">
718-
<span className="text-brand-orange">
719-
[SENTIENT]:
720-
</span>
721-
<span className="text-brand-white">
722-
{" "}
723-
{msg.text}
724-
</span>
725-
</p>
750+
<div>
751+
<p className="whitespace-pre-wrap">
752+
<span className="text-brand-orange">
753+
[SENTIENT]:
754+
</span>
755+
<span className="text-brand-white">
756+
{" "}
757+
{msg.text}
758+
</span>
759+
</p>
760+
{msg.type ===
761+
"formatted-pa-question" && (
762+
<FormattedPaQuestion />
763+
)}
764+
</div>
726765
) : (
727766
<p className="whitespace-pre-wrap">
728767
<span className="text-green-400">

src/server/main/settings/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,6 @@ class CompleteProfileRequest(BaseModel):
2424

2525
class Config:
2626
allow_population_by_field_name = True
27+
28+
class WhatsAppVerifyRequest(BaseModel):
29+
phone_number: str

src/server/main/settings/routes.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from main.dependencies import mongo_manager
77
from main.auth.utils import PermissionChecker, AuthHelper
88
from main.notifications.whatsapp_client import check_phone_number_exists, send_whatsapp_message
9-
from main.settings.models import WhatsAppMcpRequest, WhatsAppNotificationNumberRequest, ProfileUpdateRequest, WhatsAppNotificationRequest, CompleteProfileRequest
9+
from main.settings.models import WhatsAppMcpRequest, WhatsAppNotificationNumberRequest, ProfileUpdateRequest, WhatsAppNotificationRequest, CompleteProfileRequest, WhatsAppVerifyRequest
1010
from main.settings.google_sheets_utils import update_onboarding_data_in_sheet, update_plan_in_sheet, check_if_contact_is_missing
1111

1212
logger = logging.getLogger(__name__)
@@ -134,6 +134,27 @@ async def set_whatsapp_notification_number(
134134
raise e
135135
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail="An unexpected error occurred.")
136136

137+
@router.post("/whatsapp-notifications/verify", summary="Verify if a WhatsApp number exists")
138+
async def verify_whatsapp_notification_number(
139+
request: WhatsAppVerifyRequest,
140+
user_id: str = Depends(auth_helper.get_current_user_id)
141+
):
142+
phone_number = request.phone_number
143+
if not phone_number:
144+
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="phone_number is required.")
145+
146+
try:
147+
validation_result = await check_phone_number_exists(phone_number)
148+
if validation_result is None:
149+
raise HTTPException(status_code=status.HTTP_503_SERVICE_UNAVAILABLE, detail="Could not connect to WhatsApp service to verify number.")
150+
151+
return validation_result
152+
except Exception as e:
153+
logger.error(f"Error verifying WhatsApp number for user {user_id}: {e}", exc_info=True)
154+
if isinstance(e, HTTPException):
155+
raise e
156+
raise HTTPException(status_code=status.HTTP_500_INTERNAL_SERVER_ERROR, detail=str(e))
157+
137158

138159
@router.get("/whatsapp-notifications", summary="Get WhatsApp Notification settings")
139160
async def get_whatsapp_notification_settings(

0 commit comments

Comments
 (0)