Improve insights and continue WhatsApp implementation

This commit is contained in:
2026-02-15 23:02:51 +00:00
parent b23af9bc7f
commit 88224d972c
13 changed files with 628 additions and 81 deletions

View File

@@ -795,7 +795,15 @@ class XMPPComponent(ComponentXMPP):
# self.log.info(f"Upload service: {upload_service}")
upload_service_jid = "share.zm.is"
upload_service_jid = str(
getattr(settings, "XMPP_UPLOAD_SERVICE", "")
or getattr(settings, "XMPP_UPLOAD_JID", "")
).strip()
if not upload_service_jid:
self.log.error(
"XMPP upload service is not configured. Set XMPP_UPLOAD_SERVICE."
)
return None
try:
slot = await self["xep_0363"].request_slot(
@@ -1109,7 +1117,7 @@ class XMPPComponent(ComponentXMPP):
self.log.error(
f"Upload failed: {response.status} {await response.text()}"
)
return
return None
self.log.info(
f"Successfully uploaded {att['filename']} to {upload_url}"
)
@@ -1118,9 +1126,11 @@ class XMPPComponent(ComponentXMPP):
await self.send_xmpp_message(
recipient_jid, sender_jid, upload_url, attachment_url=upload_url
)
return upload_url
except Exception as e:
self.log.error(f"Error uploading {att['filename']} to XMPP: {e}")
return None
async def send_xmpp_message(
self, recipient_jid, sender_jid, body_text, attachment_url=None
@@ -1177,21 +1187,22 @@ class XMPPComponent(ComponentXMPP):
await self.send_xmpp_message(recipient_jid, sender_jid, text)
if not attachments:
return # No attachments to process
return [] # No attachments to process
# Step 2: Request upload slots concurrently
valid_uploads = await self.request_upload_slots(recipient_jid, attachments)
self.log.info("Got upload slots")
if not valid_uploads:
self.log.warning("No valid upload slots obtained.")
# return
return []
# Step 3: Upload each file and send its message immediately after upload
upload_tasks = [
self.upload_and_send(att, slot, recipient_jid, sender_jid)
for att, slot in valid_uploads
]
await asyncio.gather(*upload_tasks) # Upload files concurrently
uploaded_urls = await asyncio.gather(*upload_tasks) # Upload files concurrently
return [url for url in uploaded_urls if url]
class XMPPClient(ClientBase):