Initial commit

This commit is contained in:
Haitham Khalifa
2026-02-16 12:18:06 +01:00
commit b538d84e17
63 changed files with 15059 additions and 0 deletions
+36
View File
@@ -0,0 +1,36 @@
import { NextResponse } from 'next/server';
import { collection, getDocs, getFirestore, query, where, Timestamp } from 'firebase/firestore';
import { app } from '@/lib/firebase';
export async function GET(request: Request) {
// TODO: Secure this route using a secret header for Vercel Cron.
const db = getFirestore(app);
const now = Timestamp.now();
// TODO: Add index for scheduledAt + status.
const tasksQuery = query(
collection(db, 'callTasks'),
where('status', '==', 'pending'),
where('scheduledAt', '<=', now)
);
const snapshot = await getDocs(tasksQuery);
const origin = request.headers.get('origin') ?? 'http://localhost:3000';
for (const docSnap of snapshot.docs) {
const task = docSnap.data() as any;
// Trigger the call (TODO: include auth)
await fetch(`${origin}/api/vapi/create-call`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
phoneNumber: task.phoneNumber,
userId: task.userId,
scheduledTaskId: docSnap.id,
}),
});
}
return NextResponse.json({ processed: snapshot.size });
}