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/observers",
|
||||||
"src/pipecat/extensions",
|
"src/pipecat/extensions",
|
||||||
"src/pipecat/turns",
|
"src/pipecat/turns",
|
||||||
"src/pipecat/pipeline"
|
"src/pipecat/pipeline",
|
||||||
|
"src/pipecat/runner"
|
||||||
],
|
],
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"**/*_pb2.py",
|
"**/*_pb2.py",
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ async def configure(
|
|||||||
room_properties.enable_dialout = True
|
room_properties.enable_dialout = True
|
||||||
|
|
||||||
# Add SIP configuration if enabled
|
# Add SIP configuration if enabled
|
||||||
if sip_enabled:
|
if sip_enabled and sip_caller_phone:
|
||||||
sip_params = DailyRoomSipParams(
|
sip_params = DailyRoomSipParams(
|
||||||
display_name=sip_caller_phone,
|
display_name=sip_caller_phone,
|
||||||
video=sip_enable_video,
|
video=sip_enable_video,
|
||||||
|
|||||||
@@ -156,6 +156,8 @@ def _get_bot_module():
|
|||||||
spec = importlib.util.spec_from_file_location(
|
spec = importlib.util.spec_from_file_location(
|
||||||
module_name, os.path.join(cwd, filename)
|
module_name, os.path.join(cwd, filename)
|
||||||
)
|
)
|
||||||
|
if spec is None or spec.loader is None:
|
||||||
|
continue
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module)
|
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):
|
def _setup_whatsapp_routes(app: FastAPI, args: argparse.Namespace):
|
||||||
"""Set up WhatsApp-specific routes."""
|
"""Set up WhatsApp-specific routes."""
|
||||||
WHATSAPP_APP_SECRET = os.getenv("WHATSAPP_APP_SECRET")
|
required_vars = [
|
||||||
WHATSAPP_PHONE_NUMBER_ID = os.getenv("WHATSAPP_PHONE_NUMBER_ID")
|
"WHATSAPP_APP_SECRET",
|
||||||
WHATSAPP_TOKEN = os.getenv("WHATSAPP_TOKEN")
|
"WHATSAPP_PHONE_NUMBER_ID",
|
||||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN = os.getenv("WHATSAPP_WEBHOOK_VERIFICATION_TOKEN")
|
"WHATSAPP_TOKEN",
|
||||||
|
"WHATSAPP_WEBHOOK_VERIFICATION_TOKEN",
|
||||||
if not all(
|
]
|
||||||
[
|
missing = [v for v in required_vars if not os.getenv(v)]
|
||||||
WHATSAPP_APP_SECRET,
|
if missing:
|
||||||
WHATSAPP_PHONE_NUMBER_ID,
|
|
||||||
WHATSAPP_TOKEN,
|
|
||||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN,
|
|
||||||
]
|
|
||||||
):
|
|
||||||
logger.error(
|
logger.error(
|
||||||
"""Missing required environment variables for WhatsApp transport:
|
f"Missing required environment variables for WhatsApp transport: {', '.join(missing)}"
|
||||||
WHATSAPP_APP_SECRET
|
|
||||||
WHATSAPP_PHONE_NUMBER_ID
|
|
||||||
WHATSAPP_TOKEN
|
|
||||||
WHATSAPP_WEBHOOK_VERIFICATION_TOKEN
|
|
||||||
"""
|
|
||||||
)
|
)
|
||||||
return
|
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:
|
try:
|
||||||
from pipecat.transports.smallwebrtc.connection import SmallWebRTCConnection
|
from pipecat.transports.smallwebrtc.connection import SmallWebRTCConnection
|
||||||
from pipecat.transports.whatsapp.api import WhatsAppWebhookRequest
|
from pipecat.transports.whatsapp.api import WhatsAppWebhookRequest
|
||||||
|
|||||||
@@ -122,4 +122,4 @@ class LiveKitRunnerArguments(RunnerArguments):
|
|||||||
|
|
||||||
room_name: str
|
room_name: str
|
||||||
url: 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(
|
async def _create_telephony_transport(
|
||||||
websocket: WebSocket,
|
websocket: WebSocket,
|
||||||
params: Any | None = None,
|
params: Any,
|
||||||
transport_type: str = None,
|
transport_type: str,
|
||||||
call_data: dict = None,
|
call_data: dict,
|
||||||
) -> BaseTransport:
|
) -> BaseTransport:
|
||||||
"""Create a telephony transport with pre-parsed WebSocket data.
|
"""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
|
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
|
# Always set add_wav_header to False for telephony
|
||||||
params.add_wav_header = False
|
params.add_wav_header = False
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user