feat: add invite to room method
This commit is contained in:
parent
870a4faa9b
commit
075bc52cbe
1 changed files with 21 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue