@@ -1434,20 +1434,29 @@ def main():
14341434 )
14351435
14361436 # Stop subcommand
1437- t_stop = telegram_subparsers .add_parser ("stop" , help = "Stop background Telegram adapter" )
1437+ t_stop = telegram_subparsers .add_parser (
1438+ "stop" , help = "Stop background Telegram adapter"
1439+ )
14381440 t_stop .add_argument (
14391441 "--force" ,
14401442 action = "store_true" ,
14411443 help = "Force stop even if graceful shutdown fails" ,
14421444 )
14431445
14441446 # Status subcommand
1445- t_status = telegram_subparsers .add_parser ("status" , help = "Show status of Telegram adapter" )
1447+ t_status = telegram_subparsers .add_parser (
1448+ "status" , help = "Show status of Telegram adapter"
1449+ )
14461450 t_status .add_argument (
1447- "--health-host" , default = "127.0.0.1" , help = "Health server host (default: 127.0.0.1)"
1451+ "--health-host" ,
1452+ default = "127.0.0.1" ,
1453+ help = "Health server host (default: 127.0.0.1)" ,
14481454 )
14491455 t_status .add_argument (
1450- "--health-port" , type = int , default = 8765 , help = "Health server port (default: 8765)"
1456+ "--health-port" ,
1457+ type = int ,
1458+ default = 8765 ,
1459+ help = "Health server port (default: 8765)" ,
14511460 )
14521461
14531462 telegram_parser .set_defaults (action = "telegram" )
@@ -2206,20 +2215,34 @@ def main():
22062215 action = getattr (args , "telegram_action" , None )
22072216 if action == "start" :
22082217 try :
2209- from gaia .messaging .telegram import run_telegram
2218+ import importlib
2219+
2220+ mod = importlib .import_module ("gaia.messaging.telegram" )
2221+ run_telegram = getattr (mod , "run_telegram" )
22102222 except Exception as e : # pragma: no cover - runtime import error
22112223 print (f"❌ Telegram support is not available: { e } " , file = sys .stderr )
22122224 sys .exit (1 )
22132225
22142226 allowed = None
22152227 if getattr (args , "allowed_users" , None ):
22162228 try :
2217- allowed = set (int (x .strip ()) for x in args .allowed_users .split ("," ) if x .strip ())
2229+ allowed = set (
2230+ int (x .strip ())
2231+ for x in args .allowed_users .split ("," )
2232+ if x .strip ()
2233+ )
22182234 except Exception :
2219- print ("Invalid --allowed-users format; expected comma-separated integers" , file = sys .stderr )
2235+ print (
2236+ "Invalid --allowed-users format; expected comma-separated integers" ,
2237+ file = sys .stderr ,
2238+ )
22202239 sys .exit (2 )
22212240
2222- run_telegram (token = args .token , allowed_users = allowed , background = getattr (args , "background" , False ))
2241+ run_telegram (
2242+ token = args .token ,
2243+ allowed_users = allowed ,
2244+ background = getattr (args , "background" , False ),
2245+ )
22232246 return
22242247
22252248 if action == "stop" :
@@ -2254,8 +2277,8 @@ def main():
22542277
22552278 if action == "status" :
22562279 # Prefer health endpoint; fallback to pid file existence
2257- import urllib .request
22582280 import urllib .error
2281+ import urllib .request
22592282
22602283 host = getattr (args , "health_host" , "127.0.0.1" )
22612284 port = getattr (args , "health_port" , 8765 )
@@ -2271,12 +2294,17 @@ def main():
22712294
22722295 pid_path = os .path .expanduser ("~/.gaia/telegram.pid" )
22732296 if os .path .exists (pid_path ):
2274- print ("Telegram adapter: PID file exists, but health check failed (may be starting or unhealthy)." )
2297+ print (
2298+ "Telegram adapter: PID file exists, but health check failed (may be starting or unhealthy)."
2299+ )
22752300 else :
22762301 print ("Telegram adapter: not running" )
22772302 return
22782303
2279- print ("No telegram action specified. Use: gaia telegram start|stop|status" , file = sys .stderr )
2304+ print (
2305+ "No telegram action specified. Use: gaia telegram start|stop|status" ,
2306+ file = sys .stderr ,
2307+ )
22802308 return
22812309
22822310 # Handle core Gaia CLI commands
0 commit comments