Description
Description
- Trubudget should offer a possibility to send email notifications.
- The email notification shall only contain the link to the notifications page since the rest of the information can be seen there. It is not important that the notification contains more detailed information.
- A User shall be able to subscribe or unsubscribe to email notifications via Trubudget.
- It shall not be possible to select certain email notifications that are sent to a user.
Architecture
Thoughts
When to send an e-mail notification?
When writing to chain
When a notification is created an event is generated and written as streamitem to the notification stream of the multichain.
If an email would be sent every time such streamitem is generated the user would only get a notification if the node is connected to our email service and smtp server which is optional. That means if another organization without email service generates a notification, no email-notification are sent.
When reading from chain
API-endpoint: When a node is updated and there are new notifications no event is fired and nobody is notified. The current way to check if there are new notifications is to constantly call the notification list endpoint of the Trubudget API and filter the new ones. The main issue here is that a user can only check for his/her notifications depending on the user auth token.
walletnotify: Multichain offers a runtime parameter called walletnotify which execute a command every time a block is created/confirmed. That way a script can filter all notification created events and send user information to our email service.
Which users should be handled
Only users of the organization the API belongs to should be notified by the connected email service. Because only these users can access their account on an API of the same organization.
walletnotify approach
The task for the walletnotify script is parsing the input (json object) filter necessary information and sending these information to the Trubudget email service.
This process must be fast since walletnotify generates output every time a transaction is done/confirmed.
Performance: The script executed has to be pre-compiled because compiling is time consuming, so no javascript etc should be used. The information should be filtered as early as possible, so the filtering should be handled by mutlichain(walletnotify) itself if possible or by the script.
walletnotify vs walletnotifynew
If possible walletnotifynew should be used instead of walletnotify since walletnotifynew only executes the given command when a transaction is first seen. When a transaction is not confirmed and will never be confirmed an email would be send though which is wrong.
Filtering
Following list shows which parameters should be considered when filtering transaction information:
- only confirmed transactions
- userIds
- organization (filtering by organization should be done at the mail service since more than one mail service with a different organization can be connected to the node?)
Multichain runtime parameters (https://www.multichain.com/developers/runtime-parameters/)
Multichain Feeds
"A feed is a real-time on-disk binary log of the events relating to one or more blockchain streams", which represents the hook in our solution with saving the filtered transactions in a binary log so a external process can read them. With this approach no notifications would be lost if the database or the email service weren't available.
Unfortunately "feeds" are not available in the community version of mutlichain which we want to use since this project should be completely open source and free.
More details about feeds can be read in the recently posted blog from the mutlichain devs.
(https://www.multichain.com/blog/2020/02/multichain-feeds-for-database-integration/)