odarriba
Ravenx - Notification dispatcher
Ravenx
Hex: https://hex.pm/packages/ravenx
GitHub: https://github.com/acutario/ravenx
Ravenx is a notification dispatcher that allows to simplify the sending of notifications to external services, even if you need to send them using multiple providers.
The library has two main methods: the dispatch that returns the final state of the process and dispatch_async which just returns the reference of the %Task{} without waiting the response.
Each notification is defined by three thinhs: the strategy (or service) to use, the payload map (which contains the data used to build the notification) and the options map, which include configuration for the service provider, or similar.
In case you need to notify something using multiple methods (or strategies), you can create a Notification module that specify each notification sent.
Example of simple notification
You can just send a notification synchronously:
{:ok, response} = Ravenx.dispatch(:slack, %{title: "Hello world!", body: "Science is cool!"})
Or asynchronously:
{:ok, %Task{}} = Ravenx.dispatch_async(:slack, %{title: "Hello world!", body: "Science is cool!"})
Example of complex notification
Given this example notification module:
defmodule YourApp.Notification.NotifyUser do
use Ravenx.Notification
def get_notifications_config(user) do
# In this function you can define which strategies use for your user (or
# whatever you want to pass as argument) and return something like:
[
slack: {:slack, %{title: "Important notification!", body: "Wait..."}, %{channel: user.slack_username}},
email_user: {:email, %{subject: "Important notification!", html_body: "<h1>Wait...</h1>", to: user.email_address}},
email_company: {:email, %{subject: "Important notification about an user!", html_body: "<h1>Wait...</h1>", to: user.company.email_address}},
other_notification: {:invalid_strategy, %{text: "Important notification!"}, %{option1: value2}},
]
end
end
You can just tell Ravenx to dispatch it synchronously:
YourApp.Notification.NotifyUser.dispatch(user)
And it will spawn the different processes and return the response for each in just one call:
[
slack: {:ok, ...},
email_user: {:ok, ...},
email_company: {:ok, ...},
other_notification: {:error, {:unknown_strategy, :invalid_strategy}}
]
Most Liked
odarriba
Just published a blog post about how to use Ravenx and why we built this library:
https://medium.com/acutario/sending-notifications-in-elixir-with-ravenx-1f2502a1f272
odarriba
After some inactive months, we have just released version 2.0.0 of Ravenx.
The major changes are:
- Simpler supervision tree
- Code formatter applied to the src
- Strategies now are in separate packages (except the dummy one)
- Minor fixes
Special mention to the fact that strategies now are in different packages, avoiding additional dependencies for strategies that you are not going to use (like Bamboo).
How to upgrade
Just upgrade version, and add the packages of needed strategies. Then add the strategies to the application configuration as indicated in the README. And you are good to go!
belaustegui
Been using Ravenx by 6 months (more or less) in production delivering websocket and email notifications without any problem.
Can’t wait to update to the next release! ![]()
Popular in Announcing
Other popular topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #advent-of-code
- #elixirconf-us
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #performance








