Skip to content

Commit e40d759

Browse files
Sonra0claude
andcommitted
fix: hang up after emergency call instead of reviewing answers
When the elderly person requests an emergency call, reassure them, complete the session, and end the call immediately. Only go through the answer review when they don't need an emergency call. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ba4873d commit e40d759

1 file changed

Lines changed: 23 additions & 4 deletions

File tree

  • src/app/api/webhooks/assessment/next

src/app/api/webhooks/assessment/next/route.ts

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,10 @@ export async function POST(req: NextRequest) {
378378
console.error("Telegram emergency notification failed:", err);
379379
}
380380

381-
// Reassure the elder
381+
// Reassure the elder and end the call — don't go through answer review
382382
const reassureText = isArabic
383-
? "لا تقلق، سأتصل بهم الآن. سيتواصلون معك قريباً. الآن دعنا نراجع إجاباتك معاً."
384-
: "Don't worry, I'm calling them right now. They'll reach out to you soon. Now let's go over your answers together.";
383+
? "لا تقلق، سأتصل بهم الآن. سيتواصلون معك قريباً. ابقَ بأمان، مع السلامة!"
384+
: "Don't worry, I'm calling them right now. They'll reach out to you very soon. Stay safe, take care!";
385385

386386
let reassureTag: string;
387387
try {
@@ -393,9 +393,28 @@ export async function POST(req: NextRequest) {
393393
reassureTag = `<Say>${reassureText}</Say>`;
394394
}
395395

396+
// Complete session in background (skip review, just finalize)
397+
const answers = await prisma.assessmentAnswer.findMany({
398+
where: { sessionId },
399+
orderBy: { orderIndex: "asc" },
400+
});
401+
const totalCorrect = answers.filter((a: { result: string | null }) => a.result === "CORRECT").length;
402+
const score = answers.length > 0 ? totalCorrect / answers.length : 0;
403+
404+
prisma.assessmentSession.update({
405+
where: { id: sessionId },
406+
data: {
407+
status: "COMPLETED",
408+
overallScore: score,
409+
severity: score >= 0.75 ? "GREEN" : score >= 0.5 ? "YELLOW" : "RED",
410+
},
411+
}).catch((err: unknown) => console.error("Session completion failed:", err));
412+
413+
generateSummaryInBackground(sessionId, profile.name, profile.language, profile.id, score);
414+
415+
// Hang up after reassurance
396416
const twiml = `<Response>
397417
${reassureTag}
398-
<Redirect method="POST">${baseUrl}/api/webhooks/assessment/next?sessionId=${sessionId}&amp;answerIndex=${answerIndex}&amp;phase=review</Redirect>
399418
</Response>`;
400419

401420
return new NextResponse(twiml, {

0 commit comments

Comments
 (0)