-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMatrixClient.py
More file actions
30 lines (23 loc) · 841 Bytes
/
MatrixClient.py
File metadata and controls
30 lines (23 loc) · 841 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import config
import logging
import asyncio
import nio
log = logging.getLogger(__name__)
class MatrixClient:
def __init__(self):
self.client = nio.AsyncClient(config.MATRIX_SERVER, config.MATRIX_USER_NAME)
def login(self):
asyncio.get_event_loop().run_until_complete(self.client.login(config.MATRIX_PASSWORD))
async def do_send_message(self, message):
await self.client.room_send(
room_id=config.MATRIX_ROOM_ID,
message_type="m.room.message",
content={
"msgtype": "m.text",
"body": message
}
)
def send_message(self, message):
asyncio.get_event_loop().run_until_complete(self.do_send_message(message))
def __del__(self):
asyncio.get_event_loop().run_until_complete(self.client.close())