feat: add invite to room method

This commit is contained in:
əlemi 2024-01-29 20:41:05 +01:00
parent 870a4faa9b
commit 075bc52cbe
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -76,6 +76,23 @@ class AppService:
return func
return wrapper
async def invite_to_room(self, room: str, mxid: str) -> None:
async with self._client.request(
method="POST",
url=f"{self.base_url}/_matrix/client/r0/rooms/{room}/invite",
headers={
"Authorization": f"Bearer {self.as_token}",
"Content-Type": "application/json",
},
params={"user_id": mxid},
) as res:
if res.ok:
self.logger.debug("inviting to room %s with %s : %s", room, mxid, await res.json())
else:
self.logger.error("failed inviting to room: %s", await res.text())
res.raise_for_status()
async def join_room(self, room: str, mxid: str | None = None):
async with self._client.request(
method="POST",
@ -89,8 +106,8 @@ class AppService:
if res.ok:
self.logger.debug("joined room %s with %s : %s", room, mxid, await res.json())
else:
self.logger.error("failed sending message: %s", await res.text())
raise ValueError()
self.logger.error("failed joining room: %s", await res.text())
res.raise_for_status()
async def leave_room(self):
raise NotImplementedError
@ -113,7 +130,8 @@ class AppService:
else:
text = await res.text()
self.logger.error("failed sending message: %s", text)
raise ValueError()
res.raise_for_status()
return ""
async def redact_message(self):
raise NotImplementedError