mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-16 08:25:18 +02:00
feat: add pre call fetch configuration (#222)
* feat: add pre call fetch configuration * docs: add NEW tags for pages about new features --------- Co-authored-by: Sabiha Khan <sabihak89@gmail.com>
This commit is contained in:
parent
c4c4b591db
commit
ec2f322486
27 changed files with 646 additions and 66 deletions
|
|
@ -59,6 +59,10 @@ class NodeDataDTO(BaseModel):
|
|||
detect_voicemail: bool = False
|
||||
delayed_start: bool = False
|
||||
delayed_start_duration: Optional[float] = None
|
||||
# Pre-call fetch (start node only)
|
||||
pre_call_fetch_enabled: bool = False
|
||||
pre_call_fetch_url: Optional[str] = None
|
||||
pre_call_fetch_credential_uuid: Optional[str] = None
|
||||
tool_uuids: Optional[List[str]] = None
|
||||
document_uuids: Optional[List[str]] = None
|
||||
trigger_path: Optional[str] = None
|
||||
|
|
|
|||
|
|
@ -162,8 +162,6 @@ class PipecatEngine:
|
|||
if self._context_compaction_enabled:
|
||||
self._context_summarization_manager = ContextSummarizationManager(self)
|
||||
|
||||
await self.set_node(self.workflow.start_node_id)
|
||||
|
||||
logger.debug(f"{self.__class__.__name__} initialized")
|
||||
except Exception as e:
|
||||
logger.error(f"Error initializing {self.__class__.__name__}: {e}")
|
||||
|
|
|
|||
|
|
@ -14,7 +14,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional
|
|||
|
||||
from loguru import logger
|
||||
|
||||
from api.constants import APP_ROOT_DIR
|
||||
from api.db import db_client
|
||||
from api.enums import ToolCategory, WorkflowRunMode
|
||||
from api.services.telephony.call_transfer_manager import get_call_transfer_manager
|
||||
|
|
@ -28,11 +27,10 @@ from api.services.workflow.tools.custom_tool import (
|
|||
execute_http_tool,
|
||||
tool_to_function_schema,
|
||||
)
|
||||
from api.utils.hold_audio import load_hold_audio
|
||||
from api.utils.hold_audio import play_hold_audio_loop
|
||||
from pipecat.adapters.schemas.function_schema import FunctionSchema
|
||||
from pipecat.frames.frames import (
|
||||
FunctionCallResultProperties,
|
||||
OutputAudioRawFrame,
|
||||
TTSSpeakFrame,
|
||||
)
|
||||
from pipecat.services.llm_service import FunctionCallParams
|
||||
|
|
@ -539,7 +537,11 @@ class CustomToolManager:
|
|||
|
||||
# Start hold music as background task
|
||||
hold_music_task = asyncio.create_task(
|
||||
self.play_hold_music_loop(hold_music_stop_event, sample_rate)
|
||||
play_hold_audio_loop(
|
||||
self._engine.task,
|
||||
hold_music_stop_event,
|
||||
sample_rate,
|
||||
)
|
||||
)
|
||||
|
||||
# Wait for transfer completion using Redis pub/sub
|
||||
|
|
@ -666,44 +668,3 @@ class CustomToolManager:
|
|||
# Unknown action, treat as generic success
|
||||
logger.warning(f"Unknown transfer action: {action}, treating as success")
|
||||
await function_call_params.result_callback(result)
|
||||
|
||||
async def play_hold_music_loop(
|
||||
self, stop_event: asyncio.Event, sample_rate: int = 8000
|
||||
):
|
||||
"""Play hold music in a loop until stop event is triggered.
|
||||
|
||||
Args:
|
||||
stop_event: Event to stop the hold music loop
|
||||
sample_rate: Sample rate for the hold music (default 8000Hz for Twilio)
|
||||
"""
|
||||
try:
|
||||
# Path to hold music file based on sample rate
|
||||
hold_music_file = (
|
||||
APP_ROOT_DIR / "assets" / f"transfer_hold_ring_{sample_rate}.wav"
|
||||
)
|
||||
hold_audio_data = load_hold_audio(hold_music_file, sample_rate)
|
||||
num_samples = len(hold_audio_data) // 2
|
||||
duration = int(num_samples / sample_rate)
|
||||
|
||||
logger.info(f"Starting hold music loop with file: {hold_music_file}")
|
||||
|
||||
while not stop_event.is_set():
|
||||
# Queue the hold audio frame
|
||||
frame = OutputAudioRawFrame(
|
||||
audio=hold_audio_data,
|
||||
sample_rate=sample_rate,
|
||||
num_channels=1,
|
||||
)
|
||||
await self._engine.task.queue_frame(frame)
|
||||
|
||||
# Wait for the audio to play or until stopped
|
||||
try:
|
||||
await asyncio.wait_for(stop_event.wait(), timeout=duration + 1.5)
|
||||
break # Stop event was set
|
||||
except asyncio.TimeoutError:
|
||||
pass # Continue looping
|
||||
|
||||
logger.info("Hold music loop stopped")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error in hold music loop: {e}")
|
||||
|
|
|
|||
|
|
@ -82,6 +82,9 @@ class Node:
|
|||
self.delayed_start_duration = data.delayed_start_duration
|
||||
self.tool_uuids = data.tool_uuids
|
||||
self.document_uuids = data.document_uuids
|
||||
self.pre_call_fetch_enabled = data.pre_call_fetch_enabled
|
||||
self.pre_call_fetch_url = data.pre_call_fetch_url
|
||||
self.pre_call_fetch_credential_uuid = data.pre_call_fetch_credential_uuid
|
||||
|
||||
self.data = data
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue