Send verification ready when receiving verification request
This commit is contained in:
parent
bdede4dbf4
commit
23ca556d87
1 changed files with 24 additions and 2 deletions
|
|
@ -144,8 +144,30 @@ async def on_to_device(client: AsyncClient, event):
|
|||
"""Handles incoming interactive SAS key verification events automatically."""
|
||||
if isinstance(event, UnknownToDeviceEvent):
|
||||
if event.type == "m.key.verification.request":
|
||||
from_device = event.source.get("content", {}).get("from_device", "unknown")
|
||||
print(f"Received m.key.verification.request from {event.sender} ({from_device}).")
|
||||
content = event.source.get("content", {})
|
||||
tx_id = content.get("transaction_id")
|
||||
from_device = content.get("from_device", "*")
|
||||
|
||||
if tx_id:
|
||||
print(f"Received verification request {tx_id} from {event.sender} ({from_device}). Replying with 'ready'...")
|
||||
ready_content = {
|
||||
"from_device": client.device_id,
|
||||
"methods": ["m.sas.v1"],
|
||||
"transaction_id": tx_id,
|
||||
}
|
||||
resp = await client.to_device(
|
||||
"m.key.verification.ready",
|
||||
ready_content,
|
||||
event.sender,
|
||||
from_device,
|
||||
)
|
||||
if isinstance(resp, ToDeviceError):
|
||||
print(f"Failed to send verification ready: {resp}")
|
||||
else:
|
||||
print(f"Sent m.key.verification.ready for {tx_id}. Awaiting start...")
|
||||
|
||||
elif event.type == "m.key.verification.done":
|
||||
print(f"✅ Key verification done event received from {event.sender}.")
|
||||
|
||||
elif isinstance(event, KeyVerificationStart):
|
||||
print(f"Received key verification start from {event.sender} ({event.from_device}). Accepting start...")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue