Skip to content

Commit 13a5cce

Browse files
committed
Add support for m.mentions in send_text_to_room (spec v1.9).
1 parent 436cb89 commit 13a5cce

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

matrix_reminder_bot/functions.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ async def send_text_to_room(
1717
notice: bool = True,
1818
markdown_convert: bool = True,
1919
reply_to_event_id: Optional[str] = None,
20+
mentions_room: bool = False,
21+
mentions_user_ids: Optional[list[str]] = None,
2022
):
2123
"""Send text to a matrix room.
2224
@@ -35,14 +37,21 @@ async def send_text_to_room(
3537
3638
reply_to_event_id: Whether this message is a reply to another event. The event
3739
ID this is message is a reply to.
40+
41+
mentions_room: Whether or not this message mentions the whole room.
42+
Defaults to false.
43+
44+
mentions_user_ids: An optional list of MXIDs this message mentions.
3845
"""
46+
3947
# Determine whether to ping room members or not
4048
msgtype = "m.notice" if notice else "m.text"
4149

4250
content = {
4351
"msgtype": msgtype,
4452
"format": "org.matrix.custom.html",
4553
"body": message,
54+
"m.mentions": {},
4655
}
4756

4857
if markdown_convert:
@@ -51,6 +60,12 @@ async def send_text_to_room(
5160
if reply_to_event_id:
5261
content["m.relates_to"] = {"m.in_reply_to": {"event_id": reply_to_event_id}}
5362

63+
if mentions_room:
64+
content["m.mentions"]["room"] = True
65+
66+
if mentions_user_ids is not None:
67+
content["m.mentions"]["user_ids"] = mentions_user_ids
68+
5469
try:
5570
await client.room_send(
5671
room_id,

0 commit comments

Comments
 (0)