@@ -68,12 +68,13 @@ async def run_bot(args: SessionArguments, transport_type: Optional[str] = None):
6868 logger .info (f"Starting bot session with metadata: { json .dumps (metadata )} " )
6969 logger .debug (f"Transport type: { transport_type } " )
7070
71- if GLOBALS ["session_manager" ]:
71+ session_manager = GLOBALS .get ("session_manager" )
72+ if session_manager :
7273 if isinstance (args , PipecatSessionArguments ) and transport_type == "webrtc" :
7374 logger .info ("Will wait for the webrtc_connection to be set!" )
7475 try :
7576 GLOBALS ["pipecat_session_body" ] = args .body
76- await GLOBALS [ " session_manager" ] .wait_for_webrtc ()
77+ await session_manager .wait_for_webrtc ()
7778 except TimeoutError as e :
7879 logger .error (f"Timeout waiting for WebRTC connection: { e } " )
7980 raise
@@ -82,19 +83,19 @@ async def run_bot(args: SessionArguments, transport_type: Optional[str] = None):
8283 logger .info (
8384 "Received the webrtc_connection from Pipecat Cloud, cancelling the timeout"
8485 )
85- GLOBALS [ " session_manager" ] .cancel_timeout ()
86+ session_manager .cancel_timeout ()
8687 if not args .body :
87- args .body = GLOBALS [ "pipecat_session_body" ]
88+ args .body = GLOBALS . get ( "pipecat_session_body" )
8889
8990 try :
9091 await bot (args )
9192 except Exception as e :
9293 logger .error (f"Exception running bot(): { e } " )
9394 finally :
9495 logger .info (f"Stopping bot session with metadata: { json .dumps (metadata )} " )
95- if GLOBALS [ "session_manager" ]:
96- GLOBALS [ " session_manager" ]. complete_session ()
97- GLOBALS [ " session_manager" ] = None
96+ session_manager = GLOBALS . get ( "session_manager" )
97+ if session_manager :
98+ session_manager . complete_session ()
9899 GLOBALS ["pipecat_session_body" ] = None
99100
100101
0 commit comments