gateway: accept v7 contact requests using contactRequestId

The v7 receivedContactRequest event exposes contactRequestId (and contactId_,
the underscore being the generated-API optional marker); /_accept takes the
request id. The adapter looked for contactRequest.contactId, found nothing, and
silently no-oped — so contact requests hung unaccepted. Prefer contactRequestId,
fall back to contactId for legacy events, and trace the accepted ids. Tests for
both shapes and the disabled case.
This commit is contained in:
Denton Social committed 2026-09-26 18:52:58 -05:00
1 parent c92aff5038
commit 221edb827e
2 files changed
+53 -4

No files matched your search

+15 -4
View File
@@ -186,14 +186,25 @@ class SimplexAdapter(GatewayAdapter):
async def _maybe_accept(self, ws, resp: dict) -> None:
if not self.auto_accept:
return
contact_id = (resp.get("contactRequest") or {}).get("contactId")
if contact_id is None:
req = resp.get("contactRequest") or {}
# v7 names the field contactRequestId_ (the trailing underscore is the
# generated-API optional marker) and /_accept takes the *request* id;
# older events exposed contactId. Fall back so both shapes work.
req_id = req.get("contactRequestId")
if req_id is None:
req_id = req.get("contactId_") or req.get("contactId")
if req_id is None:
return
self._corr += 1
await ws.send(
json.dumps({"corrId": f"sf-{self._corr}", "cmd": f"/_accept {contact_id}"})
json.dumps({"corrId": f"sf-{self._corr}", "cmd": f"/_accept {req_id}"})
)
contact_id = req.get("contactId_") or req.get("contactId")
self._event(
"gateway_accepted",
contact_request_id=str(req_id),
contact_id=str(contact_id) if contact_id is not None else "",
)
self._event("gateway_accepted", contact_id=str(contact_id))
def _schedule_flush(self, message: InboundMessage, on_inbound) -> None:
chat = message.chat_id