11from typing import Any
22
3- import httpx
3+ import requests
44
55from app .types .exceptions import MatrixRequestError , MatrixSendMessageError
66
@@ -24,7 +24,7 @@ def __init__(
2424
2525 self .access_token = token
2626
27- async def post (
27+ def post (
2828 self ,
2929 url : str ,
3030 json : dict [str , Any ],
@@ -43,18 +43,15 @@ async def post(
4343 if "Authorization" not in headers :
4444 headers ["Authorization" ] = "Bearer " + self .access_token
4545
46+ response = requests .post (url , json = json , headers = headers , timeout = 10 )
4647 try :
47- async with httpx .AsyncClient () as client :
48- response = await client .post (
49- url , json = json , headers = headers , timeout = 10
50- )
5148 response .raise_for_status ()
52- except httpx . RequestError as err :
49+ except requests . exceptions . HTTPError as err :
5350 raise MatrixRequestError () from err
5451
5552 return response .json ()
5653
57- async def send_message (self , room_id : str , formatted_body : str ) -> None :
54+ def send_message (self , room_id : str , formatted_body : str ) -> None :
5855 """
5956 Send a message to the room `room_id`.
6057 `formatted_body` can contain html formatted text
@@ -74,6 +71,6 @@ async def send_message(self, room_id: str, formatted_body: str) -> None:
7471 }
7572
7673 try :
77- await self .post (url , json = data , headers = None )
74+ self .post (url , json = data , headers = None )
7875 except MatrixRequestError as error :
7976 raise MatrixSendMessageError (room_id = room_id ) from error
0 commit comments