mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-07 07:55:16 +02:00
fix: add cloudonix call hangup strategy (#181)
* fix: add cloudonix call hangup strategy * chore: upgrade pipecat
This commit is contained in:
parent
77a55fcfe3
commit
7b77721964
3 changed files with 80 additions and 1 deletions
|
|
@ -10,6 +10,7 @@ from api.services.telephony.providers.ari_call_strategies import (
|
|||
ARIBridgeSwapStrategy,
|
||||
ARIHangupStrategy,
|
||||
)
|
||||
from api.services.telephony.providers.cloudonix_call_strategies import CloudonixHangupStrategy
|
||||
from api.services.telephony.providers.twilio_call_strategies import (
|
||||
TwilioConferenceStrategy,
|
||||
TwilioHangupStrategy,
|
||||
|
|
@ -131,11 +132,13 @@ async def create_cloudonix_transport(
|
|||
|
||||
from pipecat.serializers.cloudonix import CloudonixFrameSerializer
|
||||
|
||||
hangup_strategy = CloudonixHangupStrategy()
|
||||
serializer = CloudonixFrameSerializer(
|
||||
call_id=call_id,
|
||||
stream_sid=stream_sid,
|
||||
domain_id=domain_id,
|
||||
bearer_token=bearer_token,
|
||||
hangup_strategy=hangup_strategy,
|
||||
)
|
||||
|
||||
return FastAPIWebsocketTransport(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,76 @@
|
|||
"""Cloudonix-specific call operation strategies."""
|
||||
|
||||
from typing import Any, Dict
|
||||
|
||||
from loguru import logger
|
||||
|
||||
from pipecat.serializers.call_strategies import HangupStrategy
|
||||
|
||||
|
||||
class CloudonixHangupStrategy(HangupStrategy):
|
||||
"""Implements hangup for Cloudonix calls."""
|
||||
|
||||
async def execute_hangup(self, context: Dict[str, Any]) -> bool:
|
||||
"""Terminate a Cloudonix session via REST API.
|
||||
|
||||
Note: CloudonixFrameSerializer inherits TwilioFrameSerializer and maps
|
||||
Cloudonix params to Twilio-compatible keys when building the context:
|
||||
call_id -> call_sid
|
||||
domain_id -> account_sid
|
||||
bearer_token -> auth_token
|
||||
"""
|
||||
try:
|
||||
import aiohttp
|
||||
|
||||
call_id = context.get("call_sid") or context.get("call_id")
|
||||
domain_id = context.get("account_sid") or context.get("domain_id")
|
||||
bearer_token = context.get("auth_token") or context.get("bearer_token")
|
||||
|
||||
if not call_id or not domain_id or not bearer_token:
|
||||
missing = [
|
||||
k
|
||||
for k, v in {
|
||||
"call_id": call_id,
|
||||
"domain_id": domain_id,
|
||||
"bearer_token": bearer_token,
|
||||
}.items()
|
||||
if not v
|
||||
]
|
||||
logger.warning(
|
||||
f"Cannot hang up Cloudonix call: missing required parameters: {', '.join(missing)}"
|
||||
)
|
||||
return False
|
||||
|
||||
endpoint = f"https://api.cloudonix.io/customers/self/domains/{domain_id}/sessions/{call_id}"
|
||||
headers = {
|
||||
"Authorization": f"Bearer {bearer_token}",
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
logger.info(f"Terminating Cloudonix call {call_id} via DELETE {endpoint}")
|
||||
|
||||
async with aiohttp.ClientSession() as session:
|
||||
async with session.delete(endpoint, headers=headers) as response:
|
||||
status = response.status
|
||||
response_text = await response.text()
|
||||
|
||||
if status in (200, 204, 404):
|
||||
logger.info(
|
||||
f"Successfully terminated Cloudonix session {call_id} "
|
||||
f"(HTTP {status})"
|
||||
)
|
||||
return True
|
||||
else:
|
||||
logger.warning(
|
||||
f"Unexpected response terminating Cloudonix session {call_id}: "
|
||||
f"HTTP {status}, Response: {response_text}"
|
||||
)
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
logger.error(
|
||||
f"Error terminating Cloudonix call "
|
||||
f"{context.get('call_sid') or context.get('call_id')}: {e}",
|
||||
exc_info=True,
|
||||
)
|
||||
return False
|
||||
2
pipecat
2
pipecat
|
|
@ -1 +1 @@
|
|||
Subproject commit 26e335fbfdf792d54ad37da414998762f111e231
|
||||
Subproject commit a1d39061b2829a66d1bdd03b6e0525746d382057
|
||||
Loading…
Add table
Add a link
Reference in a new issue