Matrix Pill Mention Rules

What it does

This tool makes it so that you don't get pinged anymore by mere mentions of your name or user ID. Instead, people who want to ping you must use a 'pill' (as they're called in Element).

Who to blame when things go wrong

This tool was quickly thrown together by Olivier 'reivilibre' in 2 lunchtimes!

The tool




Likely desirable controls

Advanced controls: Pill mentions

Advanced controls: Plaintext mentions


How it works

This tool uses the 'push rules' mechanism built in to the Matrix client-server specification. It adds a push rule which causes you to get notified on your pills (well, actually, any HTML messages containing the matrix.to URL to your user — but it's close enough that the few false-positives are probably interesting to you anyway).

It also disables the built-in rules that would cause you to be notified when your display name or user ID localpart (user name) are in a message. No more 1337sp33k trying to dodge pinging people!

These rules directly apply to unencrypted messages (the rules are implemented in Synapse and other homeservers), but clients such as Element also implement them client-side for encrypted messages, so this should work there too (tested to work on Element Web).

Do it with cURL instead

Yes, putting your Matrix details into some random webpage is probably not a great habit to get into. If you'd prefer, you can use the below cURL commands to do the same thing that this tool does:

To install the rule changes:

token='syt_WOO'  # use your actual access token
hs='https://matrix.librepush.net'  # use your actual homeserver
user='@reivilibre:librepush.net'  # use your actual user ID
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/pill_mention_$user" -d \
'{
   "conditions": [
     { "kind": "event_match", "key": "content.formatted_body", "pattern": "*https://matrix.to/#/'"$user"'*" }
   ],
   "actions" : [
     "notify",
     {
       "set_tweak": "sound",
       "value": "default"
     },
     {
       "set_tweak": "highlight"
     }
   ]
}'
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/.m.rule.contains_display_name/enabled" -d '{"enabled": false}'
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/.m.rule.contains_user_name/enabled" -d '{"enabled": false}'

To uninstall the rule changes:

token='syt_WOO'  # use your actual access token
hs='https://matrix.librepush.net'  # use your actual homeserver
user='@reivilibre:librepush.net'  # use your actual user ID
curl -X DELETE -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/pill_mention_$user"
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/.m.rule.contains_display_name/enabled" -d '{"enabled": true}'
curl -X PUT -H "Content-Type: application/json" -H "Authorization: Bearer $token" "$hs/_matrix/client/r0/pushrules/global/override/.m.rule.contains_user_name/enabled" -d '{"enabled": true}'