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:

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:

agustif

agustif

It looks great, Guys, do you think ravenx could fit well for connecting with Zapier?

At cercle crm we want to send notifications via zapier, and I thought about this as a good way to leave the door open to new integrations down the road.

brightball

brightball

Looks really sharp!

Where Next?

Popular in Libraries Top

tompave
Hello there, I would like to share a feature toggles library (AKA feature flags) I’ve been working on. The main package is FunWithFlags...
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
sasajuric
I’d like to announce a small library called boundaries. This is an experimental project which explores the idea of enforcing boundaries ...
New
praveenperera
FastRSS Parse RSS feeds very quickly: This is rust NIF built using rustler Uses the RSS rust crate to do the actual RSS parsing Speed...
New
pkrawat1
Presenting Aviacommerce, open source e-commerce platform in Elixir Aviacommerce is an open source e-commerce platform in Elixir. We at...
New
aditya7iyengar
Rummage.Ecto and Rummage.Phoenix provide ways to perform Searching, Sorting and Pagination over Ecto queries and Phoenix collections. Fo...
New
alisinabh
Hey everyone i’ve developed a library for Jalaali calendar for elixir which supports converting Gregorian dates to Jalaali and vice vers...
New
msaraiva
Surface is an experimental library built on top of Phoenix LiveView and its new LiveComponent API that aims to provide a more declarative...
564 42633 214
New
wojtekmach
Hey everyone! Req is an HTTP client for Elixir that I’ve been working on for quite some time. There is already a lot of HTTP clients out...
New
bluzky
You may know https://ui.shadcn.com/, a UI component library for React. I really love it’s design style and components. I’ve built some co...
381 12391 119
New

Other popular topics Top

lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
chrismccord
As promised, the first release candidate of Phoenix 1.3.0 is out! This release focuses on code generators with improved project structure...
New
mgjohns61585
Could someone help me? I'm making my first elixir program, number guessing game. I can't figure out how to convert the user's guess from ...
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
beno
I will often find my self writing things similar to: case some_value do nil -&gt; something() "" -&gt; something() _ -&gt; someth...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
AstonJ
by Lance Halvorsen Elixir and Phoenix are generating tremendous excitement as an unbeatable platform for building modern web application...
460 27162 124
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
joeerl
Hello again - after a longish gap I’ve decided I really must dig into Elixir and see what’s been happening here - so I have a few questio...
New

Sub Categories:

We're in Beta

About us Mission Statement