Vlad's Roam Garden

Powered by 🌱Roam Garden

How to create a serverless Matrix Chat bot

Last updated::


{{TODO}} Serverless is good section

maybe assume people come here already with the conception of this being good and have this as an addendum

no filtering on rules, but! even in this case it's very useful bc most of the time even in relatively large chat groups there no new messages every second

so most of the time the bot is idle

there are no explicit facilities to create a serverless bot in matrix

and bots generally are treated as "normal users"

but we can piggy-back on the push notifications mechanism which does a thing very similar to what we're looking for - on a new message (matching some criteria) it'll call an http endpoint with a given event content

I've built a small tool that simplifies a setup for this at ....

code at ...

and you can also see the explanation of what it's doing in the Readme

(this is actually the main "trick" from here you'd proceed as if you're building a serverless bot for any other platform)

After you've set up this up - your http endpont would be called with the content of the events

excluding the events sent by the bot user (...)

They would look like

...

We'll use th

caveats

messages from self and usability in DMs

about encrypted messages

Inability to filter what messages get delivered

push notifications hack works but
encrypted messages are a problem
this is solvable by using unencrypted rooms =\
or maybe there is a way to share keys with the bot ?
workaround
it seems reacts to encrypted messages are not-encrypted (to confirm)
so I can treat the original message as a black box (hopefully can still show preview/etc, but also just having a link works)
server won’t send you notifications about events from you =\
this seems to be hardcoded into spec, tried different rules, but does not seem to help
hopefully a simple change to spec/server tho, but annoying
workarounds?
forward messages to another test user or something like that?
makes it not very useful in the context of group chats tho
specifically the whole emoji react to do things won’t work anymore
have the rule registered under a different user in group chats,
kind of helps with encryption stuff too
won’t work in dms tho, which was the attractive part of this model

{{TODO}}

So when I write about the serverless serverless matrix bot bots in matrix, I can create the very basic static page tool that would register a webhook "on any message post to this URL"
there is no filtering messages sent by the bots wouldn't be a trigger it which is mostly a problem