I am hoping to configure our account to send users email notifications when an activity log they are assigned to has been created or edited. Forgive me if this has been posted about already somewhere and I’ve missed it! We are using FarmOS v2 if that is relevant.
welcome to the forum @kloria
I’m not sure such a feature is currently available, but I’ve been working on something similar for myself. External notifications, webhooks, MQTT etc - #7 by Farmer-Ed
Depending on what access you have to your farmOS instance, is it self hosted? and if you are willing/able to get your hands dirty with a bit of code, then it may not be too difficult a task. Drupals Hook system can be used to trigger some code, I haven’t used it for e-mails myself but to make http requests to another server.
Thanks! We are hosting via Farmier, and in any case I have to say the custom coding via Drupal is a fair bit out of my depth Good to hear that others are thinking along similar lines though!
Sorry I haven’t much else to offer, my solution is very much a work in progress although it is working for my needs at the moment it’s a long way from being offered as a module, I’m very much learning some of the necessary code on the fly myself.
I’ve added a feature request tag to the thread though, maybe if it gets enough interest someone might take it on.
Welcome @kloria! This is an idea that has come up a few times in the past, but alas no one has implemented it yet.
Just to add a few thoughts, in case someone comes across this in the future… Implementing this in farmOS itself probably wouldn’t be too hard, but in order for it to be a “complete” solution we would need to make sure it covers all the possible scenarios that “assign” a log:
- Adding/editing a log individually and setting/changing/unsetting the assigned users.
- Bulk assigning logs via the “Assign” bulk action (farmOS/LogAssign.php at 2.x · farmOS/farmOS · GitHub).
- Changes to logs via API.
All of these could probably be covered with a single event subscriber in the
farm_owner module that listens for changes to the
owner field on logs.
However, it makes me wonder: do we want it to be configurable at all? Should the assigning user be able to check/uncheck a box to “Send an email notification” to the assigned user? Or should it just always happen? This checkbox wouldn’t be available for API updates (unless we also added some kind of dynamic API-accessible property too). What happens if you are bulk-assigning? If you bulk-assign 100 logs to 1 user, would that user get 100 emails? Ideally not, but that would mean a more complicated (intelligent) implementation would be required (the simple event subscriber might not cut it).
Also makes me think: @jgOhYeah recently opened a pull request to add the same
owner field to Assets, in addition to Logs. Should notifications be sent for those as well? I don’t see why not?
An alternative to email notifications might be “push notifications” in a native mobile app - so you get a little ping/buzz on your phone when it happens. This idea was kicking around for a bit back when Field Kit was also distributed as a native app, but now it is only available as a PWA - I’m not sure if push notifications are possible via PWAs (@jgaehring have you ever seen that done?)
So some things to think through… but I’d love to see something like this come together!
On the “native app” idea… I could almost imagine someone building a super simple “farmOS Notifications” mobile app with the sole purpose of handling these kind of push notifications. Maybe something like that would be worth exploring as a standalone app?
Perhaps a notification app already exists with a simple API? Or something like Telegram.
Fairly sure it can be achieved in a web app too as most modern browsers for better or worse support notification services.
Ah I was imagining something that would pull from farmOS’s API (and therefore would also need to be able to connect via OAuth, read the API/data model, etc) - but to your point @Farmer-Ed maybe a push process (initiated by farmOS) would also be possible. I suppose there are challenges on either side:
- A “pull” approach would not get the notifications instantly - it would need to be constantly polling the farmOS API for updates.
- A “push” approach assumes that there is a “central server” somewhere with an API to push to, which the native app then receives notifications from (although that would probably ALSO be a polling process, I imagine, since there’s no real way for a server to push data to clients anywhere/everywhere)
And if it’s going to be a “push” process from farmOS, then I suppose it might as well just send an email.
Probably want to limit the amount of processing done by the mobile devices to conserve battery, I’d imagine a push process from farmOS would be better in this regard, but would rely on a notification server, I suppose e-mail is as good as any.
The Notifications API has been well-established in Chrome and Firefox for nearly 10 years now, but as with most modern browser features, Apple refuses to bring it to iOS Safari, although I’m surprised to see MacOS Safari has had it for a while now. As always, there are rumors buzzing about support coming soon, but I would not hold your breath. Apple is too greedy with their App Store revenues to give web standards like this any real priority.
I haven’t fully investigated it, but it looks like there’s this project called ntfy that might be able to function as an abstraction over various notification channels. Similar story on the Apple/iOS side but I guess they’re working on an app; iOS app · Issue #4 · binwiederhier/ntfy · GitHub
Might just give that a go next week sometime when I’ve a few min spare. Thanks for sharing that @Symbioquine
@Symbioquine, I was awake early this morning so decided to have a little play with this and I think it has great potential. I installed the self hosted docker image and it works out of the box, API is simple for both publishing and subscribing to notification topics.
Somewhat related is the data stream notification features we have in 2.x. It has been updated from 1.x with two concepts: condition and delivery plugins. Condition plugins introduce the ability to have multiple simple conditions (greater than 90 degrees OR less than 30 degrees) as well as something more complex in a custom condition. The delivery plugin configures where the notification is sent - right now there is only email, but in theory a delivery plugin could be added for everything mentioned above.
Right now this is all very specific to data streams but it could be possible to expand the system to other “events” (log/asset save) in the farmOS DB.
@paul121 I just tried to look at the data stream notification features, but I’m a bit lost.
I have some basic sensors setup on my dev instance, which work fine and I just installed the data stream notification module but I don’t see any new configuration options in any of the menus. I’m probably missing something obvious.
I was considering trying to make a contrib module to add similar functionality for notifications from logs, I have a cobbled together something that works for me using Node-Red but I’m also trying to learn enough PHP/Drupal to make a proper module, I’m going through a few tutorials at the moment. I will have a proper look through the code in the data stream notification module when I get a chance later to see if I can use any of it (Or even understand it )
@Farmer-Ed I’d be happy to help you through the process of a contrib module implementation if you’re interested in going down that route! Similar to the process @jgOhYeah and I went through in Is it possible to use custom fields and filtering in asset views and filter by a range of birth dates?
Happy to do that here or in a separate dedicated thread, if that would make more sense (keep this one general)?
First thing I would do is point to some of the other examples of entity event subscribers…
That would be great @mstenta, I am interested alright and would be glad of any guidance.
I have 2 threads open in the development section on projects that I’d like to have a go at.
Probably makes sense to concentrate on the notifications one as there seems to be a bit of interest there for it already. I have managed to get some of the functionality of both going in true farmer style with coding standards that may resemble the temporary gate made from baler twine and pallets.
Should a menu entry/link have been added somewhere for the data stream notifications module?
I still cant find it in a menu although I see it when I browse to https://myfarmosurl/data-stream-notifications.
I had a little play with it and its pretty cool, could do with being a little more intuitive especially with linking the data stream ID, but works well.