aioappsrv/README.md

47 lines
1.2 KiB
Markdown
Raw Normal View History

2024-01-31 05:08:37 +01:00
# aioappsrv
a tiny async library made with aiohttp to build matrix automation using its appservice api
2020-11-12 15:59:10 +01:00
2024-01-31 05:08:37 +01:00
## installation
currently not on PyPI, clone this repo and pip install it:
2024-01-29 03:27:13 +01:00
```
2024-01-31 05:08:37 +01:00
git clone https://git.alemi.dev/aioappsrv
cd aioappsrv
pip install .
2024-01-29 03:27:13 +01:00
```
2021-01-21 08:58:40 +01:00
2024-01-31 05:08:37 +01:00
## usage
you should first instantiate an AppService object providing `as`/`hs` tokens and your homeserver url:
```python
from aioappsrv.app import AppService
2024-01-29 03:27:13 +01:00
2024-01-31 05:08:37 +01:00
app = AppService(
homeserver="matrix.org",
as_token="YOUR-APPSERVICE-TOKEN",
hs_token="YOUR-HOMESERVER-TOKEN",
)
2024-01-29 03:27:13 +01:00
```
2024-01-31 05:08:37 +01:00
to execute actions use AppService's helper methods:
```python
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>")
2024-01-29 03:27:13 +01:00
```
2024-01-31 05:08:37 +01:00
to subscribe to room events use the callback decorator:
```python
from aioappsrv.matrix import Event
2024-01-29 03:27:13 +01:00
2024-01-31 05:08:37 +01:00
room = "#my-epic-room:matrix.org"
@app.callback(room)
async def my_cb(event: Event):
print(f"{event.sender}: {event.content['body']}")
2024-01-29 03:27:13 +01:00
```
2024-01-31 05:08:37 +01:00
## 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 (: