acutario / ravenx

Notification dispatch library for Elixir applications
MIT License
110 stars 8 forks source link

Notification functionality #6

Closed odarriba closed 7 years ago

odarriba commented 7 years ago

Maybe, it would be good to create some kind of modules that allows the end user to define a kind of notification (for example, "An ausence request has been approved").

The idea behind this that, due to the heterogeneity of different strategies' options and payloads, it's difficult to send notifications in multiple ways for one subject.

I have thought in something like this:

defmodule MyApp.Notifications do
  use Ravenx.Notification

  def ausence_approved(ausence) do
    user = ausence.approved

    # TODO: Check which notification strategies can be used to the user
    # and create a list like this:
    notifications = [
      [:slack, payload, options],
      [:email, payload, options],
      [:push, payload, options],
      [:push, payload, options]
    ]

    dispatch(notifications) # or dispatch_async(notifications)
  end
end

What do you think about it? I think it will be helpful for projects in which multiple notifications sent to user using multiple strategies at once.

crbelaus commented 7 years ago

Maybe this could be a behaviour and the ausence_approved a required callback of the behaviour (with a generic name). This way we could enforce a proper implementation from all custom modules implementing this behaviour.

On the other side we would need to implement each custom notification in a separated module, something like: MyApp.Notifications.AusenceApproved. I don't really know if it is good or bad :sweat_smile:

odarriba commented 7 years ago

Merged. Closing