aioappsrv/README.md

1.4 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",
)
mxid = "@_appsrv_firstuser:matrix.org"
room = "#my-epic-room:matrix.org"

to execute actions use AppService's helper methods:

await app.register_mxid(mxid)
await app.set_nick(mxid, "First User")
await app.set_avatar(mxid, "https://cdn.alemi.dev/profile/pic/someriver.jpg")
await app.invite_to_room(room, mxid)
await app.join_room(room, mxid)
await app.set_presence(mxid, online=True)
await app.send_message(room, "<b>hello world!</b>")

to subscribe to room events use the callback decorator:

from aioappsrv.matrix import Event

@app.callback(room)
async def my_cb(event: Event):
	print(f"{event.room_id}| {event.sender} : {event.content['body']}")
	await app.ack_event(event.room_id, event.event_id)

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 (: