Fix type errors in runner and add to pyright checked set
Make required parameters non-optional: LiveKitRunnerArguments.token, _create_telephony_transport args. Use os.environ[] instead of os.getenv() for required WhatsApp env vars. Guard spec/loader None in module loading. Tighten sip_caller_phone guard in daily.py.
This commit is contained in:
@@ -10,7 +10,8 @@
|
||||
"src/pipecat/observers",
|
||||
"src/pipecat/extensions",
|
||||
"src/pipecat/turns",
|
||||
"src/pipecat/pipeline"
|
||||
"src/pipecat/pipeline",
|
||||
"src/pipecat/runner"
|
||||
],
|
||||
"exclude": [
|
||||
"**/*_pb2.py",
|
||||
|
||||
@@ -228,7 +228,7 @@ async def configure(
|
||||
room_properties.enable_dialout = True
|
||||
|
||||
# Add SIP configuration if enabled
|
||||
if sip_enabled:
|
||||
if sip_enabled and sip_caller_phone:
|
||||
sip_params = DailyRoomSipParams(
|
||||
display_name=sip_caller_phone,
|
||||
video=sip_enable_video,
|
||||
|
||||
@@ -156,6 +156,8 @@ def _get_bot_module():
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
module_name, os.path.join(cwd, filename)
|
||||
)
|
||||
if spec is None or spec.loader is None:
|
||||
continue
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
|
||||
@@ -386,29 +388,24 @@ def _add_lifespan_to_app(app: FastAPI, new_lifespan):
|
||||
|
||||
def _setup_whatsapp_routes(app: FastAPI, args: argparse.Namespace):
|
||||
"""Set up WhatsApp-specific routes."""
|
||||
WHATSAPP_APP_SECRET = os.getenv("WHATSAPP_APP_SECRET")
|
||||
WHATSAPP_PHONE_NUMBER_ID = os.getenv("WHATSAPP_PHONE_NUMBER_ID")
|
||||
WHATSAPP_TOKEN = os.getenv("WHATSAPP_TOKEN")
|
||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN = os.getenv("WHATSAPP_WEBHOOK_VERIFICATION_TOKEN")
|
||||
|
||||
if not all(
|
||||
[
|
||||
WHATSAPP_APP_SECRET,
|
||||
WHATSAPP_PHONE_NUMBER_ID,
|
||||
WHATSAPP_TOKEN,
|
||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN,
|
||||
]
|
||||
):
|
||||
required_vars = [
|
||||
"WHATSAPP_APP_SECRET",
|
||||
"WHATSAPP_PHONE_NUMBER_ID",
|
||||
"WHATSAPP_TOKEN",
|
||||
"WHATSAPP_WEBHOOK_VERIFICATION_TOKEN",
|
||||
]
|
||||
missing = [v for v in required_vars if not os.getenv(v)]
|
||||
if missing:
|
||||
logger.error(
|
||||
"""Missing required environment variables for WhatsApp transport:
|
||||
WHATSAPP_APP_SECRET
|
||||
WHATSAPP_PHONE_NUMBER_ID
|
||||
WHATSAPP_TOKEN
|
||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN
|
||||
"""
|
||||
f"Missing required environment variables for WhatsApp transport: {', '.join(missing)}"
|
||||
)
|
||||
return
|
||||
|
||||
WHATSAPP_APP_SECRET = os.environ["WHATSAPP_APP_SECRET"]
|
||||
WHATSAPP_PHONE_NUMBER_ID = os.environ["WHATSAPP_PHONE_NUMBER_ID"]
|
||||
WHATSAPP_TOKEN = os.environ["WHATSAPP_TOKEN"]
|
||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN = os.environ["WHATSAPP_WEBHOOK_VERIFICATION_TOKEN"]
|
||||
|
||||
try:
|
||||
from pipecat.transports.smallwebrtc.connection import SmallWebRTCConnection
|
||||
from pipecat.transports.whatsapp.api import WhatsAppWebhookRequest
|
||||
|
||||
@@ -122,4 +122,4 @@ class LiveKitRunnerArguments(RunnerArguments):
|
||||
|
||||
room_name: str
|
||||
url: str
|
||||
token: str | None = None
|
||||
token: str
|
||||
|
||||
@@ -416,9 +416,9 @@ def _get_transport_params(transport_key: str, transport_params: dict[str, Callab
|
||||
|
||||
async def _create_telephony_transport(
|
||||
websocket: WebSocket,
|
||||
params: Any | None = None,
|
||||
transport_type: str = None,
|
||||
call_data: dict = None,
|
||||
params: Any,
|
||||
transport_type: str,
|
||||
call_data: dict,
|
||||
) -> BaseTransport:
|
||||
"""Create a telephony transport with pre-parsed WebSocket data.
|
||||
|
||||
@@ -433,12 +433,6 @@ async def _create_telephony_transport(
|
||||
"""
|
||||
from pipecat.transports.websocket.fastapi import FastAPIWebsocketTransport
|
||||
|
||||
if params is None:
|
||||
raise ValueError(
|
||||
"FastAPIWebsocketParams must be provided. "
|
||||
"The serializer and add_wav_header will be set automatically."
|
||||
)
|
||||
|
||||
# Always set add_wav_header to False for telephony
|
||||
params.add_wav_header = False
|
||||
|
||||
|
||||
Reference in New Issue
Block a user