main
py 41 lines 1.31 KB
Raw
1 """Start WhatsApp bridge immediately."""
2
3 from helpers.api import ApiHandler, Request
4 from helpers.errors import format_error
5 from helpers import plugins
6
7
8 PLUGIN_NAME = "_whatsapp_integration"
9
10
11 class Start(ApiHandler):
12
13 async def process(self, input: dict, request: Request) -> dict:
14 config = plugins.get_plugin_config(PLUGIN_NAME) or {}
15 port = int(config.get("bridge_port", 3100))
16 mode = config.get("mode", "self-chat")
17
18 from plugins._whatsapp_integration.helpers.bridge_manager import (
19 ensure_bridge_http_up,
20 is_process_alive,
21 )
22 from plugins._whatsapp_integration.helpers.storage_paths import (
23 get_bridge_media_dir,
24 get_bridge_session_dir,
25 )
26
27 session_dir = get_bridge_session_dir()
28 cache_dir = get_bridge_media_dir()
29
30 if is_process_alive():
31 return {"success": True, "message": "Bridge already running"}
32
33 try:
34 ok = await ensure_bridge_http_up(
35 port, session_dir, cache_dir, mode=mode,
36 )
37 if ok:
38 return {"success": True, "message": "Bridge started"}
39 return {"success": False, "message": "Failed to start bridge"}
40 except Exception as e:
41 return {"success": False, "message": format_error(e)}