From 13b41437e8753d30f430d2e2a6ebfaffb47c8186 Mon Sep 17 00:00:00 2001 From: Sabiha Khan <87858386+chewwbaka@users.noreply.github.com> Date: Wed, 18 Feb 2026 21:13:28 +0530 Subject: [PATCH] fix: missing call_id in gathered_context (#165) --- api/db/workflow_run_client.py | 2 ++ api/routes/telephony.py | 8 +++++--- api/services/telephony/ari_manager.py | 4 +++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/api/db/workflow_run_client.py b/api/db/workflow_run_client.py index 3cbf1bc..fc51e47 100644 --- a/api/db/workflow_run_client.py +++ b/api/db/workflow_run_client.py @@ -28,6 +28,7 @@ class WorkflowRunClient(BaseDBClient): user_id: int, call_type: CallType = CallType.OUTBOUND, initial_context: dict = None, + gathered_context: dict = None, campaign_id: int = None, queued_run_id: int = None, ) -> WorkflowRunModel: @@ -79,6 +80,7 @@ class WorkflowRunClient(BaseDBClient): mode=mode, definition_id=current_def.id if current_def else None, initial_context=initial_context or workflow.template_context_variables, + gathered_context=gathered_context or {}, campaign_id=campaign_id, queued_run_id=queued_run_id, storage_backend=current_backend.value, diff --git a/api/routes/telephony.py b/api/routes/telephony.py index 4020839..cc7ce55 100644 --- a/api/routes/telephony.py +++ b/api/routes/telephony.py @@ -425,7 +425,6 @@ async def _create_inbound_workflow_run( "caller_number": normalized_data.from_number, "called_number": normalized_data.to_number, "direction": "inbound", - "call_id": call_id, "account_id": normalized_data.account_id, "provider": provider, "data_source": data_source, @@ -433,6 +432,9 @@ async def _create_inbound_workflow_run( "to_country": normalized_data.to_country, "raw_webhook_data": normalized_data.raw_data, }, + gathered_context={ + "call_id": call_id, + }, ) logger.info( @@ -1273,11 +1275,11 @@ async def handle_vobiz_hangup_callback_by_workflow( try: db_client = WorkflowRunClient() async with db_client.async_session() as session: - # Fetch workflow run with matching call_id in initial_context + # Fetch workflow run with matching call_id in gathered_context query = text(""" SELECT id FROM workflow_runs WHERE workflow_id = :workflow_id - AND CAST(initial_context AS jsonb) @> CAST(:call_id_json AS jsonb) + AND CAST(gathered_context AS jsonb) @> CAST(:call_id_json AS jsonb) ORDER BY created_at DESC LIMIT 1 """) diff --git a/api/services/telephony/ari_manager.py b/api/services/telephony/ari_manager.py index a033c5a..ea8e414 100644 --- a/api/services/telephony/ari_manager.py +++ b/api/services/telephony/ari_manager.py @@ -468,9 +468,11 @@ class ARIConnection: "caller_number": caller_number, "called_number": called_number, "direction": "inbound", - "call_id": call_id, "provider": "ari", }, + gathered_context={ + "call_id": call_id, + }, ) logger.info(