mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-28 08:49:42 +02:00
Resolve an issue with direct socket connections using the wrong event… (#289)
* Resolve an issue with direct socket connections using the wrong event data. * Resolve the formatting issus in the provider file * chore: fix import ordering with ruff Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Nir Simionovich <nirs@cloudonix.io> Co-authored-by: Abhishek Kumar <abhishek@a6k.me> Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
5a59936b16
commit
7df73beea3
1 changed files with 27 additions and 14 deletions
|
|
@ -544,12 +544,13 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
try:
|
try:
|
||||||
stream_sid = start_msg["start"]["streamSid"]
|
stream_sid = start_msg["start"]["streamSid"]
|
||||||
call_sid = start_msg["start"]["callSid"]
|
call_sid = start_msg["start"]["callSid"]
|
||||||
|
call_session = start_msg["start"]["session"]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.error("Missing streamSid or callSid in start message")
|
logger.error("Missing streamSid or callSid or session in start message")
|
||||||
await websocket.close(code=4400, reason="Missing stream identifiers")
|
await websocket.close(code=4400, reason="Missing stream identifiers")
|
||||||
return
|
return
|
||||||
|
|
||||||
if not await self._validate_session(domain_id, call_sid, bearer_token):
|
if not await self._validate_session(domain_id, call_session, bearer_token):
|
||||||
await websocket.close(
|
await websocket.close(
|
||||||
code=4400, reason="Cloudonix session validation failed"
|
code=4400, reason="Cloudonix session validation failed"
|
||||||
)
|
)
|
||||||
|
|
@ -557,7 +558,7 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
|
|
||||||
logger.info(
|
logger.info(
|
||||||
f"Cloudonix agent-stream connected for workflow_run "
|
f"Cloudonix agent-stream connected for workflow_run "
|
||||||
f"{workflow_run_id} stream_sid={stream_sid} call_sid={call_sid} "
|
f"{workflow_run_id} stream_sid={stream_sid} call_sid={call_sid} session={call_session}"
|
||||||
f"telephony_configuration_id={config.id}"
|
f"telephony_configuration_id={config.id}"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -567,9 +568,9 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
workflow_id=workflow_id,
|
workflow_id=workflow_id,
|
||||||
workflow_run_id=workflow_run_id,
|
workflow_run_id=workflow_run_id,
|
||||||
user_id=user_id,
|
user_id=user_id,
|
||||||
call_id=call_sid,
|
call_id=call_session,
|
||||||
transport_kwargs={
|
transport_kwargs={
|
||||||
"call_id": call_sid,
|
"call_id": call_session,
|
||||||
"stream_sid": stream_sid,
|
"stream_sid": stream_sid,
|
||||||
"bearer_token": bearer_token,
|
"bearer_token": bearer_token,
|
||||||
"domain_id": domain_id,
|
"domain_id": domain_id,
|
||||||
|
|
@ -581,17 +582,15 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def _validate_session(
|
async def _validate_session(
|
||||||
self, domain_id: str, call_id: str, bearer_token: str
|
self, domain_id: str, call_session: str, bearer_token: str
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Confirm the session is live with Cloudonix.
|
"""Confirm the session is live with Cloudonix.
|
||||||
|
|
||||||
Hits ``GET /customers/self/domains/{domain_id}/sessions/{call_id}``
|
Hits ``GET /customers/self/domains/{domain_id}/sessions/{call_session}``
|
||||||
with the supplied bearer token. A 200 response means both the
|
with the supplied bearer token. A 200 response means both the
|
||||||
token is valid and the session exists.
|
token is valid and the session exists.
|
||||||
"""
|
"""
|
||||||
endpoint = (
|
endpoint = f"{self.base_url}/customers/self/domains/{domain_id}/sessions/{call_session}"
|
||||||
f"{self.base_url}/customers/self/domains/{domain_id}/sessions/{call_id}"
|
|
||||||
)
|
|
||||||
headers = {
|
headers = {
|
||||||
"Authorization": f"Bearer {bearer_token}",
|
"Authorization": f"Bearer {bearer_token}",
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
|
|
@ -605,13 +604,13 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Cloudonix session validation failed: "
|
f"Cloudonix session validation failed: "
|
||||||
f"HTTP {response.status} domain_id={domain_id} "
|
f"HTTP {response.status} domain_id={domain_id} "
|
||||||
f"call_id={call_id} body={body}"
|
f"call_id={call_session} body={body}"
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(
|
logger.error(
|
||||||
f"Cloudonix session validation error for domain_id={domain_id} "
|
f"Cloudonix session validation error for domain_id={domain_id} "
|
||||||
f"call_id={call_id}: {e}"
|
f"call_id={call_session}: {e}"
|
||||||
)
|
)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
@ -952,10 +951,24 @@ class CloudonixProvider(TelephonyProvider):
|
||||||
**kwargs: Any,
|
**kwargs: Any,
|
||||||
) -> Dict[str, Any]:
|
) -> Dict[str, Any]:
|
||||||
"""
|
"""
|
||||||
Cloudonix provider does not support call transfers.
|
Initiate a call transfer via Cloudonix.
|
||||||
|
|
||||||
|
Uses inline CXML to put the destination into a conference when they answer,
|
||||||
|
and a status callback to track the transfer outcome.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
destination: The destination phone number (E.164 format)
|
||||||
|
transfer_id: Unique identifier for tracking this transfer
|
||||||
|
conference_name: Name of the conference to join the destination into
|
||||||
|
timeout: Transfer timeout in seconds
|
||||||
|
**kwargs: Additional Twilio-specific parameters
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
Dict containing transfer result information
|
||||||
|
|
||||||
Raises:
|
Raises:
|
||||||
NotImplementedError: Cloudonix call transfers are yet to be implemented
|
ValueError: If provider configuration is invalid
|
||||||
|
Exception: If Twilio API call fails
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError("Cloudonix provider does not support call transfers")
|
raise NotImplementedError("Cloudonix provider does not support call transfers")
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue