simple and asynchronous matrix appservice framework
Find a file
alemi 6f7ddbbc9e
feat: impersonated ack event
the matrix client-server spec actually doesn't say anything about
passing user_id as param:
https://spec.matrix.org/latest/client-server-api/#post_matrixclientv3roomsroomidreceiptreceipttypeeventid
however matrix-bot-sdk inside its "doRequest" method adds it as query
parameter nonetheless:
4fb43f174e/src/MatrixClient.ts (L2005)
4fb43f174e/src/MatrixClient.ts (L1201)
maybe it just works on some servers?
2024-02-03 17:12:54 +01:00
src/aioappsrv feat: impersonated ack event 2024-02-03 17:12:54 +01:00
.editorconfig chore: restructured and packaged 2024-01-29 03:27:13 +01:00
.gitignore chore: restructured and packaged 2024-01-29 03:27:13 +01:00
LICENSE Create LICENSE 2020-11-11 11:48:31 +00:00
pyproject.toml fix: wrong author email 2024-01-29 16:55:17 +01:00
README.md docs: showcase more methods 2024-01-31 05:14:33 +01:00

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