aioappsrv/README.md

49 lines
1.4 KiB
Markdown
Raw Permalink 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-31 05:14:33 +01:00
mxid = "@_appsrv_firstuser:matrix.org"
room = "#my-epic-room:matrix.org"
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
await app.register_mxid(mxid)
await app.set_nick(mxid, "First User")
2024-01-31 05:14:33 +01:00
await app.set_avatar(mxid, "https://cdn.alemi.dev/profile/pic/someriver.jpg")
2024-01-31 05:08:37 +01:00
await app.invite_to_room(room, mxid)
await app.join_room(room, mxid)
2024-01-31 05:14:33 +01:00
await app.set_presence(mxid, online=True)
2024-01-31 05:08:37 +01:00
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
@app.callback(room)
async def my_cb(event: Event):
2024-01-31 05:14:33 +01:00
print(f"{event.room_id}| {event.sender} : {event.content['body']}")
await app.ack_event(event.room_id, event.event_id)
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 (: