diff --git a/core/clients/signalapi.py b/core/clients/signalapi.py index dc72748..9348bce 100644 --- a/core/clients/signalapi.py +++ b/core/clients/signalapi.py @@ -1,4 +1,3 @@ - from rest_framework import status import requests @@ -11,7 +10,8 @@ import asyncio async def start_typing(uuid): - url = f"http://signal:8080/v1/typing_indicator/{settings.SIGNAL_NUMBER}" + base = getattr(settings, "SIGNAL_HTTP_URL", "http://signal:8080").rstrip("/") + url = f"{base}/v1/typing_indicator/{settings.SIGNAL_NUMBER}" data = {"recipient": uuid} async with aiohttp.ClientSession() as session: @@ -19,7 +19,8 @@ async def start_typing(uuid): return await response.text() # Optional: Return response content async def stop_typing(uuid): - url = f"http://signal:8080/v1/typing_indicator/{settings.SIGNAL_NUMBER}" + base = getattr(settings, "SIGNAL_HTTP_URL", "http://signal:8080").rstrip("/") + url = f"{base}/v1/typing_indicator/{settings.SIGNAL_NUMBER}" data = {"recipient": uuid} async with aiohttp.ClientSession() as session: @@ -68,7 +69,8 @@ async def send_message_raw(recipient_uuid, text=None, attachments=[]): Returns: int | bool: Timestamp if successful, False otherwise. """ - url = "http://signal:8080/v2/send" + base = getattr(settings, "SIGNAL_HTTP_URL", "http://signal:8080").rstrip("/") + url = f"{base}/v2/send" data = { "recipients": [recipient_uuid], @@ -117,7 +119,8 @@ async def fetch_signal_attachment(attachment_id): } or None if the request fails. """ - url = f"http://signal:8080/v1/attachments/{attachment_id}" + base = getattr(settings, "SIGNAL_HTTP_URL", "http://signal:8080").rstrip("/") + url = f"{base}/v1/attachments/{attachment_id}" try: async with aiohttp.ClientSession() as session: diff --git a/core/clients/xmpp.py b/core/clients/xmpp.py index ad5a953..c7fd767 100644 --- a/core/clients/xmpp.py +++ b/core/clients/xmpp.py @@ -307,9 +307,6 @@ class XMPPComponent(ComponentXMPP): self.log.warning("XMPP disconnected, attempting to reconnect...") self.connect() - def session_start(self, *args): - self.log.info(f"Session started: {args}") - async def request_upload_slot(self, recipient, filename, content_type, size): """ Requests an upload slot from XMPP for HTTP File Upload (XEP-0363). @@ -647,5 +644,8 @@ class XMPPClient(ClientBase): def start(self): self.log.info("XMPP client starting...") + # ensure slixmpp uses the same asyncio loop as the router + self.client.loop = self.loop + self.client.connect() #self.client.process() \ No newline at end of file diff --git a/core/management/commands/ur.py b/core/management/commands/ur.py index 18345e6..c6436a5 100644 --- a/core/management/commands/ur.py +++ b/core/management/commands/ur.py @@ -13,6 +13,6 @@ class Command(BaseCommand): instance = UnifiedRouter(loop) - instance.start() + #instance.start() instance.run() \ No newline at end of file diff --git a/core/modules/router.py b/core/modules/router.py index 07d69f4..a386270 100644 --- a/core/modules/router.py +++ b/core/modules/router.py @@ -17,14 +17,18 @@ class UnifiedRouter(object): self.xmpp = XMPPClient(self, loop, "xmpp") self.signal = SignalClient(self, loop, "signal") - def start(self): + def _start(self): + print("UR _start") self.xmpp.start() self.signal.start() def run(self): try: - self.xmpp.client.process() + #self.xmpp.client.client.process() + # self.xmpp.start() + print("IN RUN BEFORE START") + self._start() self.loop.run_forever() except (KeyboardInterrupt, SystemExit): self.log.info("Process terminating")