import { NextResponse } from "next/server";
export async function GET(request: Request) { try { const url = new URL(request.url); const callerNumber = url.searchParams.get("caller") || "";
const ringbaAccountId = process.env.RINGBA_ACCOUNT_ID;
const ringbaPoolId = process.env.RINGBA_POOL_ID;
const ringbaApiToken = process.env.RINGBA_API_TOKEN;
const apiUrl = `https://api.ringba.com/v2/${ringbaAccountId}/numberpools/${ringbaPoolId}/Numbers`;
const ringbaResponse = await fetch(apiUrl, {
method: "GET",
headers: {
Authorization: `Token ${ringbaApiToken}`,
"Content-Type": "application/json",
},
});
if (!ringbaResponse.ok) {
const errorText = await ringbaResponse.text();
console.error("❌ Ringba API error:", errorText);
throw new Error("Ringba request failed");
}
const ringbaData = await ringbaResponse.json();
const numbers = ringbaData?.result?.numbers || [];
if (numbers.length === 0) {
throw new Error("No numbers available in the number pool");
}
// Randomly select a number
const selected = numbers[Math.floor(Math.random() * numbers.length)];
const phoneNumber = selected.phoneNumber;
return NextResponse.json({ phoneNumber });
} catch (error) { console.error("🔥 Error fetching Ringba number:", error); return NextResponse.json({ error: "Failed to fetch phone number" }, { status: 500 }); } } create this
Loading...
Loading...
i added the API end point in the Bland.ai to fetch the number and then transfer the call but its not happening what should we do now my current flow is caller dials a twilio number which then comes to the bland.ai and after Ai qualify the caller it should transfer to the ringba number using the Api that we have created