UnleashX commited on
Commit
66662fd
·
verified ·
1 Parent(s): bb73224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -6
app.py CHANGED
@@ -1,18 +1,20 @@
1
  #!/usr/bin/env python3
2
  #
3
- # san_integration_script.py (v6 - Simplified Audio Processing)
4
  # ============================================================
5
  # Description:
6
  # - Establishes a real-time, two-way audio bridge between a SAN system
7
  # and the Millis AI platform.
8
  # - Direct audio forwarding at 16kHz PCM format (no conversion needed).
9
  # - Removed buffer logic for direct streaming.
 
10
  #
11
  # Changes in this version:
12
  # - Removed audio format conversion logic (resampling)
13
  # - Removed buffer management and chunking
14
  # - Simplified audio flow for direct 16kHz PCM streaming
15
  # - Removed scipy dependency
 
16
  # -------------------------------------------------------------------
17
 
18
  import os
@@ -185,10 +187,13 @@ async def fetch_call_credentials_with_fallback(call_id: str, fallback_msg: dict)
185
  extra_params = fallback_msg.get("extraParams", {})
186
  custom_field = fallback_msg.get("custom_field", {})
187
 
 
188
  agent_id = (extra_params.get("platform_agent_id") or
189
  custom_field.get("agentId") or
190
- fallback_msg.get("agentId"))
 
191
 
 
192
  public_key = (extra_params.get("publicKey") or extra_params.get("public_key") or
193
  custom_field.get("publicKey") or custom_field.get("public_key") or
194
  fallback_msg.get("publicKey") or fallback_msg.get("public_key"))
@@ -407,10 +412,24 @@ async def media_socket(ws: WebSocket):
407
  if processor is None:
408
  logger.info(f"Starting processor for call: {new_call_id}")
409
 
410
- # Extract credentials
411
  extra_params = msg.get("extraParams", {})
412
- agent_id = extra_params.get("platform_agent_id")
413
- public_key = PUBLIC_KEY
 
 
 
 
 
 
 
 
 
 
 
 
 
 
414
 
415
  if not agent_id or not public_key:
416
  credentials = await fetch_call_credentials_with_fallback(new_call_id, msg)
@@ -419,6 +438,7 @@ async def media_socket(ws: WebSocket):
419
 
420
  if not agent_id:
421
  logger.error(f"No agent_id found for call_id: {new_call_id}")
 
422
  await ws.close(code=1008, reason="Missing agent_id")
423
  return
424
 
@@ -548,7 +568,7 @@ async def test_mongodb():
548
  }
549
 
550
  if __name__ == "__main__":
551
- print("Starting SAN to Millis AI Integration Server (v6 - Simplified)...")
552
  logger.info("=== SERVER STARTING ===")
553
  logger.info(f"Public Key: {PUBLIC_KEY[:10] + '...' if PUBLIC_KEY else 'NOT_SET'}")
554
  logger.info(f"Millis URI: {MILLIS_WS_URI}")
 
1
  #!/usr/bin/env python3
2
  #
3
+ # san_integration_script.py (v6 - Simplified Audio Processing - Fixed)
4
  # ============================================================
5
  # Description:
6
  # - Establishes a real-time, two-way audio bridge between a SAN system
7
  # and the Millis AI platform.
8
  # - Direct audio forwarding at 16kHz PCM format (no conversion needed).
9
  # - Removed buffer logic for direct streaming.
10
+ # - Fixed credential extraction logic.
11
  #
12
  # Changes in this version:
13
  # - Removed audio format conversion logic (resampling)
14
  # - Removed buffer management and chunking
15
  # - Simplified audio flow for direct 16kHz PCM streaming
16
  # - Removed scipy dependency
17
+ # - Fixed comprehensive credential extraction fallback
18
  # -------------------------------------------------------------------
19
 
20
  import os
 
187
  extra_params = fallback_msg.get("extraParams", {})
188
  custom_field = fallback_msg.get("custom_field", {})
189
 
190
+ # Comprehensive agent_id extraction
191
  agent_id = (extra_params.get("platform_agent_id") or
192
  custom_field.get("agentId") or
193
+ fallback_msg.get("agentId") or
194
+ extra_params.get("agentId"))
195
 
196
+ # Comprehensive public_key extraction
197
  public_key = (extra_params.get("publicKey") or extra_params.get("public_key") or
198
  custom_field.get("publicKey") or custom_field.get("public_key") or
199
  fallback_msg.get("publicKey") or fallback_msg.get("public_key"))
 
412
  if processor is None:
413
  logger.info(f"Starting processor for call: {new_call_id}")
414
 
415
+ # Extract credentials with comprehensive fallback
416
  extra_params = msg.get("extraParams", {})
417
+ custom_field = msg.get("custom_field", {})
418
+
419
+ # Try multiple sources for agent_id (restored original logic)
420
+ agent_id = (extra_params.get("platform_agent_id") or
421
+ custom_field.get("agentId") or
422
+ msg.get("agentId") or
423
+ extra_params.get("agentId"))
424
+
425
+ # Try multiple sources for public_key
426
+ public_key = (PUBLIC_KEY or
427
+ extra_params.get("publicKey") or
428
+ extra_params.get("public_key") or
429
+ custom_field.get("publicKey") or
430
+ custom_field.get("public_key") or
431
+ msg.get("publicKey") or
432
+ msg.get("public_key"))
433
 
434
  if not agent_id or not public_key:
435
  credentials = await fetch_call_credentials_with_fallback(new_call_id, msg)
 
438
 
439
  if not agent_id:
440
  logger.error(f"No agent_id found for call_id: {new_call_id}")
441
+ logger.error("Tried: extraParams.platform_agent_id, custom_field.agentId, msg.agentId, extraParams.agentId, MongoDB")
442
  await ws.close(code=1008, reason="Missing agent_id")
443
  return
444
 
 
568
  }
569
 
570
  if __name__ == "__main__":
571
+ print("Starting SAN to Millis AI Integration Server (v6 - Simplified - Fixed)...")
572
  logger.info("=== SERVER STARTING ===")
573
  logger.info(f"Public Key: {PUBLIC_KEY[:10] + '...' if PUBLIC_KEY else 'NOT_SET'}")
574
  logger.info(f"Millis URI: {MILLIS_WS_URI}")