It would be awesome if the Trilium Server supported a simple Webhook mechanism for note submission.
I would immediately leverage this to send notes to Trilium from Slack, from IFTTT, from JIRA, etc.
Hmm, Trilium actually does have API to do this, but it's currently not documented. It is used in trilium-sender which is a simple Android app from which you can create notes and send pictures to Trilium.
Looking at that code - I think the main change here is support for an "api key" or other token that would allow a robot to login. (Otherwise Slack/IFTT/Other isn't going to be able to authenticate).
Yes - the flow in the android app is that first user needs to login using credentials using which the android app gets long lived token which is then used for authentication against the server installation.
But I guess for e.g. Slack it would make more sense to generate the token in Trilium and then manually set it in the slack plugin, right?
I dug a little deeper into Slack and IFTTT - just as the two services that I can personally imagine using the most.... There are probably myriad other apps and integrations that could be imagined.
Slack's integration is not as easy as I had hoped. Slack allows you to easily create "slash commands" that call a specific URL, but the format and content of the POST is fixed by Slack. See this.... So it looks like for Slack we would need a dedicated endpoint.
It looks from first glace like that's more or less how github handles their webhooks as well - See this
IFTTT allows you to "make a web request" after a trigger, and it is a bit easier to take advantage of than Slack. IFTTT allow you to set the URL, the HTTP call type (GET, POST), as well as edit the message body to fit your needs. Unfortunately, they don't allow you to set headers, only the response body. So I guess the only real limitation here would be the API Token would need to be in the body text... Not really ideal, but maybe workable.
I'm hesitant to implement per-service API in the Trilium itself. But maybe it could be done on a user level.
Trilium could expose general "cath-all" endpoint on e.g. /api/public-catch-all and you would be able to register a script handler for given call. So e.g. you would have a script note with label @requestHandler=slack/note. Now all requests (GET, POST ...) going to /api/public-catch-all/slack/note would be handled by the script note. From script note you can use full Trilium script API to create a new note or whatever.
Authentication would have to be handled by script as well (but you can use e.g. static secret token). This way I think it wouldn't be too difficult to create integration with any such service ...
Completely agree on implementing a per-service API... That's just whack-a-mole thinking that could lead to terrible bloat-ware.
I love the idea of the catch-all + scripting. That really leverages the awesome capabilities of the Trilium's scripting! It's also really flexible, so you could implement all kinds of interactivity and interaction beyond simply posting new notes. You leave it entirely up to the user how to deal with the specific response bodies and content - so the main repo remains clear of all that integration-specific code.
released in 0.29.
Documentation here: https://github.com/zadam/trilium/wiki/Custom-request-handler
This is phenomenal, and works perfectly! Thanks for the hard work!
Most helpful comment
released in 0.29.
Documentation here: https://github.com/zadam/trilium/wiki/Custom-request-handler