Fix Signal messages and replies
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import asyncio
|
||||
import base64
|
||||
import io
|
||||
import os
|
||||
import secrets
|
||||
import shutil
|
||||
import time
|
||||
from typing import Any
|
||||
from urllib.parse import quote_plus
|
||||
@@ -479,6 +481,46 @@ def _account_key(value: str) -> str:
|
||||
return raw
|
||||
|
||||
|
||||
def _wipe_signal_cli_local_state() -> bool:
|
||||
"""
|
||||
Best-effort local signal-cli state reset for json-rpc deployments where
|
||||
REST account delete endpoints are unavailable.
|
||||
"""
|
||||
config_roots = (
|
||||
"/code/signal-cli-config",
|
||||
"/signal-cli-config",
|
||||
"/home/.local/share/signal-cli",
|
||||
)
|
||||
removed_any = False
|
||||
for root in config_roots:
|
||||
if not os.path.isdir(root):
|
||||
continue
|
||||
try:
|
||||
entries = os.listdir(root)
|
||||
except Exception:
|
||||
continue
|
||||
for entry in entries:
|
||||
if not entry:
|
||||
continue
|
||||
# Keep runtime configuration scaffold; wipe account/pairing state.
|
||||
if entry in {"jsonrpc2.yml", "jsonrpc.yml"}:
|
||||
continue
|
||||
path = os.path.join(root, entry)
|
||||
if os.path.isdir(path):
|
||||
try:
|
||||
shutil.rmtree(path)
|
||||
removed_any = True
|
||||
except Exception:
|
||||
continue
|
||||
else:
|
||||
try:
|
||||
os.remove(path)
|
||||
removed_any = True
|
||||
except Exception:
|
||||
continue
|
||||
return removed_any
|
||||
|
||||
|
||||
def unlink_account(service: str, account: str) -> bool:
|
||||
service_key = _service_key(service)
|
||||
account_value = str(account or "").strip()
|
||||
@@ -492,14 +534,18 @@ def unlink_account(service: str, account: str) -> bool:
|
||||
"/"
|
||||
)
|
||||
target = quote_plus(account_value)
|
||||
unlinked = False
|
||||
for path in (f"/v1/accounts/{target}", f"/v1/account/{target}"):
|
||||
try:
|
||||
response = requests.delete(f"{base}{path}", timeout=20)
|
||||
if response.ok:
|
||||
return True
|
||||
unlinked = True
|
||||
break
|
||||
except Exception:
|
||||
continue
|
||||
return False
|
||||
if unlinked:
|
||||
return True
|
||||
return _wipe_signal_cli_local_state()
|
||||
|
||||
if service_key in {"whatsapp", "instagram"}:
|
||||
state = get_runtime_state(service_key)
|
||||
@@ -715,8 +761,13 @@ async def send_message_raw(
|
||||
prepared_attachments = await prepare_outbound_attachments(
|
||||
service_key, attachments or []
|
||||
)
|
||||
result = await signalapi.send_message_raw(recipient, text, prepared_attachments)
|
||||
meta = dict(metadata or {})
|
||||
result = await signalapi.send_message_raw(
|
||||
recipient,
|
||||
text,
|
||||
prepared_attachments,
|
||||
metadata=meta,
|
||||
)
|
||||
xmpp_source_id = str(meta.get("xmpp_source_id") or "").strip()
|
||||
if xmpp_source_id and result:
|
||||
from core.models import PersonIdentifier
|
||||
|
||||
Reference in New Issue
Block a user