Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

feat: API endpoint get call by phone number

Clémence Lesné7f94594d8aa6
diff --git a/main.py b/main.py
index ec1a675..86e6a72 100644
--- a/main.py
+++ b/main.py
@@ -1,4 +1,4 @@
-from typing import Optional
+from typing import List, Optional
from azure.communication.callautomation import (
CallAutomationClient,
CallConnectionClient,
@@ -177,6 +177,14 @@ async def health_liveness_get() -> None:
pass
+ "/call",
+ description="Get all calls by phone number.",
+)
+async def call_get(phone_number: str) -> List[CallModel]:
+ return await get_calls_by_phone_number(phone_number)
+
+
@api.get(
"/call/initiate",
status_code=status.HTTP_204_NO_CONTENT,
@@ -1022,3 +1030,13 @@ def get_last_call_by_phone_number(phone_number: str) -> Optional[CallModel]:
)
row = cursor.fetchone()
return CallModel.model_validate_json(row[0]) if row else None
+
+
+async def get_calls_by_phone_number(phone_number: str) -> List[CallModel]:
+ async with aiosqlite.connect(CONFIG.database.sqlite_path) as db:
+ cursor = await db.execute(
+ f"SELECT data FROM calls WHERE phone_number = ? ORDER BY DATETIME(created_at) DESC",
+ (phone_number,),
+ )
+ rows = await cursor.fetchall()
+ return [CallModel.model_validate_json(row[0]) for row in rows if row]