iamb icon indicating copy to clipboard operation
iamb copied to clipboard

`On message` callback

Open yassinebenarbia opened this issue 7 months ago • 5 comments

Feature

It would be really useful to have a way to run a lua script each time a message is received, where that script is optionally provided via the config file with something like this:

[settings]
on_message = "/path/to/script.lua"

and it would be nice to provide as much context about the message as possible to the script/function via a lua table

Note(s)

There is this dude that was able to pull something similar via mlua.

yassinebenarbia avatar Apr 24 '25 23:04 yassinebenarbia

What are you trying to achieve with this? Do you want to change state in iamb or just call external stuff.

I feel like it would be way easier to call an executable and provide context in environment variables, commandline arguments or on stdin.

VAWVAW avatar May 29 '25 22:05 VAWVAW

I was trying to display a notification message when I receive a DM like in the element desktop client, tho it would be best case scenario to be able to call internal stuff with some kind of exposed API (like in nvim) but simply being aware of some events and react to them would be good enough for now, tho what those evens are is kinda not clear for me, I think it's best starting with something simple like received DMs, like I suggested, and go from there.

Also, I don't get what you mean by call an executable and provide context in environment variables if you are talking about how to provide the "script" I think having it in config file, passing it as a command argument, or even using a specific env variable for it's path would work for now, tho the first option is much preferred imo, and for the language, I think lua would be the best here, no?

yassinebenarbia avatar May 30 '25 00:05 yassinebenarbia

Desktop notifications are already supported with the settings.notifications.enabled option.

Iamb currently has no lua capabilities and I expect that adding an interpreter and enough interfaces to make it useful is substantial work that probably should have support from upstream libraries.

On the other hand using the operating system to call a program like a bash or python script is really easy and would satisfy most use cases that don't need to modify the state of iamb.

VAWVAW avatar May 30 '25 10:05 VAWVAW

~The settings.notifications.enabled didn't work in my case, not sure why tho.~ It worked, but still want to add some custom behavior like sound effects and filter some messages, by user, server, etc.

Lua support should not be that hard to pull imo, tho it may be for providing internal API to interact with Iamb but providing a way to manage/handle "matrix events" from Lua should be reasonable for now.

I guess having another client to pull/recieve events isn't ideal no? I thought about writing a daemon to do that, and I'll probably end up with that, but it would be much better if this is a feature in Iamb so others/me don't have to do so.

yassinebenarbia avatar May 30 '25 20:05 yassinebenarbia

This kind of gets at one of the things I've been thinking about adding long-term. I'd like to do something similar to what trinity does and allow exposing an API for iamb plugins using wasmtime. This would allow folks to write plugins in a large number of languages as long as they have a way to compile it to use WASI.

Ideally one of the first plugins would be one that translates the hooks exposed to plugins and then executes a user-provided script with input to ensure that the two always have the same level of information and access.

ulyssa avatar May 31 '25 03:05 ulyssa