Fix Signal messages and replies
This commit is contained in:
@@ -9,6 +9,7 @@ from core.clients.transport import send_message_raw
|
||||
from core.messaging import ai as ai_runner
|
||||
from core.models import (
|
||||
AI,
|
||||
Chat,
|
||||
ChatTaskSource,
|
||||
DerivedTask,
|
||||
DerivedTaskEvent,
|
||||
@@ -30,18 +31,43 @@ def _channel_variants(service: str, channel: str) -> list[str]:
|
||||
if not value:
|
||||
return []
|
||||
variants = [value]
|
||||
if str(service or "").strip().lower() == "whatsapp":
|
||||
service_key = str(service or "").strip().lower()
|
||||
if service_key == "whatsapp":
|
||||
bare = value.split("@", 1)[0].strip()
|
||||
if bare and bare not in variants:
|
||||
variants.append(bare)
|
||||
direct = f"{bare}@s.whatsapp.net" if bare else ""
|
||||
if direct and direct not in variants:
|
||||
variants.append(direct)
|
||||
group = f"{bare}@g.us" if bare else ""
|
||||
if group and group not in variants:
|
||||
variants.append(group)
|
||||
if service_key == "signal":
|
||||
digits = re.sub(r"[^0-9]", "", value)
|
||||
if digits and digits not in variants:
|
||||
variants.append(digits)
|
||||
if digits:
|
||||
plus = f"+{digits}"
|
||||
if plus not in variants:
|
||||
variants.append(plus)
|
||||
return variants
|
||||
|
||||
|
||||
async def _resolve_source_mappings(message: Message) -> list[ChatTaskSource]:
|
||||
variants = _channel_variants(message.source_service or "", message.source_chat_id or "")
|
||||
if str(message.source_service or "").strip().lower() == "signal":
|
||||
signal_value = str(message.source_chat_id or "").strip()
|
||||
if signal_value:
|
||||
companions = await sync_to_async(list)(
|
||||
Chat.objects.filter(source_uuid=signal_value).values_list("source_number", flat=True)
|
||||
)
|
||||
companions += await sync_to_async(list)(
|
||||
Chat.objects.filter(source_number=signal_value).values_list("source_uuid", flat=True)
|
||||
)
|
||||
for candidate in companions:
|
||||
for expanded in _channel_variants("signal", str(candidate or "").strip()):
|
||||
if expanded and expanded not in variants:
|
||||
variants.append(expanded)
|
||||
if not variants:
|
||||
return []
|
||||
return await sync_to_async(list)(
|
||||
|
||||
Reference in New Issue
Block a user