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

fix: Callback secret validation and storage

Clémence Lesné17091674bee3
diff --git a/main.py b/main.py
index fc4ed5f..0854ed1 100644
--- a/main.py
+++ b/main.py
@@ -316,8 +316,11 @@ async def communication_event_worker(
secret: str,
) -> None:
call = await db.call_asearch_one(phone_number)
- if not call or call.callback_secret.get_secret_value() != secret:
- _logger.warn(f"Call with {phone_number} not found")
+ if not call:
+ _logger.warn(f"Call {phone_number} not found")
+ return
+ if call.callback_secret != secret:
+ _logger.warn(f"Secret for call {phone_number} does not match")
return
event = CloudEvent.from_dict(event_dict)
@@ -1444,7 +1447,7 @@ async def callback_url(caller_id: str) -> str:
call = CallModel(phone_number=caller_id)
await db.call_aset(call)
return CALL_EVENT_URL.format(
- callback_secret=html.escape(call.callback_secret.get_secret_value()),
+ callback_secret=html.escape(call.callback_secret),
phone_number=html.escape(call.phone_number),
)
diff --git a/models/call.py b/models/call.py
index 6ea0022..d69f5b7 100644
--- a/models/call.py
+++ b/models/call.py
@@ -16,11 +16,9 @@ class CallModel(BaseModel):
# Immutable fields
call_id: UUID = Field(default_factory=uuid4, frozen=True)
created_at: datetime = Field(default_factory=datetime.utcnow, frozen=True)
- callback_secret: SecretStr = Field(
- default=SecretStr(
- "".join(
- random.choice(string.ascii_letters + string.digits) for _ in range(16)
- )
+ callback_secret: str = Field(
+ default="".join(
+ random.choice(string.ascii_letters + string.digits) for _ in range(16)
),
frozen=True,
)