-
Notifications
You must be signed in to change notification settings - Fork 616
Notifications
DemocracyOS manages user notifications through a separate node application, the Notifier server.
The purpose of this is to unload DemocracyOS itself from the hurdle of costly I/O operations and scheduling that are only relevant for notifications, while having a fault-tolerant approach as well (if the notifier fails it may resume notifications in the future, while the main app is still running). You can learn more about the Notifier and what notifications it provides in its own repo.
First of all, know where your instance of notifier-server
is going to be running. And update your config files accordingly:
"notifications": {
"url": "http://notifier-server.somehost.com:9001/api/events",
"token": 123456
}
WARNING: specifying the notifier
port is ALWAYS needed, even if it's running on port 80
. We will fix this in future releases but for the time being please take it into account.
And that's all you need to do.
NOTE: the contents of config/defaults.json
are the notifier's defaults for a local dev environment, so you needn't change those for a local build.
DemocracyOS communicates with the notifier
through a small API client, the notifier-client. You can always hit the notifier
directly through an HTTP call, but we recommend you leverage the existing client as shown.
In order to send notifications from anywhere in the app (server-side), you should first require the notifier-client
and call it in the following fashion:
var notifier = require('notifier-client')(config.notifications);
notifier.notify('some-event-name')
.to('[email protected]')
.withData( someDataObject )
.send(function (err, data) {
if (err) return fn(err);
return fn(null, doc);
})
Some events are already supported by notifier
(you can check which ones here). If you want to support custom events for your deployment then please fork notifier
and customise as needed.
That's all there is to know about notifier
for using it. If you want to know more or improve the existing feature set, please read more on the notifier repo
Visit our official website - Developed by Democracia en Red and contributors from the world over!