odarriba

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

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

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

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! :bow:

Where Next?

Popular in Announcing Top

jakub-zawislak
Hi everyone, I’m coming from the Symfony (PHP) framework. I like Phoenix, but it has a one thing that was build much better in the Symfo...
New
Crowdhailer
The latest release of Ace (0.10.0) includes serving content over HTTP/2. I have started writing a webserver to teach my self more about...
New
brainlid
LangChain is short for Language Chain. An LLM, or Large Language Model, is the “Language” part. This library makes it easier for Elixir a...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
fuelen
Hey folks! Want to present a toolkit for writing command-line user interfaces. It provides a convenient interface for colorizing text...
New
anshuman23
Hello all, I have been working on my proposed project called Tensorflex as part of Google Summer of Code 2018.. Tensorflex can be used f...
New
woylie
Flop is an Elixir library that applies filtering, ordering and pagination parameters to your Ecto queries. offset-based pagination with...
New
mattludwigs
Grizzly is a library for working with Z-Wave devices. Z-Wave is a low-frequency radio protocol for controlling smart home devices on a me...
New
trisolaran
Hi! :waving_hand: I would like to present LiveSelect, a little library that I wrote to easily add a dynamic selection input to your LV f...
198 10858 107
New

Other popular topics Top

Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
dogweather
I wrote this comment on r/haskell, and it’s not popular there. :wink: But I think I’m on to something… Haskell reminds me of Java, and e...
New

We're in Beta

About us Mission Statement