1.2 KiB
1.2 KiB
aioappsrv
a tiny async library made with aiohttp to build matrix automation using its appservice api
installation
currently not on PyPI, clone this repo and pip install it:
git clone https://git.alemi.dev/aioappsrv
cd aioappsrv
pip install .
usage
you should first instantiate an AppService object providing as
/hs
tokens and your homeserver url:
from aioappsrv.app import AppService
app = AppService(
homeserver="matrix.org",
as_token="YOUR-APPSERVICE-TOKEN",
hs_token="YOUR-HOMESERVER-TOKEN",
)
to execute actions use AppService's helper methods:
mxid = "@_appsrv_firstuser:matrix.org"
room = "#my-epic-room:matrix.org"
await app.register_mxid(mxid)
await app.set_nick(mxid, "First User")
await app.invite_to_room(room, mxid)
await app.join_room(room, mxid)
await app.send_message(room, "<b>hello world!</b>")
to subscribe to room events use the callback decorator:
from aioappsrv.matrix import Event
room = "#my-epic-room:matrix.org"
@app.callback(room)
async def my_cb(event: Event):
print(f"{event.sender}: {event.content['body']}")
state
this is quite early in development, i want to keep the general usage flow of this but don't get attached to import paths because they will change (: