docs: showcase more methods

This commit is contained in:
əlemi 2024-01-31 05:14:33 +01:00
parent 7b385e3103
commit d134faa17e
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -19,16 +19,18 @@ app = AppService(
as_token="YOUR-APPSERVICE-TOKEN", as_token="YOUR-APPSERVICE-TOKEN",
hs_token="YOUR-HOMESERVER-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: to execute actions use AppService's helper methods:
```python ```python
mxid = "@_appsrv_firstuser:matrix.org"
room = "#my-epic-room:matrix.org"
await app.register_mxid(mxid) await app.register_mxid(mxid)
await app.set_nick(mxid, "First User") 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.invite_to_room(room, mxid)
await app.join_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>") await app.send_message(room, "<b>hello world!</b>")
``` ```
@ -36,10 +38,10 @@ to subscribe to room events use the callback decorator:
```python ```python
from aioappsrv.matrix import Event from aioappsrv.matrix import Event
room = "#my-epic-room:matrix.org"
@app.callback(room) @app.callback(room)
async def my_cb(event: Event): async def my_cb(event: Event):
print(f"{event.sender}: {event.content['body']}") print(f"{event.room_id}| {event.sender} : {event.content['body']}")
await app.ack_event(event.room_id, event.event_id)
``` ```
## state ## state